manual_lua_at_client.md

January 18, 2016 · View on GitHub

##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:

starlightmoonshinelua51jsluavmjs
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 code5.15.15.15.2.3
Works with Sailor on LuaJIT based servers, such as openresty
DOM manipulationincomplete
Can require Lua modulesOnly on Apache
Supports Lua callbacksx
Supports Lua script tagsx
Can call JS methods like eval() from Lua??x
Supports the Lua C APIxxincomplete
How to print "hello" to the consoleprint("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