Skip to content

Commit 3362815

Browse files
ConnorBPmakspll
andauthored
Apply LUA api providers before loading script. (#98)
* apply api providers before loading script. Fixes issue where api is not available during script initialization. * fix linting errors --------- Co-authored-by: Maksymilian Mozolewski <makspl17@gmail.com>
1 parent 85e66a5 commit 3362815

File tree

1 file changed

+10
-4
lines changed
  • languages/bevy_mod_scripting_lua/src

1 file changed

+10
-4
lines changed

languages/bevy_mod_scripting_lua/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,23 @@ impl<A: LuaArg> ScriptHost for LuaScriptHost<A> {
113113
#[cfg(not(feature = "unsafe_lua_modules"))]
114114
let lua = Lua::new();
115115

116-
lua.load(script)
116+
// init lua api before loading script
117+
let mut lua = Mutex::new(lua);
118+
providers.attach_all(&mut lua)?;
119+
120+
lua.get_mut()
121+
.map_err(|e| ScriptError::FailedToLoad {
122+
script: script_data.name.to_owned(),
123+
msg: e.to_string(),
124+
})?
125+
.load(script)
117126
.set_name(script_data.name)
118127
.exec()
119128
.map_err(|e| ScriptError::FailedToLoad {
120129
script: script_data.name.to_owned(),
121130
msg: e.to_string(),
122131
})?;
123132

124-
let mut lua = Mutex::new(lua);
125-
126-
providers.attach_all(&mut lua)?;
127133
Ok(lua)
128134
}
129135

0 commit comments

Comments
 (0)