diff options
Diffstat (limited to 'src/emu/luaengine.c')
-rw-r--r-- | src/emu/luaengine.c | 71 |
1 files changed, 70 insertions, 1 deletions
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)); + } + }; +} |