move generator script execution to an isolated Lua state

This commit is contained in:
MihailRis
2024-10-06 18:23:33 +03:00
parent 091805a16e
commit 73d96fd4f7
8 changed files with 101 additions and 75 deletions
+5 -5
View File
@@ -17,11 +17,11 @@ Hud* scripting::hud = nullptr;
void scripting::on_frontend_init(Hud* hud) {
scripting::hud = hud;
lua::openlib(lua::get_main_thread(), "hud", hudlib);
lua::openlib(lua::get_main_state(), "hud", hudlib);
for (auto& pack : engine->getContentPacks()) {
lua::emit_event(
lua::get_main_thread(),
lua::get_main_state(),
pack.id + ".hudopen",
[&](lua::State* L) {
return lua::pushinteger(L, hud->getPlayer()->getId());
@@ -33,7 +33,7 @@ void scripting::on_frontend_init(Hud* hud) {
void scripting::on_frontend_render() {
for (auto& pack : engine->getContentPacks()) {
lua::emit_event(
lua::get_main_thread(),
lua::get_main_state(),
pack.id + ".hudrender",
[&](lua::State* L) { return 0; }
);
@@ -43,7 +43,7 @@ void scripting::on_frontend_render() {
void scripting::on_frontend_close() {
for (auto& pack : engine->getContentPacks()) {
lua::emit_event(
lua::get_main_thread(),
lua::get_main_state(),
pack.id + ".hudclose",
[&](lua::State* L) {
return lua::pushinteger(L, hud->getPlayer()->getId());
@@ -60,7 +60,7 @@ void scripting::load_hud_script(
std::string src = files::read_string(file);
logger.info() << "loading script " << file.u8string();
lua::execute(lua::get_main_thread(), env, src, file.u8string());
lua::execute(lua::get_main_state(), env, src, file.u8string());
register_event(env, "init", packid + ".init");
register_event(env, "on_hud_open", packid + ".hudopen");