trunk/src/emu/luaengine.c
| r242704 | r242705 | |
| 337 | 337 | return 0; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | int lua_engine::l_emu_set_hook(lua_State *L) |
| 341 | { |
| 342 | luaThis->emu_set_hook(L); |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | void lua_engine::emu_set_hook(lua_State *L) |
| 347 | { |
| 348 | luaL_argcheck(L, lua_isfunction(L, 1) || lua_isnil(L, 1), 1, "callback function expected"); |
| 349 | luaL_argcheck(L, lua_isstring(L, 2), 2, "message (string) expected"); |
| 350 | const char *hookname = luaL_checkstring(L,2); |
| 351 | |
| 352 | if (strcmp(hookname, "output") == 0) { |
| 353 | hook_output_cb.set(L, 1); |
| 354 | if (!output_notifier_set) { |
| 355 | output_set_notifier(NULL, s_output_notifier, this); |
| 356 | output_notifier_set = true; |
| 357 | } |
| 358 | } else if (strcmp(hookname, "frame") == 0) { |
| 359 | hook_frame_cb.set(L, 1); |
| 360 | } else { |
| 361 | luai_writestringerror("%s", "Unknown hook name, aborting.\n"); |
| 362 | } |
| 363 | } |
| 364 | |
| 340 | 365 | //------------------------------------------------- |
| 341 | 366 | // machine_get_screens - return table of available screens userdata |
| 342 | 367 | // -> manager:machine().screens[":screen"] |
| r242704 | r242705 | |
| 773 | 798 | .addCFunction ("romname", l_emu_romname ) |
| 774 | 799 | .addCFunction ("keypost", l_emu_keypost ) |
| 775 | 800 | .addCFunction ("hook_output", l_emu_hook_output ) |
| 801 | .addCFunction ("sethook", l_emu_set_hook ) |
| 776 | 802 | .addCFunction ("time", l_emu_time ) |
| 777 | 803 | .addCFunction ("wait", l_emu_wait ) |
| 778 | 804 | .addCFunction ("after", l_emu_after ) |
| r242704 | r242705 | |
| 836 | 862 | mg_start_thread(::serve_lua, this); |
| 837 | 863 | } |
| 838 | 864 | |
| 865 | //------------------------------------------------- |
| 866 | // frame_hook - called at each frame refresh, used to draw a HUD |
| 867 | //------------------------------------------------- |
| 868 | bool lua_engine::frame_hook() |
| 869 | { |
| 870 | bool is_cb_hooked = false; |
| 871 | if (m_machine != NULL) { |
| 872 | // invoke registered callback (if any) |
| 873 | is_cb_hooked = hook_frame_cb.active(); |
| 874 | if (is_cb_hooked) { |
| 875 | lua_State *L = hook_frame_cb.precall(); |
| 876 | hook_frame_cb.call(this, L, 0); |
| 877 | } |
| 878 | } |
| 879 | return is_cb_hooked; |
| 880 | } |
| 881 | |
| 839 | 882 | void lua_engine::periodic_check() |
| 840 | 883 | { |
| 841 | 884 | osd_lock_acquire(lock); |
trunk/src/emu/luaengine.h
| r242704 | r242705 | |
| 44 | 44 | |
| 45 | 45 | void serve_lua(); |
| 46 | 46 | void periodic_check(); |
| 47 | bool frame_hook(); |
| 47 | 48 | |
| 48 | 49 | void resume(lua_State *L, int nparam = 0, lua_State *root = NULL); |
| 49 | 50 | void set_machine(running_machine *machine) { m_machine = machine; update_machine(); } |
| r242704 | r242705 | |
| 68 | 69 | hook hook_output_cb; |
| 69 | 70 | bool output_notifier_set; |
| 70 | 71 | |
| 72 | hook hook_frame_cb; |
| 73 | |
| 71 | 74 | static lua_engine* luaThis; |
| 72 | 75 | |
| 73 | 76 | std::map<lua_State *, std::pair<lua_State *, int> > thread_registry; |
| r242704 | r242705 | |
| 82 | 85 | int emu_after(lua_State *L); |
| 83 | 86 | int emu_wait(lua_State *L); |
| 84 | 87 | void emu_hook_output(lua_State *L); |
| 88 | void emu_set_hook(lua_State *L); |
| 85 | 89 | |
| 86 | 90 | static int l_ioport_write(lua_State *L); |
| 87 | 91 | static int l_emu_after(lua_State *L); |
| r242704 | r242705 | |
| 97 | 101 | static int l_emu_start(lua_State *L); |
| 98 | 102 | static int l_emu_pause(lua_State *L); |
| 99 | 103 | static int l_emu_unpause(lua_State *L); |
| 104 | static int l_emu_set_hook(lua_State *L); |
| 100 | 105 | |
| 101 | 106 | // "emu.machine" namespace |
| 102 | 107 | static luabridge::LuaRef l_machine_get_devices(const running_machine *r); |