diff options
author | 2020-12-18 15:54:52 +1100 | |
---|---|---|
committer | 2020-12-18 15:54:52 +1100 | |
commit | 1df245cb99882892678216c3d0c6e243611d627c (patch) | |
tree | a8f3563a74d58755f4a82d4cbfc2406cf79543b3 /src/frontend/mame/luaengine_render.cpp | |
parent | ff9c1a0ca91f925e5c23b22a92a53c83f9f655ba (diff) |
More Lua engine clean-up and documentation, resulting in core cleanup.
More Lua interface cleanup, additional properties and methods, and
documentation migration/expansion.
Emulated switch inputs can have "not" codes applied to host input axis
directions. It works the same way as host switch inputs - push twice
for a "not" prefix.
Input polling helpers no longer need to store state in the input device
items. There’s less leakage, and less chance of things interfering with
each other.
Allow snapshot view options to be configured through the internal UI via
the video options menu. Made video options menus place initial focus on
the currently selected view item. Removed some crud from the menu base
class.
Fixed the description of the "snapview" option. The value to get raw
screen pixels was changed to "native" a long time ago but the
description was never updated.
Re-arranged the Golden Poker button lamps so that the 6-button layouts
for Jolli Witch and Wild Witch make sense. In 6-button mode, the hold
buttons double as bonus game and bet buttons, but the lamp outputs don't
change. The simplest way to deal with this without requiring the user
to switch views or using layout scripting is to place the dedicated
buttons directly below the hold buttons that correspond to them.
Removed some software list data that was redundantly copied into
device_image_interface (m_supported was never even set, so it didn't
even work), and made crc() work better (previously it wasn't
recalculuated after unloading and loading another image).
Made strformat.h and devcb.h play nicer with C++17 and pre-standard
C++20. Format precision now correctly limits the length of string
views. Confirmed that strformat.{h,cpp} works with pre-standard C++20
support in GCC 9.
Removed an auto_alloc from cpu/arm7.
Diffstat (limited to 'src/frontend/mame/luaengine_render.cpp')
-rw-r--r-- | src/frontend/mame/luaengine_render.cpp | 150 |
1 files changed, 10 insertions, 140 deletions
diff --git a/src/frontend/mame/luaengine_render.cpp b/src/frontend/mame/luaengine_render.cpp index ca472dba675..b910a717561 100644 --- a/src/frontend/mame/luaengine_render.cpp +++ b/src/frontend/mame/luaengine_render.cpp @@ -21,6 +21,10 @@ namespace { struct layout_file_views { layout_file_views(layout_file &f) : file(f) { } + layout_file::view_list &items() { return file.views(); } + + static layout_view &unwrap(layout_file::view_list::iterator const &it) { return *it; } + static int push_key(lua_State *L, layout_file::view_list::iterator const &it, std::size_t ix) { return sol::stack::push_reference(L, it->unqualified_name()); } layout_file &file; }; @@ -29,6 +33,10 @@ struct layout_file_views struct layout_view_items { layout_view_items(layout_view &v) : view(v) { } + layout_view::item_list &items() { return view.items(); } + + static layout_view::item &unwrap(layout_view::item_list::iterator const &it) { return *it; } + static int push_key(lua_State *L, layout_view::item_list::iterator const &it, std::size_t ix) { return sol::stack::push(L, ix + 1); } layout_view &view; }; @@ -53,48 +61,9 @@ template <> struct is_container<render_target_view_names> : std::true_type { }; template <> -struct usertype_container<layout_file_views> : lua_engine::immutable_collection_helper<layout_file_views, layout_file::view_list> +struct usertype_container<layout_file_views> : lua_engine::immutable_sequence_helper<layout_file_views, layout_file::view_list> { -private: - using view_list = layout_file::view_list; - - template <bool Indexed> - static int next_pairs(lua_State *L) - { - indexed_iterator &i(stack::unqualified_get<user<indexed_iterator> >(L, 1)); - if (i.src.end() == i.it) - return stack::push(L, lua_nil); - int result; - if constexpr (Indexed) - result = stack::push(L, i.ix + 1); - else - result = stack::push_reference(L, i.it->unqualified_name()); - result += stack::push_reference(L, *i.it); - ++i; - return result; - } - - template <bool Indexed> - static int start_pairs(lua_State *L) - { - layout_file_views &self(get_self(L)); - stack::push(L, next_pairs<Indexed>); - stack::push<user<indexed_iterator> >(L, self.file.views(), self.file.views().begin()); - stack::push(L, lua_nil); - return 3; - } - public: - static int at(lua_State *L) - { - layout_file_views &self(get_self(L)); - std::ptrdiff_t const index(stack::unqualified_get<std::ptrdiff_t>(L, 2)); - if ((0 >= index) || (self.file.views().size() < index)) - return stack::push(L, lua_nil); - else - return stack::push_reference(L, *std::next(self.file.views().begin(), index - 1)); - } - static int get(lua_State *L) { layout_file_views &self(get_self(L)); @@ -113,72 +82,13 @@ public: { return get(L); } - - static int index_of(lua_State *L) - { - layout_file_views &self(get_self(L)); - layout_view &view(stack::unqualified_get<layout_view>(L, 2)); - auto it(self.file.views().begin()); - std::ptrdiff_t ix(0); - while ((self.file.views().end() != it) && (&view != &*it)) - { - ++it; - ++ix; - } - if (self.file.views().end() == it) - return stack::push(L, lua_nil); - else - return stack::push(L, ix + 1); - } - - static int size(lua_State *L) - { - layout_file_views &self(get_self(L)); - return stack::push(L, self.file.views().size()); - } - - static int empty(lua_State *L) - { - layout_file_views &self(get_self(L)); - return stack::push(L, self.file.views().empty()); - } - - static int next(lua_State *L) { return stack::push(L, next_pairs<false>); } - static int pairs(lua_State *L) { return start_pairs<false>(L); } - static int ipairs(lua_State *L) { return start_pairs<true>(L); } }; template <> -struct usertype_container<layout_view_items> : lua_engine::immutable_collection_helper<layout_view_items, layout_view::item_list> +struct usertype_container<layout_view_items> : lua_engine::immutable_sequence_helper<layout_view_items, layout_view::item_list> { -private: - using item_list = layout_view::item_list; - - static int next_pairs(lua_State *L) - { - indexed_iterator &i(stack::unqualified_get<user<indexed_iterator> >(L, 1)); - if (i.src.end() == i.it) - return stack::push(L, lua_nil); - int result; - result = stack::push(L, i.ix + 1); - result += stack::push_reference(L, *i.it); - ++i.it; - ++i.ix; - return result; - } - public: - static int at(lua_State *L) - { - layout_view_items &self(get_self(L)); - std::ptrdiff_t const index(stack::unqualified_get<std::ptrdiff_t>(L, 2)); - if ((0 >= index) || (self.view.items().size() < index)) - return stack::push(L, lua_nil); - else - return stack::push_reference(L, *std::next(self.view.items().begin(), index - 1)); - } - static int get(lua_State *L) { layout_view_items &self(get_self(L)); @@ -195,50 +105,10 @@ public: return get(L); } - static int index_of(lua_State *L) - { - layout_view_items &self(get_self(L)); - layout_view::item &item(stack::unqualified_get<layout_view::item>(L, 2)); - auto it(self.view.items().begin()); - std::ptrdiff_t ix(0); - while ((self.view.items().end() != it) && (&item != &*it)) - { - ++it; - ++ix; - } - if (self.view.items().end() == it) - return stack::push(L, lua_nil); - else - return stack::push(L, ix + 1); - } - - static int size(lua_State *L) - { - layout_view_items &self(get_self(L)); - return stack::push(L, self.view.items().size()); - } - - static int empty(lua_State *L) - { - layout_view_items &self(get_self(L)); - return stack::push(L, self.view.items().empty()); - } - - static int next(lua_State *L) { return stack::push(L, next_pairs); } - static int pairs(lua_State *L) { return luaL_error(L, "sol: cannot call 'pairs' on type '%s': not iterable by ID", sol::detail::demangle<layout_view_items>().c_str()); } - - static int ipairs(lua_State *L) - { - layout_view_items &self(get_self(L)); - stack::push(L, next_pairs); - stack::push<user<indexed_iterator> >(L, self.view.items(), self.view.items().begin()); - stack::push(L, lua_nil); - return 3; - } }; |