Skip to content

Commit 05a0abb

Browse files
committed
Replace Requite::load with Require::loader
1 parent f0c0527 commit 05a0abb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/luau/require.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::result::Result as StdResult;
88
use std::{env, fmt, fs, ptr};
99

1010
use crate::error::Result;
11+
use crate::function::Function;
1112
use crate::state::{callback_error_ext, Lua};
1213
use crate::types::MaybeSend;
1314
use crate::value::Value;
@@ -85,10 +86,10 @@ pub trait Require: MaybeSend {
8586
/// This function is only called if `is_config_present` returns true.
8687
fn config(&self) -> IoResult<Vec<u8>>;
8788

88-
/// Loads the module and returns the result (function or table).
89-
fn load(&self, lua: &Lua, path: &str, chunk_name: &str, content: &[u8]) -> Result<Value> {
89+
/// Returns a loader that when called, loads the module and returns the result.
90+
fn loader(&self, lua: &Lua, path: &str, chunk_name: &str, content: &[u8]) -> Result<Function> {
9091
let _ = path;
91-
lua.load(content).set_name(chunk_name).call(())
92+
lua.load(content).set_name(chunk_name).into_function()
9293
}
9394
}
9495

@@ -424,7 +425,7 @@ pub(super) unsafe extern "C" fn init_config(config: *mut ffi::luarequire_Configu
424425
let contents = CStr::from_ptr(contents).to_bytes();
425426
callback_error_ext(state, ptr::null_mut(), false, move |extra, _| {
426427
let rawlua = (*extra).raw_lua();
427-
match this.load(rawlua.lua(), &path, &chunk_name, contents)? {
428+
match (this.loader(rawlua.lua(), &path, &chunk_name, contents)?).call(())? {
428429
Value::Nil => rawlua.push(true)?,
429430
value => rawlua.push_value(&value)?,
430431
};

0 commit comments

Comments
 (0)