fusionlanguage / fut

Fusion programming language. Transpiling to C, C++, C#, D, Java, JavaScript, Python, Swift, TypeScript and OpenCL C.
https://fusion-lang.org
GNU General Public License v3.0
1.74k stars 55 forks source link

Transpiling to Lua? #98

Open ghost opened 1 year ago

ghost commented 1 year ago

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 commented 11 months ago

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

pfusik commented 11 months ago

Does Lua have incompatible dialects? Or only different implementations?

ghost commented 11 months ago

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.

teadrinker commented 1 month ago

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