trunk/src/emu/luaengine.c
| r242854 | r242855 | |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | //------------------------------------------------- |
| 439 | // device_get_state - return table of available state userdata |
| 440 | // -> manager:machine().devices[":maincpu"].state |
| 441 | //------------------------------------------------- |
| 442 | |
| 443 | luabridge::LuaRef lua_engine::l_dev_get_states(const device_t *d) |
| 444 | { |
| 445 | device_t *dev = const_cast<device_t *>(d); |
| 446 | lua_State *L = luaThis->m_lua_state; |
| 447 | luabridge::LuaRef st_table = luabridge::LuaRef::newTable(L); |
| 448 | for (const device_state_entry *s = dev->state().state_first(); s != NULL; s = s->next()) { |
| 449 | // XXX: refrain from exporting non-visible entries? |
| 450 | if (s) { |
| 451 | st_table[s->symbol()] = const_cast<device_state_entry *>(s); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | return st_table; |
| 456 | } |
| 457 | |
| 458 | //------------------------------------------------- |
| 459 | // state_get_value - return value of a devices state |
| 460 | // -> manager:machine().devices[":maincpu"].state["PC"].value |
| 461 | //------------------------------------------------- |
| 462 | |
| 463 | UINT64 lua_engine::l_state_get_value(const device_state_entry *d) |
| 464 | { |
| 465 | return d->value(); |
| 466 | } |
| 467 | |
| 468 | //------------------------------------------------- |
| 469 | // state_set_value - set value of a devices state |
| 470 | // -> manager:machine().devices[":maincpu"].state["D0"].value = 0x0c00 |
| 471 | //------------------------------------------------- |
| 472 | |
| 473 | void lua_engine::l_state_set_value(device_state_entry *d, UINT64 val) |
| 474 | { |
| 475 | d->set_value(val); |
| 476 | } |
| 477 | |
| 478 | //------------------------------------------------- |
| 439 | 479 | // mem_read - templated memory readers for <sign>,<size> |
| 440 | 480 | // -> manager:machine().devices[":maincpu"].spaces["program"]:read_i8(0xC000) |
| 441 | 481 | //------------------------------------------------- |
| r242854 | r242855 | |
| 831 | 871 | .addFunction ("shortname", &device_t::shortname) |
| 832 | 872 | .addFunction ("tag", &device_t::tag) |
| 833 | 873 | .addProperty <luabridge::LuaRef, void> ("spaces", &lua_engine::l_dev_get_memspaces) |
| 874 | .addProperty <luabridge::LuaRef, void> ("state", &lua_engine::l_dev_get_states) |
| 834 | 875 | .endClass() |
| 835 | 876 | .beginClass <lua_addr_space> ("lua_addr_space") |
| 836 | 877 | .addCFunction ("read_i8", &lua_addr_space::l_mem_read<INT8>) |
| r242854 | r242855 | |
| 857 | 898 | .addFunction ("height", &screen_device::height) |
| 858 | 899 | .addFunction ("width", &screen_device::width) |
| 859 | 900 | .endClass() |
| 901 | .beginClass <device_state_entry> ("dev_space") |
| 902 | .addFunction ("name", &device_state_entry::symbol) |
| 903 | .addProperty <UINT64, UINT64> ("value", &lua_engine::l_state_get_value, &lua_engine::l_state_set_value) |
| 904 | .addFunction ("is_visible", &device_state_entry::visible) |
| 905 | .addFunction ("is_divider", &device_state_entry::divider) |
| 906 | .endClass() |
| 860 | 907 | .endNamespace(); |
| 861 | 908 | |
| 862 | 909 | luabridge::push (m_lua_state, machine_manager::instance()); |
trunk/src/emu/luaengine.h
| r242854 | r242855 | |
| 104 | 104 | |
| 105 | 105 | // "emu.machine" namespace |
| 106 | 106 | static luabridge::LuaRef l_machine_get_devices(const running_machine *r); |
| 107 | static luabridge::LuaRef devtree_dfs(device_t *root, luabridge::LuaRef dev_table); |
| 108 | static luabridge::LuaRef l_dev_get_states(const device_t *d); |
| 109 | static UINT64 l_state_get_value(const device_state_entry *d); |
| 110 | static void l_state_set_value(device_state_entry *d, UINT64 v); |
| 107 | 111 | static luabridge::LuaRef l_dev_get_memspaces(const device_t *d); |
| 108 | | static luabridge::LuaRef devtree_dfs(device_t *root, luabridge::LuaRef dev_table); |
| 109 | 112 | struct lua_addr_space { |
| 110 | 113 | template<typename T> int l_mem_read(lua_State *L); |
| 111 | 114 | }; |