mirror of
https://github.com/lune-org/lune.git
synced 2025-04-10 21:40:54 +01:00
create thread when requiring module
This commit is contained in:
parent
1708c05522
commit
3b56b4159d
2 changed files with 12 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
use crate::{library::StandardLibrary, luaurc::RequireAlias};
|
use crate::{library::StandardLibrary, luaurc::RequireAlias};
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
|
use mlua_luau_scheduler::{IntoLuaThread, LuaSchedulerExt};
|
||||||
use std::{collections::HashMap, path::PathBuf, sync::Arc};
|
use std::{collections::HashMap, path::PathBuf, sync::Arc};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
fs,
|
fs,
|
||||||
|
@ -149,12 +150,17 @@ impl RequireContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = fs::read_to_string(&path_abs).await?;
|
let content = fs::read_to_string(&path_abs).await?;
|
||||||
|
let thread = lua
|
||||||
|
.load(&content)
|
||||||
|
.set_name(path_abs.to_string_lossy())
|
||||||
|
.into_lua_thread(lua)?;
|
||||||
|
|
||||||
|
let thread_id = lua.push_thread_back(thread, ())?;
|
||||||
|
lua.wait_for_thread(thread_id).await;
|
||||||
|
|
||||||
let multi = lua
|
let multi = lua
|
||||||
.load(content)
|
.get_thread_result(thread_id)
|
||||||
.set_name(path_abs.to_string_lossy())
|
.ok_or(RequireError::ThreadReturnedNone)??;
|
||||||
.eval_async::<LuaMultiValue>()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let mutli_clone = multi.clone();
|
let mutli_clone = multi.clone();
|
||||||
let multi_reg = lua.create_registry_value(mutli_clone.into_vec())?;
|
let multi_reg = lua.create_registry_value(mutli_clone.into_vec())?;
|
||||||
|
|
|
@ -23,6 +23,8 @@ pub enum RequireError {
|
||||||
InvalidStdAlias(String),
|
InvalidStdAlias(String),
|
||||||
#[error("Library '{0}' does not point to a member of '{1}' standard libraries")]
|
#[error("Library '{0}' does not point to a member of '{1}' standard libraries")]
|
||||||
StdMemberNotFound(String, String),
|
StdMemberNotFound(String, String),
|
||||||
|
#[error("Thread result returned none")]
|
||||||
|
ThreadReturnedNone,
|
||||||
|
|
||||||
#[error("IOError: {0}")]
|
#[error("IOError: {0}")]
|
||||||
IOError(#[from] std::io::Error),
|
IOError(#[from] std::io::Error),
|
||||||
|
|
Loading…
Add table
Reference in a new issue