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

Expose Luau bytecode loading API, add example #38

Merged
merged 1 commit into from
Jan 12, 2024

Conversation

nurpax
Copy link
Contributor

@nurpax nurpax commented Jan 3, 2024

for #30

This exposes Luau API for loading precompiled Luau bytecode.

I found some information from the Luau repository that indicates bytecode is not intended to be fully backwards/forwards compatible. I think loading bytecode can be justified due to performance reasons (improves start up time) but anyone doing bytecode loading should be prepared to be able to recompile bytecode if they upgrade Luau.

It feels like adding a zig-implementation of luau-compile into Ziglua. It wouldn't be much code since the original luau-compile is pretty straightforward too.

Anyway, I'm working on a little blog post that explains how to use VSCode, Zig and Luau together so that VSCode can perform real-time static type checking of Luau code. It may not be obvious from the docs of any of these components :)

@nurpax
Copy link
Contributor Author

nurpax commented Jan 3, 2024

The example could cover more functionality, like how to call some specific function defined in the bytecode blob. But I guess that can be added in another PR.

@natecraddock
Copy link
Owner

Anyway, I'm working on a little blog post that explains how to use VSCode, Zig and Luau together so that VSCode can perform real-time static type checking of Luau code. It may not be obvious from the docs of any of these components :)

Feel free to share this when you finish!

As I mentioned on the other PR, I won't have time to review this week, but thank you for the PR and I'll review it thoroughly soon!

@nurpax
Copy link
Contributor Author

nurpax commented Jan 5, 2024

Feel free to share this when you finish!

Here's a preview of what: https://github.com/nurpax/luau-zig-example

Longer term, I'd like to be able to auto-generate the Zig->Luau bindings. I did see some work on that here in issues, but rather than using comptime, I think I'll do it in a separate pass in Python. I'm just too slow at writing comptime code and I feel like it'll be easier for me to develop & debug if I can see the generated interface code.

examples/luau-bytecode.zig Outdated Show resolved Hide resolved
@nurpax
Copy link
Contributor Author

nurpax commented Jan 10, 2024

Update to this PR: https://github.com/natecraddock/ziglua/pull/38/files#r1447697186

I'll change the approach a little bit.

@nurpax
Copy link
Contributor Author

nurpax commented Jan 10, 2024

@natecraddock updated this PR. It's done as far as I'm concerned.

@natecraddock
Copy link
Owner

natecraddock commented Jan 12, 2024

@nurpax sorry, but I just merged the tests.zig changes, so this will need to be updated a bit. Should be really straightforward. Just move your changes to tests.zig to the new file and then add a if (ziglua.lang != .luau) return; to the top of the test.

I'll hold off on merging the lib.zig files for a bit though

- Add ziglua.compile for a safer wrapper around c.luau_compile
- Add Lua.loadBytecode()
- Add example
@nurpax
Copy link
Contributor Author

nurpax commented Jan 12, 2024

@natecraddock Updated the PR against the main branch. Ready to merge as far as I'm concerned.

If you're not in a hurry with your lib.zig changes, then I could work on the two other Luau specific PRs over the weekend.

@natecraddock
Copy link
Owner

Looks good, thanks for working on this!

If you're not in a hurry with your lib.zig changes, then I could work on the two other Luau specific PRs over the weekend.

Yeah I'm taking a break for now. Merging all of the tests took a lot of effort 😅

@natecraddock natecraddock merged commit 3337d7e into natecraddock:main Jan 12, 2024
3 checks passed
@nurpax nurpax deleted the luau-bytecode branch January 17, 2024 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants