Skip to content

Pre-compiling Lua? #137

Answered by khvzak
sawcce asked this question in Q&A
Mar 22, 2022 · 3 comments · 4 replies
Discussion options

You must be logged in to vote

You can load chunk and then dump it to bytecode:

let bytecode = lua.load("return 1 + 1").into_function()?.dump(true);

// To load it back
let result = lua.load(&bytecode).set_mode(ChunkMode::Binary).eval::<i32>()?;
assert_eq!(result, 2);

Starting from 0.8.0 bytecode can be loaded without restrictions (since too many ways available to load bytecode and too much effort to protect all that places).
On the previous versions Lua must be created via unsafe_new.

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@sawcce
Comment options

Answer selected by sawcce
Comment options

You must be logged in to vote
3 replies
@khvzak
Comment options

@khvzak
Comment options

@sawcce
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants