Skip to content

Commit

Permalink
Apply LUA api providers before loading script. (#98)
Browse files Browse the repository at this point in the history
* apply api providers before loading script.

Fixes issue where api is not available during script initialization.

* fix linting errors

---------

Co-authored-by: Maksymilian Mozolewski <[email protected]>
  • Loading branch information
ConnorBP and makspll committed Jan 25, 2024
1 parent 85e66a5 commit 3362815
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions languages/bevy_mod_scripting_lua/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,23 @@ impl<A: LuaArg> ScriptHost for LuaScriptHost<A> {
#[cfg(not(feature = "unsafe_lua_modules"))]
let lua = Lua::new();

lua.load(script)
// init lua api before loading script
let mut lua = Mutex::new(lua);
providers.attach_all(&mut lua)?;

lua.get_mut()
.map_err(|e| ScriptError::FailedToLoad {
script: script_data.name.to_owned(),
msg: e.to_string(),
})?
.load(script)
.set_name(script_data.name)
.exec()
.map_err(|e| ScriptError::FailedToLoad {
script: script_data.name.to_owned(),
msg: e.to_string(),
})?;

let mut lua = Mutex::new(lua);

providers.attach_all(&mut lua)?;
Ok(lua)
}

Expand Down

0 comments on commit 3362815

Please sign in to comment.