-
Notifications
You must be signed in to change notification settings - Fork 36
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
Luau support #30
Comments
I tried doing this and got it to work. I built Luau using their cmake-based build and linked the output library with ziglua. It'd be better if everything was built through build.zig but I didn't look into that part. It might be doable or it might get hairy. I can share my notes if you want, although I didn't encounter any major problems. You need to configure the cmake build correctly to make it use extern "C" to make it work. There are some differences between Luau and other Lua implementations and Luau also uses a compiler and code is loaded as bytecode so it'll need some additional functions and tweaks. But the usual stuff like calling a Lua function uses the same Lua 5.1 API. |
Thanks for taking a look into things! Feel free to share your notes here, that would likely be helpful. I'm also interested in getting things to work with the build.zig. I'm planning on working on this over the next few days. I expect it should be possible because mlua seems to support Luau bindings for Rust |
Here's the mods that I made to ziglua to compile against Luau. I don't think there's anything that's directly useful but sharing here in case it's helpful:
I had to use the following Building Luau:
I'm not sure how Ziglua should deal with the Luau command line tools. Probably wouldn't be a bad idea to also package & build those through build.zig? More work though. The compiler is something that I believe is a must use with Luau, so perhaps building that along with everything else in Ziglua will be pretty convenient. BTW fingers crossed that Zig dropping LLVM (and thus C++) won't make bundling C++ libs like Luau a tool configuration nightmare. |
Hey! Sorry for the weeks of silence. I finally had a large block of time to work on this. I have Luau building from source in the build.zig file now, and tests seem to be passing. I did have to comment out several tests in my rush to get things working. I'll take some time now to clean things up. |
Really cool, thanks for the update, @natecraddock! Looking forward to using it. |
Missed this the first time. My understanding is that there would be some sort of optional llvm dependency still. It's a long ways out though, so only time will tell! I just pushed to the luau branch (https://github.com/natecraddock/ziglua/tree/luau) all my changes. It is still a work in progress, but the basics should work now. Feel free to give it a try if you have time. I just tested using Luau with the build system and it seems to work great!
This is the first time I have used Luau, so I'm unfamiliar with what is expected. If I have missed anything let me know! |
Thanks, I'll give it a try over the holidays! I actually haven't used Luau either, but I have a strong intuition that I'll have a better time with it than normal Lua. Luau has some non-Roblox users too, such as Alan Wake 2 (https://www.remedygames.com/article/how-northlight-makes-alan-wake-2-shine) |
I just finished fixing all of the tests for Luau. I copied the tests from Lua 5.1, so I may be missing some things that Luau includes from newer versions of Lua. But it should be mostly feature complete now! https://github.com/natecraddock/ziglua/tree/luau I'll be merging this in in the next few days after some more testing |
I wonder if I'm running the tests correctly. Here's what I get when running
(There's something to be said about the clarity if "zig test" output clarity.. like which actual test failed?) I think it's failing on loadString:
On Linux, here's what I get:
Ie., prints nothing. Who knows what it ran as Zig test system has a tendency of taking overt control over running tests. EDIT: actually I guess it runs something? I ran the produced Trying to run example zig function on Linux:
The interpreter example works tho. I also didn't look very hard yet, but is there a Zig API for loading bytecode? I think the common approach to using Luau is to compile luau code into bytecode and then load bytecode only. |
OK, here's a patch that fixes the error on Windows. AFAICT the problem is that it's not portable to assume that
IMO adding a wrapper for |
I started working on an example that loads precompiled bytecode (e.g., use However, a question on types. To load bytecode, I'm planning to add something like this:
Does the use of non-sentinel Otherwise, I have a small example that's able to load a bytecode file and execute the loaded module. This stuff is exceptionally poorly documented in Luau, so I'll play with this a bit more to see that I did everything right. For example, I have no idea what the above |
Thanks for catching this! I did just assume that
I very likely use sentinel slices way too much in Ziglua. For return types from Lua it makes more sense, but for passing data in to Lua I expect it is not needed as much as I have done it. Feel free to not use a sentinel in your PR.
I'm glad I'm not alone in feeling this 😂 I've had to read through the source code to determine how many of the API functions have changed. I do actually know what Please feel free to give more suggestions on the Luau API. I know you said you aren't super familiar with it, but based on things you said (like "I think the common approach to using Luau is to compile luau code into bytecode and then load bytecode only.") you appear to be more familiar than me. Thanks! |
Clarifying my earlier comment: I'd say it's not a portability assumption even, just that one shouldn't assume a particular implementation for the For pure malloc/free, there's also: https://ziglang.org/documentation/master/std/#A;std:heap.raw_c_allocator. But I think it's better done as in my patch so that whatever gets allocated in C is also deallocated in C.
Sure! I'll need to use it for something real to see what's missing. Chunkname: Yep, I think you're right. I found out later that it's a concept in "core Lua" too, so pretty sure that's what it means here too.
Yeah, it's easy to go from a sentinel slice to normal slice, so a sentinel return type is fine (and preferred if it means one less allocation) but the other direction is harder as it implies an allocation (need one more byte for the ending 0). I thought there was a function for converting from slice to zero-terminated string but I can't even find it now in the std lib. :) |
I pushed some fixes, added windows CI coverage, and made a PR (probably should have done that a while ago at this point). Looks like everything is good to go. I'll probably merge this PR within the next day because at this point any future fixes or additional features can be done later. |
Yeah, I think it makes sense to merge. Easier to add stuff on top of it then. |
Some conversations on #19 show interest in Luau support.
It should be possible, though I haven't attempted yet. It is written in C++ which may cause issues.
The text was updated successfully, but these errors were encountered: