Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/emu/distate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 70 additions & 1 deletion src/emu/luaengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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>)
Expand All @@ -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());
Expand Down Expand Up @@ -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));
}
};
}
5 changes: 4 additions & 1 deletion src/emu/luaengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ class lua_engine

// "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);
};
Expand Down