diff options
Diffstat (limited to 'src/frontend/mame/luaengine.h')
-rw-r--r-- | src/frontend/mame/luaengine.h | 96 |
1 files changed, 64 insertions, 32 deletions
diff --git a/src/frontend/mame/luaengine.h b/src/frontend/mame/luaengine.h index f61baa8c083..de94e7ba729 100644 --- a/src/frontend/mame/luaengine.h +++ b/src/frontend/mame/luaengine.h @@ -12,7 +12,8 @@ #pragma once -#include <condition_variable> +#include "notifier.h" + #include <functional> #include <map> #include <memory> @@ -21,7 +22,12 @@ #include <tuple> #include <vector> +#define SOL_USING_CXX_LUA 1 +#ifdef MAME_DEBUG +#define SOL_ALL_SAFETIES_ON 1 +#else #define SOL_SAFE_USERTYPE 1 +#endif #include "sol/sol.hpp" struct lua_State; @@ -43,8 +49,9 @@ public: ~lua_engine(); void initialize(); - void load_script(const char *filename); - void load_string(const char *value); + sol::load_result load_script(std::string const &filename); + sol::load_result load_string(std::string const &value); + sol::environment make_environment(); bool frame_hook(); @@ -52,9 +59,8 @@ public: std::pair<bool, std::optional<long> > menu_callback(const std::string &menu, int index, const std::string &event); void set_machine(running_machine *machine); - std::vector<std::string> &get_menu() { return m_menu; } + std::vector<std::string> const &get_menu() { return m_menu; } void attach_notifiers(); - void on_frame_done(); void on_sound_update(); void on_periodic(); bool on_missing_mandatory_image(const std::string &instance_name); @@ -117,29 +123,46 @@ public: sol::state_view &sol() const { return *m_sol_state; } -private: - template<typename T, size_t SIZE> class enum_parser; + template <typename Func, typename... Params> + sol::protected_function_result invoke(Func &&func, Params&&... args) + { + auto profile = g_profiler.start(PROFILER_LUA); - struct addr_space; + sol::thread th = sol::thread::create(m_lua_state); + sol::coroutine cr(th.state(), std::forward<Func>(func)); + return cr(std::forward<Params>(args)...); + } - struct save_item { - void *base; - unsigned int size; - unsigned int count; - unsigned int valcount; - unsigned int blockcount; - unsigned int stride; - }; + template <typename Func, typename... Params> + static auto invoke_direct(Func &&func, Params&&... args) + { + auto profile = g_profiler.start(PROFILER_LUA); + return func(std::forward<Params>(args)...); + } - struct context +private: + struct notifiers { - context() { busy = false; yield = false; } - std::string result; - std::condition_variable sync; - bool busy; - bool yield; + util::notifier<> on_reset; + util::notifier<> on_stop; + util::notifier<> on_pause; + util::notifier<> on_resume; + util::notifier<> on_frame; + util::notifier<> on_presave; + util::notifier<> on_postload; }; + template <typename T, size_t Size> class enum_parser; + + class buffer_helper; + struct addr_space; + class palette_wrapper; + template <typename T> class bitmap_helper; + class tap_helper; + class addr_space_change_notif; + class symbol_table_wrapper; + class expression_wrapper; + // internal state lua_State *m_lua_state; std::unique_ptr<sol::state_view> m_sol_state; @@ -147,31 +170,40 @@ private: std::vector<std::string> m_menu; - template <typename R, typename T, typename D> - auto make_simple_callback_setter(void (T::*setter)(delegate<R ()> &&), D &&dflt, const char *name, const char *desc); + emu_timer *m_timer; + + // machine event notifiers + std::optional<notifiers> m_notifiers; + + // deferred coroutines + std::vector<std::pair<attotime, int> > m_waiting_tasks; + std::vector<int> m_update_tasks; + std::vector<int> m_frame_tasks; + + template <typename... T> + auto make_notifier_adder(util::notifier<T...> ¬ifier, const char *desc); + template <typename T, typename D, typename R, typename... A> + auto make_simple_callback_setter(void (T::*setter)(delegate<R (A...)> &&), D &&dflt, const char *name, const char *desc); running_machine &machine() const { return *m_machine; } void on_machine_prestart(); - void on_machine_start(); + void on_machine_reset(); void on_machine_stop(); void on_machine_pause(); void on_machine_resume(); void on_machine_frame(); + void on_machine_presave(); + void on_machine_postload(); - void resume(void *ptr, int nparam); + void resume(s32 param); void register_function(sol::function func, const char *id); - int enumerate_functions(const char *id, std::function<bool(const sol::protected_function &func)> &&callback); + template <typename T> size_t enumerate_functions(const char *id, T &&callback); bool execute_function(const char *id); sol::object call_plugin(const std::string &name, sol::object in); void close(); - void run(sol::load_result res); - - template <typename TFunc, typename... TArgs> - sol::protected_function_result invoke(TFunc &&func, TArgs&&... args); - void initialize_debug(sol::table &emu); void initialize_input(sol::table &emu); void initialize_memory(sol::table &emu); |