fut icon indicating copy to clipboard operation
fut copied to clipboard

Transpiling to Lua?

Open ghost opened this issue 2 years ago • 4 comments

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.

ghost avatar Aug 18 '23 06:08 ghost

Which version of Lua will you use? I suggest LuaJIT.

ghost avatar Sep 23 '23 14:09 ghost

Does Lua have incompatible dialects? Or only different implementations?

pfusik avatar Sep 23 '23 14:09 pfusik

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.

ghost avatar Sep 23 '23 14:09 ghost

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)
})

teadrinker avatar Jul 30 '24 11:07 teadrinker