Open ghost opened 1 year ago
Which version of Lua will you use? I suggest LuaJIT.
Does Lua have incompatible dialects? Or only different implementations?
Does Lua have incompatible dialects? Or only different implementations?
LuaJIT is a compiler for Lua language. I suggest LuaJIT because it will have the best performance compared to the normal Lua interpreter. LuaJIT is only compatible with the Lua 5.1 syntax. The latest version of standard Lua is now 5.4.4, and the latest version of LuaJIT is 2.1.
Lua uses a combined structure for dictionaries/objects and lists/arrays, and the lists are NOT zero indexed. One of my failed projects was a transcompiler which primarily targeted js and lua (very basic c++/php support), I dealt with the indexing issue in the following way, never use the Lua length operator, and do special init:
list = [10,20,30]
push(list, 40)
print(len(list)) // prints 4
for value in list {
print(value)
}
would compile to the lua code:
local list = {[0]= 10, 20, 30 ,__n=3}
s_push(list, 40)
s_print(s_len(list)) -- prints 4
for value in pairs( list ) do
s_print(value)
end
(js for reference)
var list = [10, 20, 30]
s_push(list, 40)
s_print(s_len(list)) // prints 4
s_forV( list , function(value){
s_print(value)
})
I know something similar for Lua, it's called CSharp.lua: https://github.com/yanghuan/CSharp.lua
But it's a full fledged CSharp compiler that uses Roslyn and thus requires .NET to run.