lua: sub folders support, check for .lua file extension, refactor and simplify internals. (#1775)

This commit is contained in:
Quentin
2023-07-22 13:05:43 +02:00
committed by GitHub
parent 093abc72da
commit fa8043be2a
15 changed files with 288 additions and 300 deletions

View File

@ -1,6 +1,6 @@
#pragma once
#include "lua_module.hpp"
#include "core/enums.hpp"
#include "lua_module.hpp"
namespace big
{
@ -10,21 +10,11 @@ namespace big
std::mutex m_module_lock;
std::vector<std::shared_ptr<lua_module>> m_modules;
struct module_load_info
{
std::string m_name;
std::function<void(std::weak_ptr<lua_module>)> m_on_module_loaded;
};
std::queue<module_load_info> m_modules_load_queue;
static constexpr std::chrono::seconds m_delay_between_changed_scripts_check = 3s;
std::chrono::high_resolution_clock::time_point m_wake_time_changed_scripts_check;
folder m_scripts_folder;
public:
bool m_schedule_reload_modules;
public:
lua_manager(folder scripts_folder);
~lua_manager();
@ -37,28 +27,22 @@ namespace big
return m_modules.size();
}
bool has_gui_to_draw(rage::joaat_t tab_hash);
inline const folder& get_scripts_folder() const
{
return m_scripts_folder;
}
std::weak_ptr<lua_module> get_module(rage::joaat_t module_id);
bool has_gui_to_draw(rage::joaat_t tab_hash);
void draw_independent_gui();
void draw_gui(rage::joaat_t tab_hash);
void unload_module(rage::joaat_t module_id);
void load_module(const std::string& module_name);
void load_module(const std::filesystem::path& module_path);
void reload_changed_scripts();
void queue_load_module(const std::string& module_name, std::function<void(std::weak_ptr<lua_module>)> on_module_loaded);
void load_modules_from_queue();
std::weak_ptr<lua_module> get_module(rage::joaat_t module_id);
void handle_error(const sol::error& error, const sol::state_view& state);
template<menu_event menu_event_, typename Return = void, typename... Args>