-
Notifications
You must be signed in to change notification settings - Fork 90
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
feature/impl-luau-lib: Add support for luau.compile
and luau.load
.
#82
Conversation
… through 'options' table
…/impl-luau-lib
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments - I think everything looks pretty good, not sure exactly how we would expand the testing suite here, but if you think of anything feel free to add some more tests since this is such a low level feature.
|
||
assert(type(luau.compile) == "function", "expected `luau.compile` to be a function") | ||
|
||
assert( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to verify that this is actually bytecode and not an arbitrary string? Does Luau bytecode start with any specific magic header or somesuch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can tell - Luau bytecode does start off with the version of the bytecode, but the bytes after that go into the content of that bytecode.
<bytecode-ver> ...
I've found this from both of these sources;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: Additionally, if a compilation fails - instead of producing an error, the luau.compile
function will return a message where the first byte is 0, and the error is attached afterwards. (luau.load
accounts for this, but i'll get it tested none-the-less!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, if a compilation fails - instead of producing an error, the luau.compile function will return a message where the first byte is 0, and the error is attached afterwards
I think it would probably be a good idea to check for this on the rust end of things for the compile
function and throw a lua error then, too. We don't really have any other APIs that behave like this in Lune where they return an error message, if the user wants to handle errors/fallible functions pcall
should be the go-to for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the above changes in b5906b2
Co-authored-by: Filip Tibell <filip.tibell@gmail.com>
Co-authored-by: Filip Tibell <filip.tibell@gmail.com>
…*` method options
|
||
assert(type(luau.compile) == "function", "expected `luau.compile` to be a function") | ||
|
||
assert( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, if a compilation fails - instead of producing an error, the luau.compile function will return a message where the first byte is 0, and the error is attached afterwards
I think it would probably be a good idea to check for this on the rust end of things for the compile
function and throw a lua error then, too. We don't really have any other APIs that behave like this in Lune where they return an error message, if the user wants to handle errors/fallible functions pcall
should be the go-to for consistency
Co-authored-by: Filip Tibell <filip.tibell@gmail.com>
Co-authored-by: Filip Tibell <filip.tibell@gmail.com>
Co-authored-by: Filip Tibell <filip.tibell@gmail.com>
…lune into feature/impl-luau-lib
Context
Lune at the moment has no way to optimally run source/bytecode, this PR aims to try and implement a new
luau
library that allows developers to create Luau closures in their code.This PR attempts to bring together some of the points made in
[RFC] Lune built-in luau library
, however, discards theseySafeEnv
function call as i'm not certain how we'd go about doing that undermlua
(Would be happy to discuss this though!)
This PR
luau
Lune library.luau.compile
function to compile a string into bytecode.options
table allowing developers to setoptimization_level
,coverage_level
anddebug_level
luau.load
function to load either bytecode or a source string into a function.options
table allowing developers to setdebug_name
.luau
Lune librarydocumentationtypes forluau
Lune libraryYet to-do