diff options
Diffstat (limited to 'src/frontend/mame/luaengine.ipp')
-rw-r--r-- | src/frontend/mame/luaengine.ipp | 95 |
1 files changed, 93 insertions, 2 deletions
diff --git a/src/frontend/mame/luaengine.ipp b/src/frontend/mame/luaengine.ipp index cb6824dd262..78652d557e6 100644 --- a/src/frontend/mame/luaengine.ipp +++ b/src/frontend/mame/luaengine.ipp @@ -59,21 +59,98 @@ private: // don't convert core_optons to a table directly -template<> struct is_container<core_options> : std::false_type { }; +template <> struct is_container<core_options> : std::false_type { }; +// buffer customisation sol::buffer *sol_lua_get(sol::types<buffer *>, lua_State *L, int index, sol::stack::record &tracking); int sol_lua_push(sol::types<buffer *>, lua_State *L, buffer *value); +// lua_engine::devenum customisation +template <typename T> struct is_container<lua_engine::devenum<T> > : std::true_type { }; +template <typename T> struct usertype_container<lua_engine::devenum<T> >; + } // namespace sol +// osd_file::error customisation int sol_lua_push(sol::types<osd_file::error>, lua_State *L, osd_file::error &&value); template <typename Handler> bool sol_lua_check(sol::types<osd_file::error>, lua_State *L, int index, Handler &&handler, sol::stack::record &tracking); +// map_handler_type customisation int sol_lua_push(sol::types<map_handler_type>, lua_State *L, map_handler_type &&value); +template <typename T, typename C, typename I = typename C::iterator> +struct lua_engine::immutable_container_helper +{ +protected: + using iterator = I; + + static T &get_self(lua_State *L) + { + auto p(sol::stack::unqualified_check_get<T *>(L, 1)); + if (!p) + luaL_error(L, "sol: 'self' is not of type '%s' (pass 'self' as first argument with ':' or call on proper type)", sol::detail::demangle<T>().c_str()); + if (!p.value()) + luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument with ':' or call on a '%s' type", sol::detail::demangle<T>().c_str()); + return *p.value(); + } + + struct indexed_iterator + { + indexed_iterator(C &s, iterator i) : src(s), it(i), ix(0U) { } + + C &src; + iterator it; + std::size_t ix; + + indexed_iterator &operator++() + { + ++it; + ++ix; + return *this; + } + }; + +public: + static int set(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'set(key, value)' on type '%s': container is not modifiable", sol::detail::demangle<T>().c_str()); + } + + static int index_set(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'container[key] = value' on type '%s': container is not modifiable", sol::detail::demangle<T>().c_str()); + } + + static int add(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'add' on type '%s': container is not modifiable", sol::detail::demangle<T>().c_str()); + } + + static int insert(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'insert' on type '%s': container is not modifiable", sol::detail::demangle<T>().c_str()); + } + + static int find(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'find' on type '%s': no supported comparison operator for the value type", sol::detail::demangle<T>().c_str()); + } + + static int clear(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'clear' on type '%s': container is not modifiable", sol::detail::demangle<T>().c_str()); + } + + static int erase(lua_State *L) + { + return luaL_error(L, "sol: cannot call 'erase' on type '%s': container is not modifiable", sol::detail::demangle<T>().c_str()); + } +}; + + struct lua_engine::addr_space { addr_space(address_space &s, device_memory_interface &d) : space(s), dev(d) { } @@ -90,7 +167,7 @@ struct lua_engine::addr_space }; -template<typename T, size_t SIZE> +template <typename T, size_t SIZE> class lua_engine::enum_parser { public: @@ -121,4 +198,18 @@ private: std::array<std::pair<const char *, T>, SIZE> m_map; }; + +//------------------------------------------------- +// invoke - invokes a function, wrapping profiler +//------------------------------------------------- + +template <typename TFunc, typename... TArgs> +inline sol::protected_function_result lua_engine::invoke(TFunc &&func, TArgs &&... args) +{ + g_profiler.start(PROFILER_LUA); + sol::protected_function_result result = func(std::forward<TArgs>(args)...); + g_profiler.stop(); + return result; +} + #endif // MAME_FRONTEND_MAME_LUAENGINE_IPP |