summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/emu/input.cpp2
-rw-r--r--src/emu/ioport.cpp20
-rw-r--r--src/emu/output.h1
-rw-r--r--src/frontend/mame/luaengine.ipp17
-rw-r--r--src/frontend/mame/luaengine_input.cpp49
5 files changed, 47 insertions, 42 deletions
diff --git a/src/emu/input.cpp b/src/emu/input.cpp
index 1390ce8086f..b58958a6935 100644
--- a/src/emu/input.cpp
+++ b/src/emu/input.cpp
@@ -469,7 +469,7 @@ bool input_seq::is_valid() const noexcept
if (lastcode.internal())
return false;
- // if this is the end, we're ok
+ // if this is the end, we're OK
if (code == end_code)
return true;
diff --git a/src/emu/ioport.cpp b/src/emu/ioport.cpp
index a8fc5c0fdd3..0ea7974caf5 100644
--- a/src/emu/ioport.cpp
+++ b/src/emu/ioport.cpp
@@ -705,16 +705,12 @@ const char *ioport_field::name() const
const input_seq &ioport_field::seq(input_seq_type seqtype) const noexcept
{
- // if no live state, return default
- if (!m_live)
- return defseq(seqtype);
+ // if the sequence is not the special default code, return it
+ if (m_live && !m_live->seq[seqtype].is_default())
+ return m_live->seq[seqtype];
- // if the sequence is the special default code, return the expanded default value
- if (m_live->seq[seqtype].is_default())
- return manager().type_seq(m_type, m_player, seqtype);
-
- // otherwise, return the sequence as-is
- return m_live->seq[seqtype];
+ // otherwise return the default sequence
+ return defseq(seqtype);
}
@@ -741,14 +737,8 @@ const input_seq &ioport_field::defseq(input_seq_type seqtype) const noexcept
void ioport_field::set_defseq(input_seq_type seqtype, const input_seq &newseq)
{
- const bool was_changed = seq(seqtype) != defseq(seqtype);
-
// set the new sequence
m_seq[seqtype] = newseq;
-
- // also update live state unless previously customized
- if (m_live && !was_changed)
- m_live->seq[seqtype] = newseq;
}
diff --git a/src/emu/output.h b/src/emu/output.h
index 3571cc1f24b..79c0c61eb16 100644
--- a/src/emu/output.h
+++ b/src/emu/output.h
@@ -109,6 +109,7 @@ public:
auto &operator[](unsigned n) { return m_proxies[n]; }
auto &operator[](unsigned n) const { return m_proxies[n]; }
+ auto size() const { return std::size(m_proxies); }
auto begin() { return std::begin(m_proxies); }
auto end() { return std::end(m_proxies); }
auto begin() const { return std::begin(m_proxies); }
diff --git a/src/frontend/mame/luaengine.ipp b/src/frontend/mame/luaengine.ipp
index f995b0a4a7b..10d1f55f33f 100644
--- a/src/frontend/mame/luaengine.ipp
+++ b/src/frontend/mame/luaengine.ipp
@@ -448,31 +448,26 @@ template <typename T, size_t SIZE>
class lua_engine::enum_parser
{
public:
- constexpr enum_parser(std::initializer_list<std::pair<const char *, T>> values)
+ constexpr enum_parser(std::initializer_list<std::pair<std::string_view, T> > values)
{
if (values.size() != SIZE)
throw false && "size template argument incorrectly specified";
std::copy(values.begin(), values.end(), m_map.begin());
}
- T operator()(const char *text) const
+ T operator()(std::string_view text) const
{
auto iter = std::find_if(
- m_map.begin() + 1,
- m_map.end(),
- [text](const auto &x) { return !strcmp(text, x.first); });
+ m_map.begin() + 1,
+ m_map.end(),
+ [&text] (const auto &x) { return text == x.first; });
if (iter == m_map.end())
iter = m_map.begin();
return iter->second;
}
- T operator()(const std::string &text) const
- {
- return (*this)(text.c_str());
- }
-
private:
- std::array<std::pair<const char *, T>, SIZE> m_map;
+ std::array<std::pair<std::string_view, T>, SIZE> m_map;
};
diff --git a/src/frontend/mame/luaengine_input.cpp b/src/frontend/mame/luaengine_input.cpp
index de8157e6dcd..f32858ccce3 100644
--- a/src/frontend/mame/luaengine_input.cpp
+++ b/src/frontend/mame/luaengine_input.cpp
@@ -151,24 +151,32 @@ void lua_engine::initialize_input(sol::table &emu)
ioport_manager_type["type_group"] = sol::overload(
&ioport_manager::type_group,
[] (ioport_manager &im, ioport_type type) { return im.type_group(type, 0); });
- ioport_manager_type["type_seq"] = sol::overload(
- [] (ioport_manager &im, ioport_type type, int player, char const *seq_type_string)
+ ioport_manager_type["type_seq"] =
+ [] (ioport_manager &im, ioport_type type, std::optional<int> player, std::optional<char const *> seq_type_string)
{
- input_seq_type seq_type = s_seq_type_parser(seq_type_string);
- return im.type_seq(type, player, seq_type);
- },
- [] (ioport_manager &im, ioport_type type, int player) { return im.type_seq(type, player, SEQ_TYPE_STANDARD); },
- [] (ioport_manager &im, ioport_type type) { return im.type_seq(type, 0, SEQ_TYPE_STANDARD); });
+ if (!player)
+ player = 0;
+ input_seq_type seq_type = seq_type_string ? s_seq_type_parser(*seq_type_string) : SEQ_TYPE_STANDARD;
+ return im.type_seq(type, *player, seq_type);
+ };
+ ioport_manager_type["set_type_seq"] =
+ [] (ioport_manager &im, ioport_type type, std::optional<int> player, std::optional<char const *> seq_type_string, input_seq const &seq)
+ {
+ if (!player)
+ player = 0;
+ input_seq_type seq_type = seq_type_string ? s_seq_type_parser(*seq_type_string) : SEQ_TYPE_STANDARD;
+ im.set_type_seq(type, *player, seq_type, seq);
+ };
ioport_manager_type["token_to_input_type"] =
- [] (ioport_manager &im, std::string const &string)
- {
- int player;
- ioport_type const type = im.token_to_input_type(string.c_str(), player);
- return std::make_tuple(type, player);
- };
+ [] (ioport_manager &im, std::string const &string)
+ {
+ int player;
+ ioport_type const type = im.token_to_input_type(string.c_str(), player);
+ return std::make_tuple(type, player);
+ };
ioport_manager_type["input_type_to_token"] = sol::overload(
- &ioport_manager::input_type_to_token,
- [] (ioport_manager &im, ioport_type type) { return im.input_type_to_token(type, 0); });
+ &ioport_manager::input_type_to_token,
+ [] (ioport_manager &im, ioport_type type) { return im.input_type_to_token(type, 0); });
ioport_manager_type["ports"] = sol::property([] (ioport_manager &im) { return tag_object_ptr_map<ioport_list>(im.ports()); });
@@ -402,6 +410,17 @@ void lua_engine::initialize_input(sol::table &emu)
seqpoll_type["modified"] = sol::property(&input_sequence_poller::modified);
+ auto iptseq_type = emu.new_usertype<input_seq>(
+ "input_seq",
+ sol::call_constructor, sol::constructors<input_seq(), input_seq(input_seq const &)>());
+ iptseq_type["reset"] = &input_seq::reset;
+ iptseq_type["set_default"] = &input_seq::set_default;
+ iptseq_type["empty"] = sol::property(&input_seq::empty);
+ iptseq_type["length"] = sol::property(&input_seq::length);
+ iptseq_type["is_valid"] = sol::property(&input_seq::is_valid);
+ iptseq_type["is_default"] = sol::property(&input_seq::is_default);
+
+
auto input_class_type = sol().registry().new_usertype<input_class>("input_class", sol::no_constructor);
input_class_type["name"] = sol::property(&input_class::name);
input_class_type["enabled"] = sol::property(&input_class::enabled);