Pretty interesting. I'm a professional user of Lua, and while I love it, I really get frustrated at a lot of aspects of it, especially how loose the typing is. I've long wished there were more strongly typed alternatives, but just nothing compares to the performance, stability, and quality of documentation of Lua.
I'm not sure how I would embed this in a non-Zig project, though.
Have you heard of Teal (https://github.com/teal-language/tl)? It's like typescript for Lua made by Hisham. It also has the concept of declaration files so you can import (and type) existing Lua modules if needed.
Teal only type checks when run from the command line though, which isn't the best when you want to embed Lua. At least thats what my reading of the docs says, I'd be happy if I'm wrong. But reading the docs now, it doesn't seem to say that any more - maybe its changed recently?
Edit: Oh yes it's still like that 'When loading and running the Teal module from Lua, there is no type checking! Type checking will only happen when you run tl check or load a program with tl run.' from
https://github.com/teal-language/tl/blob/master/docs/tutoria...
I haven't, but I might have to do a lot of work to get it working, as my typical use of Lua is deeply embedded and customized, and doesn't allow any filesystem access. I will definitely look into that, though, thank you. The only real Lua dialect I'm familiar with in that area is Moonscript.
Terra and Nelua are both very different in goals than Teal. Teal is literally gradual types integrated into Lua keeping as many of Lua's idioms as possible (to a fault[1]). Terra and Nelua are both very metaprogrammable systems programming languages. Nelua's goals are primarily to soften C's rough edges, comparable to something like Nim.
There's another one you missed in Pallene[2]. But again, it's goal was to optimize the stack sharing involved in using the C API. It also adds types though and maintains Lua idioms as much as possible.
If you want non-allocating scripting for optimal performance (and io limited to what you provide as buffer), go for https://dascript.org/. I dont think there are currently other projects with that performance (+ also inspired by Zig).
Though, not sure how clunky it is to use.
Curious, if you don't mind, what kind of professional usage with Lua you work on? I was working on some Nginx/Openresty scripting with Lua module to implement kind of web edge service and really liked it.
We use a heavily stripped and sandboxed Lua interpreter for user scripts in a monitoring system. The initial approach was going to be WebAssembly, but that didn't pan out for a couple reasons.
Much of the functionally has been wrapped or customized to disallow any system access that doesn't go through an access control layer, including for require, and disallowing catching certain errors with pcall and through coroutines. Anything that could feasibly break the sandbox is also removed, like the debug package, and the ability to load bytecode (text sources only). The actual Lua sources are 100% vanilla, though we complete it with C++ to be compatible with the rest of the codebase.
Comments
Pretty interesting. I'm a professional user of Lua, and while I love it, I really get frustrated at a lot of aspects of it, especially how loose the typing is. I've long wished there were more strongly typed alternatives, but just nothing compares to the performance, stability, and quality of documentation of Lua.
I'm not sure how I would embed this in a non-Zig project, though.
Have you heard of Teal (https://github.com/teal-language/tl)? It's like typescript for Lua made by Hisham. It also has the concept of declaration files so you can import (and type) existing Lua modules if needed.
Teal only type checks when run from the command line though, which isn't the best when you want to embed Lua. At least thats what my reading of the docs says, I'd be happy if I'm wrong. But reading the docs now, it doesn't seem to say that any more - maybe its changed recently?
Edit: Oh yes it's still like that 'When loading and running the Teal module from Lua, there is no type checking! Type checking will only happen when you run tl check or load a program with tl run.' from https://github.com/teal-language/tl/blob/master/docs/tutoria...
I haven't, but I might have to do a lot of work to get it working, as my typical use of Lua is deeply embedded and customized, and doesn't allow any filesystem access. I will definitely look into that, though, thank you. The only real Lua dialect I'm familiar with in that area is Moonscript.
There's many different approaches to typed Lua:
- https://luau-lang.org (interpreted / sandboxed)
- https://terralang.org (JIT interpreted)
- https://nelua.io (Lua -> C)
- https://typescripttolua.github.io/ (TS -> Lua)
- https://github.com/teal-language/tl (Teal -> Lua)
- https://github.com/sumneko/lua-language-server (IDE only typing)
With minimum effort you can get a lot of benefit from using Sumneko's Lua language server.
Terra and Nelua are both very different in goals than Teal. Teal is literally gradual types integrated into Lua keeping as many of Lua's idioms as possible (to a fault[1]). Terra and Nelua are both very metaprogrammable systems programming languages. Nelua's goals are primarily to soften C's rough edges, comparable to something like Nim.
There's another one you missed in Pallene[2]. But again, it's goal was to optimize the stack sharing involved in using the C API. It also adds types though and maintains Lua idioms as much as possible.
[1]: https://github.com/teal-language/tl/discussions/339
[2]: https://github.com/pallene-lang/pallene
There is Roblox's typed variant
https://luau-lang.org/
See also this list for comparison https://github.com/fubark/cyber/issues/6, if you dont want lua by a meta-compiler.
If you want non-allocating scripting for optimal performance (and io limited to what you provide as buffer), go for https://dascript.org/. I dont think there are currently other projects with that performance (+ also inspired by Zig). Though, not sure how clunky it is to use.
Curious, if you don't mind, what kind of professional usage with Lua you work on? I was working on some Nginx/Openresty scripting with Lua module to implement kind of web edge service and really liked it.
We use a heavily stripped and sandboxed Lua interpreter for user scripts in a monitoring system. The initial approach was going to be WebAssembly, but that didn't pan out for a couple reasons.
Much of the functionally has been wrapped or customized to disallow any system access that doesn't go through an access control layer, including for require, and disallowing catching certain errors with pcall and through coroutines. Anything that could feasibly break the sandbox is also removed, like the debug package, and the ability to load bytecode (text sources only). The actual Lua sources are 100% vanilla, though we complete it with C++ to be compatible with the rest of the codebase.
There’s a C embed example in the examples folder
Nice, thanks. Looks pretty reasonable, but I'd really have to learn some zig myself to be fully comfortable using it, I think.