Languages that compile to Lua

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

内容简介: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》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

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

再启动

再启动

[日] 大前研一 / 田龙姬、金枫 / 中华工商联合出版社有限责任公司 / 2010-1 / 29.00元

1、“全球管理大师”、“日本战略之父”大前研一,职场励志最新巨作。 2、2010年1月中华工商联合出版社有限责任公司与日知公司继《货币战争2》《中国大趋势》之后,再度联手,重磅推出。 3、震撼中国职场的宗师级巨作,势必引领2010年中国职场4、世界著名出版商小学馆授予独家中文简体出版权。 5、试问,哪个老板不希望自己的员工不断实现自身的“再启动”呢? 6、只有不断激励鞭策自......一起来看看 《再启动》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具