Use compiler directly in require impl

This commit is contained in:
Filip Tibell 2023-07-20 09:03:29 +02:00
parent 8eda0532fa
commit 151cfe9b2f
No known key found for this signature in database
2 changed files with 5 additions and 4 deletions

View file

@ -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)?;

View file

@ -69,7 +69,7 @@ impl Lune {
) -> Result<ExitCode, LuaError> {
// 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)?;