-
Notifications
You must be signed in to change notification settings - Fork 63
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
[RFC] Lune built-in luau
library
#11
Comments
luau
libraryluau
library (load
, safeLoad
, compile
)
luau
library (load
, safeLoad
, compile
)luau
library
Hey'o @regginator ~ I've implemented two out of three methods mentioned above in this PR.
I've not managed to manipulate |
Hello, thank you so much for working on this feature! This proposal was a bit flawed, but it was just an idea for everything - it'd probably be better to eventually just have an API interface to as much of Again, thanks for making this a real thing! |
Closed as implemented in #82 - for additional features we can open new issues |
Introduction
In Lune, we currently have no way to dynamically run source/bytecode whatsoever;
loadstring()
is omitted from the environment afaik.In standalone Luau, due to multiple sandboxing reasons,
loadstring()
can only run direct source code. (as opposed to loading raw bytecode in vanilla Lua) The function also deoptimizes the environment of the loaded closure, as it's directly returned and can be modifed/manipulated in any way:Proposition
This default behavior isn't even intended for most using
loadstring()
, and disablessafeenv
internally in the VM.I propose some sort of built-in library for Lune like "
luau
", which could provide some fairly basic functions and utils for compiling/loading source code or bytecode as-is, as we don't really need to sandbox for this seperate behavior.(Potential) API
Also, these should probably all error for basic logical reasons, like incorrect type input etc. They shouldn't error by themselves though, as these functions would be how a script generally knows if compilation is successful.
Compile Luau Source Code to Bytecode
It would take in input source code, as well as an optional
options
table for certain basicLuau::Compile
compilation options. If successful, it'd return the binary bytecode file/chunk as a string, and no compiler error ofcourse. (string, nil
) Otherwise, it'd just returnnil, string
;string
being the Luau compiler error.Example Usage:
Load & Run Source/Bytecode
This would be almost identical to
loadstring()
's API, but also accepting bytecode forsource
, just like vanilla Lua. (Luau doesn't have this behavior at all, it wouldn't be default expected behavior)It would just return the closure as-is, like normal loadstring would. By default, this would mean
safeenv
would naturally be disabled in the VM internally for this closure env. However, ifoptions.safeLoad
is set totrue
, theclosure
return will just proxy back the return of a call, similarly to howrequire()
would, and not allow the raw closure environment to be modified from outside of itself. This would solve any safeenv VM optimization issues.Set
safeenv
for VM on Current Environment(Suggested from @TheGreatSageEqualToHeaven) Sets
L->safeenv
directly on the currentL
state.Conclusion
There should probably be much more added to interact with low level Luau APIs, but these are just basic suggestions for such a library. If you have any disagreements or issues with these ideas, please lmk!
The text was updated successfully, but these errors were encountered: