Merge pull request #100 from lucab/lucab/mame-lua/devstate

luaengine: expose device state entries
This commit is contained in:
Miodrag Milanović 2015-01-11 10:43:24 +01:00
commit bad1ab38e4
3 changed files with 75 additions and 2 deletions

View File

@ -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

View File

@ -435,6 +435,46 @@ luabridge::LuaRef lua_engine::l_dev_get_memspaces(const device_t *d)
return sp_table;
}
//-------------------------------------------------
// 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));
}
};
}

View File

@ -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);
};