summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Miodrag Milanović <mmicko@gmail.com>2015-01-11 10:43:24 +0100
committer Miodrag Milanović <mmicko@gmail.com>2015-01-11 10:43:24 +0100
commitbad1ab38e480dbcaa8d178dddaaa3fc1313fc142 (patch)
treeda27ae405c893180775423511f4ad9a87bd398ec
parente41f7ec65efb98ccc9672349fd62992b7828dbcf (diff)
parent7465f69e223de9271bcab206f1088e9eafd297ca (diff)
Merge pull request #100 from lucab/lucab/mame-lua/devstate
luaengine: expose device state entries
-rw-r--r--src/emu/distate.h1
-rw-r--r--src/emu/luaengine.c71
-rw-r--r--src/emu/luaengine.h5
3 files changed, 75 insertions, 2 deletions
diff --git a/src/emu/distate.h b/src/emu/distate.h
index 30d742b307d..7b5117e19e2 100644
--- a/src/emu/distate.h
+++ b/src/emu/distate.h
@@ -45,6 +45,7 @@ class device_state_entry
{
friend class device_state_interface;
friend class simple_list<device_state_entry>;
+ friend class lua_engine;
private:
// construction/destruction
diff --git a/src/emu/luaengine.c b/src/emu/luaengine.c
index 6db3a48b2f2..8f22617e45d 100644
--- a/src/emu/luaengine.c
+++ b/src/emu/luaengine.c
@@ -436,6 +436,46 @@ luabridge::LuaRef lua_engine::l_dev_get_memspaces(const device_t *d)
}
//-------------------------------------------------
+// device_get_state - return table of available state userdata
+// -> manager:machine().devices[":maincpu"].state
+//-------------------------------------------------
+
+luabridge::LuaRef lua_engine::l_dev_get_states(const device_t *d)
+{
+ device_t *dev = const_cast<device_t *>(d);
+ lua_State *L = luaThis->m_lua_state;
+ luabridge::LuaRef st_table = luabridge::LuaRef::newTable(L);
+ for (const device_state_entry *s = dev->state().state_first(); s != NULL; s = s->next()) {
+ // XXX: refrain from exporting non-visible entries?
+ if (s) {
+ st_table[s->symbol()] = const_cast<device_state_entry *>(s);
+ }
+ }
+
+ return st_table;
+}
+
+//-------------------------------------------------
+// state_get_value - return value of a devices state
+// -> manager:machine().devices[":maincpu"].state["PC"].value
+//-------------------------------------------------
+
+UINT64 lua_engine::l_state_get_value(const device_state_entry *d)
+{
+ return d->value();
+}
+
+//-------------------------------------------------
+// state_set_value - set value of a devices state
+// -> manager:machine().devices[":maincpu"].state["D0"].value = 0x0c00
+//-------------------------------------------------
+
+void lua_engine::l_state_set_value(device_state_entry *d, UINT64 val)
+{
+ d->set_value(val);
+}
+
+//-------------------------------------------------
// mem_read - templated memory readers for <sign>,<size>
// -> manager:machine().devices[":maincpu"].spaces["program"]:read_i8(0xC000)
//-------------------------------------------------
@@ -827,8 +867,11 @@ void lua_engine::initialize()
.addData ("manufacturer", &game_driver::manufacturer)
.endClass ()
.beginClass <device_t> ("device")
- .addFunction("name", &device_t::tag)
+ .addFunction ("name", &device_t::name)
+ .addFunction ("shortname", &device_t::shortname)
+ .addFunction ("tag", &device_t::tag)
.addProperty <luabridge::LuaRef, void> ("spaces", &lua_engine::l_dev_get_memspaces)
+ .addProperty <luabridge::LuaRef, void> ("state", &lua_engine::l_dev_get_states)
.endClass()
.beginClass <lua_addr_space> ("lua_addr_space")
.addCFunction ("read_i8", &lua_addr_space::l_mem_read<INT8>)
@@ -850,9 +893,17 @@ void lua_engine::initialize()
.endClass()
.deriveClass <screen_device, lua_screen> ("screen_dev")
.addFunction ("name", &screen_device::name)
+ .addFunction ("shortname", &screen_device::shortname)
+ .addFunction ("tag", &screen_device::tag)
.addFunction ("height", &screen_device::height)
.addFunction ("width", &screen_device::width)
.endClass()
+ .beginClass <device_state_entry> ("dev_space")
+ .addFunction ("name", &device_state_entry::symbol)
+ .addProperty <UINT64, UINT64> ("value", &lua_engine::l_state_get_value, &lua_engine::l_state_set_value)
+ .addFunction ("is_visible", &device_state_entry::visible)
+ .addFunction ("is_divider", &device_state_entry::divider)
+ .endClass()
.endNamespace();
luabridge::push (m_lua_state, machine_manager::instance());
@@ -957,3 +1008,21 @@ void lua_engine::start()
{
resume(m_lua_state);
}
+
+
+//**************************************************************************
+// LuaBridge Stack specializations
+//**************************************************************************
+
+namespace luabridge {
+ template <>
+ struct Stack <UINT64> {
+ static inline void push (lua_State* L, UINT64 value) {
+ lua_pushunsigned(L, static_cast <lua_Unsigned> (value));
+ }
+
+ static inline UINT64 get (lua_State* L, int index) {
+ return static_cast <UINT64> (luaL_checkunsigned (L, index));
+ }
+ };
+}
diff --git a/src/emu/luaengine.h b/src/emu/luaengine.h
index 6206b426a36..8f261370214 100644
--- a/src/emu/luaengine.h
+++ b/src/emu/luaengine.h
@@ -104,8 +104,11 @@ private:
// "emu.machine" namespace
static luabridge::LuaRef l_machine_get_devices(const running_machine *r);
- static luabridge::LuaRef l_dev_get_memspaces(const device_t *d);
static luabridge::LuaRef devtree_dfs(device_t *root, luabridge::LuaRef dev_table);
+ static luabridge::LuaRef l_dev_get_states(const device_t *d);
+ static UINT64 l_state_get_value(const device_state_entry *d);
+ static void l_state_set_value(device_state_entry *d, UINT64 v);
+ static luabridge::LuaRef l_dev_get_memspaces(const device_t *d);
struct lua_addr_space {
template<typename T> int l_mem_read(lua_State *L);
};