Fix lua native bindings and lua script reload (#1575)

* fix: script manager and lua scripts: change the api so that the m_scripts array is only modified in a specific safe location: before it gets ticked.
* fix script manager: don't expose the script vector directly, for multithreading safety
* fix lua manager usage: don't iterate the module array without locking, nor un/load module from a script thread
* lua script: only do actual loading of lua modules in script mgr
* lua native bindin: fix pointer parameters, out C style parameters are returned as multiple return values lua-style
This commit is contained in:
Quentin
2023-07-01 22:40:17 +02:00
committed by GitHub
parent 57ac1a315c
commit d1e839651b
12 changed files with 43494 additions and 6581 deletions

View File

@ -8,7 +8,6 @@
namespace big
{
static std::weak_ptr<lua_module> selected_module{};
static bool show = true;
void view::lua_scripts()
{
@ -17,21 +16,11 @@ namespace big
if (ImGui::BeginListBox("##empty", ImVec2(200, 200)))
{
auto& modules = g_lua_manager->get_modules();
if (show && modules.size() > 0)
{
for (const auto& module : modules)
{
if (ImGui::Selectable(module->module_name().c_str(),
!selected_module.expired() && selected_module.lock().get() == module.get()))
selected_module = module;
}
}
else
{
ImGui::Text("No scripts loaded");
}
g_lua_manager->for_each_module([](auto& module) {
if (ImGui::Selectable(module->module_name().c_str(),
!selected_module.expired() && selected_module.lock().get() == module.get()))
selected_module = module;
});
ImGui::EndListBox();
}
@ -46,22 +35,23 @@ namespace big
ImGui::Text("Memory Patches Registered: %d", selected_module.lock()->m_registered_patches.size());
ImGui::Text("GUI Tabs Registered: %d", selected_module.lock()->m_gui.size());
components::button("Reload", [] {
if (components::button("Reload"))
{
auto name = selected_module.lock()->module_name();
auto id = selected_module.lock()->module_id();
g_lua_manager->unload_module(id);
g_lua_manager->load_module(name);
selected_module = g_lua_manager->get_module(id);
});
g_lua_manager->queue_load_module(name, [](std::weak_ptr<big::lua_module> loaded_module) {
selected_module = loaded_module;
});
}
}
ImGui::EndGroup();
components::button("Reload All", [] {
show = false;
g_lua_manager->reload_all_modules();
show = true;
});
if (components::button("Reload All"))
{
g_lua_manager->m_schedule_reload_modules = true;
}
}
}