Skip to content

Commit e83d0a3

Browse files
committed
🎉 call post/pre lua hooks
1 parent 481227b commit e83d0a3

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

runtime/src/game.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ impl Game {
256256
gl.enable(glow::MULTISAMPLE);
257257
}
258258

259+
let plugin_interface = PluginInterface {
260+
lua: &self.lua_env.lua,
261+
};
262+
self.plugin_env.pre_lua_hook(plugin_interface);
263+
259264
// Update screen transitions
260265
lua_screen::update_screen_transition(&self.lua_env.lua, delta_time.as_secs_f32());
261266

@@ -284,6 +289,11 @@ impl Game {
284289
.draw(&self.lua_env.resources, true);
285290
}
286291

292+
let plugin_interface = PluginInterface {
293+
lua: &self.lua_env.lua,
294+
};
295+
self.plugin_env.post_lua_hook(plugin_interface);
296+
287297
// Default Duration metrics
288298
self.metrics_holder
289299
.borrow_mut()

runtime/src/lua_env.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use crate::console::{print_lua_error, print_warn};
2727
use crate::game_resource::ResourceManager;
2828
use crate::graphics::batchdraw::BatchDraw2d;
2929
use crate::io::IoEnvState;
30-
use crate::io::fs::ReadOnlyFileSystem;
3130

3231
use crate::metrics::MetricsHolder;
3332

runtime/src/native_plugin.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,31 @@ impl PluginEnvironment {
9393
self.loaded_plugins.iter()
9494
}
9595

96+
/// Call the initialization hook of all the loaded plugins
9697
pub fn init(&self, plugin_interface: PluginInterface) {
9798
for plugin in &self.loaded_plugins {
9899
plugin.call_init_hook(plugin_interface); // might trigger a crash I guess?
99100
}
100101
}
102+
103+
pub fn pre_lua_hook(&self, plugin_interface: PluginInterface) {
104+
for plugin in &self.loaded_plugins {
105+
plugin.call_pre_lua_hook(plugin_interface);
106+
}
107+
}
108+
109+
pub fn post_lua_hook(&self, plugin_interface: PluginInterface) {
110+
for plugin in &self.loaded_plugins {
111+
plugin.call_post_lua_hook(plugin_interface);
112+
}
113+
}
114+
115+
/// Call the release hook of all the loaded plugins
116+
pub fn release_hook(&self, plugin_interface: PluginInterface) {
117+
for plugin in &self.loaded_plugins {
118+
plugin.call_release_hook(plugin_interface);
119+
}
120+
}
101121
}
102122

103123
pub static DYNAMIC_LIB_SUFFIXES: [&str; 4] = ["so", "dll", "dylib", "wasm"];

0 commit comments

Comments
 (0)