Languages that compile to Lua

栏目: IT技术 · 发布时间: 4年前

内容简介:SinceMoonscript has been around for a while (one of the reasons I forgot to add it to this post in my initial publication) and is stable and used in the industry, it is probably the most popularMoonScript is a dynamic scripting language that compiles into

Since Lua 5.4.0 is out, and that made me really happy, I decided to dedicate a small post to languages that compile to Lua .

Moonscript

Moonscript has been around for a while (one of the reasons I forgot to add it to this post in my initial publication) and is stable and used in the industry, it is probably the most popular compile to Lua language out there. I believe that a large part of Itch.io is powered by moonscript and NginX. Moonscript feels like CoffeeScript but for Lua. If you pair it with the Lapis web framework by the same author, you have a delightful setup to launch your next web application.

MoonScript is a dynamic scripting language that compiles into Lua. It gives you the power of one of the fastest scripting languages combined with a rich set of features.

Source: MoonScript, a language that compiles to Lua

Example of Moonscript

class Thing
  name: "unknown"

class Person extends Thing
  say_name: => print "Hello, I am #{@name}!"

with Person!
  .name = "MoonScript"
  \say_name!

Moonscript is built with Lua and Moonscript itself (almost in equal parts).

Fennel

I believe Fennel is the most popular new compile to Lua language current out there. There are a lot of people being Fennel developers first and Lua developers second. It looks quite neat, it has a Lisp flavour in its syntax and macro system but it is not a Common Lisp , its semantics conform to Lua semantics in most places.

  • Full Lua compatibility: Easily call any Lua function or library from Fennel and vice-versa.
  • Zero overhead: Compiled code should be just as or more efficient than hand-written Lua.
  • Compile-time macros: Ship compiled code with no runtime dependency on Fennel.
  • Embeddable: Fennel is a one-file library as well as an executable. Embed it in other programs to support runtime extensibility and interactive development.

Source: the Fennel programming language

It is quite neat and like Lua, it can run on a small ESP32 all the way to beefy server in a datacenter running OpenResty.

Examples of Fennel

The sample below is using Löve which is a game development library for Lua.

;; Sample: read the state of the keyboard and move the player accordingly
(local dirs {:up [0 -1] :down [0 1] :left [-1 0] :right [1 0]})

(each [key delta (pairs dirs)]
  (when (love.keyboard.isDown key)
    (let [[dx dy] delta
          [px py] player
          x (+ px (* dx player.speed dt))
          y (+ py (* dy player.speed dt))]
      (world:move player x y))))

Fennel is mostly built in Lua.

Urn

Urn is also a Lisp-like language for Lua. While Fennel is Lua in Lisp clothes, Urn is more into the Lisp-family being influenced by Common Lisp and Clojure.

  • A minimal¹ Lisp implementation, with full support for compile time code execution and macros.
  • Support for Lua 5.1, 5.2 and 5.3. Should also work with LuaJIT.
  • Lisp–1 scoping rules (functions and data share the same namespace).
  • Influenced by a whole range of Lisp implementations, including Common Lisp and Clojure.
  • Produces standalone, optimised Lua files: no dependencies on a standard library.

Source: Urn: A Lisp implementation for Lua | Urn

Example of Urn

Who doesn’t like pattern matching? All languages should have it by now…

> (case '("x" (foo 2 3))
.   [(string?  @ ?x) (.. "Got a string " x)]
.   [("x" (foo . ?x)) (.. "Got some remaining values " (pretty x))])
out = "Got some remaining values (2 3)"

Urn compiles to Lua but it is written in Common Lisp.

Amulet ML

Amulet ML is a functional language in the ML tradition (I love ML).

  • Generalised Algebraic Data Types (GADTs),
  • Multi-parameter type classes with associated types and functional dependencies, including support for quantified constraints,
  • Type functions supporting dependent kinds, and equality constraints,
  • Rank-N, impredicative types via Quick Look: ∀ quantifiers can appear anywhere in a type, not only the top-level,
  • Principled, extensible records via row polymorphism support inference of principal types.

Source: Amulet ML

Example of Amulet ML

let map f = function
| [] -> []
| Cons (x, xs) -> Cons (f x, map f xs)

let filter p xs = [ x | with x <- xs, p x ]
  • Minimalist syntax: semicolons, in and other noise is entirely optional.
  • Pattern matching and guards make writing code more intuitive.
  • List comprehensions are a short and sweet way of expressing complex computations on lists.

Be aware that even though Amulet ML compiles to Lua, it is written basically in Haskell with some bits in SML and OCaml.


以上所述就是小编给大家介绍的《Languages that compile to Lua》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

数据结构与算法

数据结构与算法

张铭、王腾蛟、赵海燕 / 高等教育出版社 / 2008-6 / 34.00元

《数据结构与算法》是普通高等教育“十一五”国家级规划教材,也是北京市精品课程主讲教材。《数据结构与算法》按照IEEE/ACM CC20025和教育部教指委关于“计算机科学与技术专业规范”(CCC2005)的要求编写,力求使学生较全面地理解数据结构的概念、掌握各种数据结构与算法的实现方式,同时比较不同数据结构和算法的特点,重点强调实践教学和学生动手能力的培养。 《数据结构与算法》的内容涉及基本......一起来看看 《数据结构与算法》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具