Show HN: Lua/LuaJIT with C/C++/Java/JavaScript syntax
github.com
github.com
It seems to me that you're really trying to express a concept that could be referred to as "C-like syntax" or "JavaScript-like syntax," with the latter probably being more accurate. It would certainly be less confusing than repeating "C/C++/Java/JavaScript syntax" over and over.
Also if you have done any enhancement to Lua/LuaJIT and want help or talk about it I'm glad to hear from you.
There is an parser/transpiler using lemon/re2c that can transpile almost any Lua source to LJS see here https://github.com/mingodad/ljs/tree/master/lua2ljs .
Here are some non trivial projects converted to LJS:
ljsjit at https://github.com/mingodad/ljsjit
ljs-5.1 at https://github.com/mingodad/ljs-5.1
ZeroBraneStudio port at https://github.com/mingodad/ZeroBraneStudioLJS
raptorjit-ljs at https://github.com/mingodad/raptorjit-ljs
snabb-ljs at https://github.com/mingodad/snabb-ljs
premake5-ljs at https://github.com/mingodad/premake-core/tree/ljs
The next steps that I have in mind now is to add the remaining syntax sugar like:
-C/C++/Java/Javascript for loop
-Switch statement
-Class statement
-const declarations
- type checking (actually https://fascinatedbox.github.io/lily/ has those and it seems a good one to port/add)
-Understand and make it easier for other people understand the implementation of LuaJIT.
It seems that Mike Paul is still the main one that do it.
Now there is a repository on https://github.com/LuaJIT/LuaJIT/issues and after send a message to the mailing list and no answer for few days another user told me about it and I opened an issue of a problem I found while converting LuaJIT to LjsJIT see https://github.com/LuaJIT/LuaJIT/issues/461
[1] http://www.squirrel-lang.org/
[2] http://www.lemon-lang.org/Congrats for the project, transpilers are great fun.
An impactful project and a logical next step would be writing a new version of Moonshine (http://moonshinejs.org/) or writing a modern full-blown Lua to JS transpiler.
Cheers !
Can a project using 5.3 lua continue using existing .lua files but also write new files in .ljs?
> switch
Aren't match statements all the rage nowadays? Even C++20 get's one (with a silly name, of course)!
> class
Finally, setmetatable is nice, but, yes, "proper" not handrolled classes.
> const
Too few scripting languages have these. Do you intend to make this include interior mutability as well or is this only pointer deep?
I spent the last two years more or less full time trying out ways of making interpreters of similar complexity go faster without making the same mistake.
One method that seems really promising so far is AOT tracing [0], making guarantees and removing redundant code ahead of time based on incomplete semantic models. It's different from a full compiler in that it only tries to improve the situation and will back out and leave code alone where the semantic model is insufficient. And since it acts as a transformation on VM code, it's fairly transparent and easy to debug. The complexity of the models is a three way compromise between faster tracing, faster code and implementation complexity.
Once the VM code is reasonably optimal, further compiling to C by generating the interpreter code inline becomes even more attractive. Which also leads to native executables as a bonus feature.
Best wishes !
Just wanted to mention some alternatives to LuaJIT, since I don't think it's a viable way forward for languages of this scale.
Likewise!
The reason I'm tracing is that it's the only way I've found to prove anything of value in such a formless language; even Lisp knows which arguments belong to which function call, in Forth that depends on what came before.
And it fits well with an interpreted language, since a slow compile often defeats the purpose of compiling in the first place. The tracing I've implemented so far is instant in comparison.