##Reference Manual
###Lua at client
With Sailor, you can not only write the backend of your app with Lua, but you can also write Lua code that will run on the browser. This is possible because Sailor will get this piece of code and give it to a Virtual Machine that will handle it and run Javascript behind the scenes. Sailor is compatible with different implementations of Lua-to-Javascript virtual machines. The default is starlight. In case you want to use a different VM, you will have to download the folder with the libraries, put it inside the pub
folder of your Sailor app and edit your conf/conf.lua
to configure your app to use this VM instead.
Here is a small comparative table of the compatible VMs:
starlight | moonshine | lua51js | luavmjs | |
---|---|---|---|---|
The code is pre-processed on the server and bytecode is sent to the JS VM | ✓ | |||
The code is sent as a string to the JS VM | ✓ | ✓ | ✓ | |
Compatible Lua version of the client written code | 5.1 | 5.1 | 5.1 | 5.2.3 |
Works with Sailor on LuaJIT based servers, such as openresty | ✓ | ✓ | ✓ | |
DOM manipulation | ✓ | ✓ | incomplete | ✓ |
Can require Lua modules | ✓ | ✓ | Only on Apache | |
Supports Lua callbacks | ✓ | ✓ | x | ✓ |
Supports Lua script tags | ✓ | x | ✓ | ✓ |
Can call JS methods like eval() from Lua | ? | ? | x | ✓ |
Supports the Lua C API | x | x | ✓ | incomplete |
How to print "hello" to the console | print("hello") | print("hello") | print("hello") | print("hello") |
How to pop an alert message with "hello" | window:alert("hello") | window:alert("hello") | js.window:alert("hello") | js.global:alert("hello") |
You can find more information about them here:
Starlight: Examples, Github Repo
Moonshine: Official website, Github Repo
Lua5.1.js: Examples, Github Repo
Lua.vm.js: Examples, Official website, Github Repo