diff --git a/packages/lib/src/importer/require.rs b/packages/lib/src/importer/require.rs index 492c4ad..a6bbe53 100644 --- a/packages/lib/src/importer/require.rs +++ b/packages/lib/src/importer/require.rs @@ -7,7 +7,7 @@ use std::{ }; use dunce::canonicalize; -use mlua::prelude::*; +use mlua::{prelude::*, Compiler as LuaCompiler}; use tokio::fs; use tokio::sync::Mutex as AsyncMutex; @@ -194,8 +194,9 @@ async fn load_file<'lua>( .trim_end_matches(".lua") .trim_end_matches(".luau"); // Load the file into a thread + let compiled_func = LuaCompiler::default().compile(&contents); let loaded_func = lua - .load(&contents) + .load(compiled_func) .set_name(path_relative_no_extension) .into_function()?; let loaded_thread = lua.create_thread(loaded_func)?; diff --git a/packages/lib/src/lib.rs b/packages/lib/src/lib.rs index bfb3c0a..0aa9044 100644 --- a/packages/lib/src/lib.rs +++ b/packages/lib/src/lib.rs @@ -69,7 +69,7 @@ impl Lune { ) -> Result { // Create our special lune-flavored Lua object with extra registry values let lua = lua::create_lune_lua()?; - let script_bytecode = LuaCompiler::default().compile(script_contents); + let script = LuaCompiler::default().compile(script_contents); // Create our task scheduler and all globals // NOTE: Some globals require the task scheduler to exist on startup let sched = TaskScheduler::new(lua)?.into_static(); @@ -77,7 +77,7 @@ impl Lune { importer::create(lua, self.args.clone())?; // Create the main thread and schedule it let main_chunk = lua - .load(script_bytecode) + .load(script) .set_name(script_name.as_ref()) .into_function()?; let main_thread = lua.create_thread(main_chunk)?;