mirror of
https://github.com/lune-org/lune.git
synced 2024-12-13 13:30:38 +00:00
Use compiler directly in require impl
This commit is contained in:
parent
8eda0532fa
commit
151cfe9b2f
2 changed files with 5 additions and 4 deletions
|
@ -7,7 +7,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use dunce::canonicalize;
|
use dunce::canonicalize;
|
||||||
use mlua::prelude::*;
|
use mlua::{prelude::*, Compiler as LuaCompiler};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio::sync::Mutex as AsyncMutex;
|
use tokio::sync::Mutex as AsyncMutex;
|
||||||
|
|
||||||
|
@ -194,8 +194,9 @@ async fn load_file<'lua>(
|
||||||
.trim_end_matches(".lua")
|
.trim_end_matches(".lua")
|
||||||
.trim_end_matches(".luau");
|
.trim_end_matches(".luau");
|
||||||
// Load the file into a thread
|
// Load the file into a thread
|
||||||
|
let compiled_func = LuaCompiler::default().compile(&contents);
|
||||||
let loaded_func = lua
|
let loaded_func = lua
|
||||||
.load(&contents)
|
.load(compiled_func)
|
||||||
.set_name(path_relative_no_extension)
|
.set_name(path_relative_no_extension)
|
||||||
.into_function()?;
|
.into_function()?;
|
||||||
let loaded_thread = lua.create_thread(loaded_func)?;
|
let loaded_thread = lua.create_thread(loaded_func)?;
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl Lune {
|
||||||
) -> Result<ExitCode, LuaError> {
|
) -> Result<ExitCode, LuaError> {
|
||||||
// Create our special lune-flavored Lua object with extra registry values
|
// Create our special lune-flavored Lua object with extra registry values
|
||||||
let lua = lua::create_lune_lua()?;
|
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
|
// Create our task scheduler and all globals
|
||||||
// NOTE: Some globals require the task scheduler to exist on startup
|
// NOTE: Some globals require the task scheduler to exist on startup
|
||||||
let sched = TaskScheduler::new(lua)?.into_static();
|
let sched = TaskScheduler::new(lua)?.into_static();
|
||||||
|
@ -77,7 +77,7 @@ impl Lune {
|
||||||
importer::create(lua, self.args.clone())?;
|
importer::create(lua, self.args.clone())?;
|
||||||
// Create the main thread and schedule it
|
// Create the main thread and schedule it
|
||||||
let main_chunk = lua
|
let main_chunk = lua
|
||||||
.load(script_bytecode)
|
.load(script)
|
||||||
.set_name(script_name.as_ref())
|
.set_name(script_name.as_ref())
|
||||||
.into_function()?;
|
.into_function()?;
|
||||||
let main_thread = lua.create_thread(main_chunk)?;
|
let main_thread = lua.create_thread(main_chunk)?;
|
||||||
|
|
Loading…
Reference in a new issue