Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpiling to Lua? #98

Open
ghost opened this issue Aug 18, 2023 · 4 comments
Open

Transpiling to Lua? #98

ghost opened this issue Aug 18, 2023 · 4 comments
Labels
backend enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Aug 18, 2023

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.

@pfusik pfusik added enhancement New feature or request backend labels Aug 18, 2023
@ghost
Copy link
Author

ghost commented Sep 23, 2023

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

@pfusik
Copy link
Collaborator

pfusik commented Sep 23, 2023

Does Lua have incompatible dialects? Or only different implementations?

@ghost
Copy link
Author

ghost commented Sep 23, 2023

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants