From e612bea1cb29f95fbf8f0643a5ff46a34945009e Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 3 Nov 2016 11:33:48 +0100 Subject: [PATCH] removed non-operational lua console code (nw) --- src/frontend/mame/luaengine.cpp | 203 -------------------------------- src/frontend/mame/luaengine.h | 8 -- src/frontend/mame/mame.cpp | 1 - 3 files changed, 212 deletions(-) diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp index 4b83314fc62..9cacb72d4a8 100644 --- a/src/frontend/mame/luaengine.cpp +++ b/src/frontend/mame/luaengine.cpp @@ -34,22 +34,6 @@ // LUA ENGINE //************************************************************************** -#if !defined(LUA_PROMPT) -#define LUA_PROMPT "> " -#define LUA_PROMPT2 ">> " -#endif - -#if !defined(LUA_MAXINPUT) -#define LUA_MAXINPUT 512 -#endif - -#define lua_readline(b,p) \ - (fputs(p, stdout), fflush(stdout), /* show prompt */ \ - fgets(b, LUA_MAXINPUT, stdin) != nullptr) /* get line */ - -#define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout) -#define luai_writeline() (luai_writestring("\n", 1), fflush(stdout)) - extern "C" { int luaopen_zlib(lua_State *L); int luaopen_lfs(lua_State *L); @@ -211,190 +195,6 @@ namespace sol } } -struct msg { - std::string text; - int ready; - std::string response; - int status; - int done; -} msg; - -static std::mutex g_mutex; -static lua_State *globalL = nullptr; - -static void lstop(lua_State *L, lua_Debug *ar) -{ - (void)ar; /* unused arg. */ - lua_sethook(L, nullptr, 0, 0); - luaL_error(L, "interrupted!"); -} - - -static void laction(int i) -{ - signal(i, SIG_DFL); /* if another SIGINT happens before lstop, - terminate process (default action) */ - lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); -} - -static int traceback (lua_State *L) -{ - const char *msg = lua_tostring(L, 1); - if (msg) - luaL_traceback(L, L, msg, 1); - else if (!lua_isnoneornil(L, 1)) - { /* is there an error object? */ - if (!luaL_callmeta(L, 1, "__tostring")) /* try its 'tostring' metamethod */ - lua_pushliteral(L, "(no error message)"); - } - return 1; -} - -int lua_engine::docall(int narg, int nres) -{ - int status; - int base = lua_gettop(m_lua_state) - narg; /* function index */ - lua_pushcfunction(m_lua_state, traceback); /* push traceback function */ - lua_insert(m_lua_state, base); /* put it under chunk and args */ - globalL = m_lua_state; /* to be available to 'laction' */ - signal(SIGINT, laction); - status = lua_pcall(m_lua_state, narg, nres, base); - signal(SIGINT, SIG_DFL); - lua_remove(m_lua_state, base); /* remove traceback function */ - return status; -} - -void lua_engine::serve_lua() -{ - osd_sleep(osd_ticks_per_second() / 1000 * 50); - printf("%s v%s\n%s\n%s\n\n", emulator_info::get_appname(),build_version,emulator_info::get_copyright_info(),LUA_COPYRIGHT); - fflush(stdout); - char buff[LUA_MAXINPUT]; - std::string oldbuff; - - const char *b = LUA_PROMPT; - - do { - // Wait for input - fputs(b, stdout); fflush(stdout); /* show prompt */ - fgets(buff, LUA_MAXINPUT, stdin); - - // Create message - { - std::lock_guard lock(g_mutex); - if (msg.ready == 0) { - msg.text = oldbuff; - if (oldbuff.length() != 0) msg.text.append("\n"); - msg.text.append(buff); - msg.ready = 1; - msg.done = 0; - } - } - - // Wait for response - int done; - do { - osd_sleep(osd_ticks_per_second() / 1000); - std::lock_guard lock(g_mutex); - done = msg.done; - } while (done==0); - - // Do action on client side - { - std::lock_guard lock(g_mutex); - - if (msg.status == -1) { - b = LUA_PROMPT2; - oldbuff = msg.response; - } - else { - b = LUA_PROMPT; - oldbuff = ""; - } - msg.done = 0; - } - - } while (1); -} - -static void *serve_lua(void *param) -{ - lua_engine *engine = (lua_engine *)param; - engine->serve_lua(); - return nullptr; -} - -void lua_engine::periodic_check() -{ - std::lock_guard lock(g_mutex); - if (msg.ready == 1) { - lua_settop(m_lua_state, 0); - int status = luaL_loadbuffer(m_lua_state, msg.text.c_str(), msg.text.length(), "=stdin"); - if (incomplete(status)==0) /* cannot try to add lines? */ - { - if (status == LUA_OK) status = docall(0, LUA_MULTRET); - report(status); - if (status == LUA_OK && lua_gettop(m_lua_state) > 0) /* any result to print? */ - { - luaL_checkstack(m_lua_state, LUA_MINSTACK, "too many results to print"); - lua_getglobal(m_lua_state, "print"); - lua_insert(m_lua_state, 1); - if (lua_pcall(m_lua_state, lua_gettop(m_lua_state) - 1, 0, 0) != LUA_OK) - lua_writestringerror("%s\n", lua_pushfstring(m_lua_state, - "error calling " LUA_QL("print") " (%s)", - lua_tostring(m_lua_state, -1))); - } - } - else - { - status = -1; - } - msg.status = status; - msg.response = msg.text; - msg.text = ""; - msg.ready = 0; - msg.done = 1; - } -} - -int lua_engine::report(int status) { - if (status != LUA_OK && !lua_isnil(m_lua_state, -1)) - { - const char *msg = lua_tostring(m_lua_state, -1); - if (msg == nullptr) msg = "(error object is not a string)"; - lua_writestringerror("%s\n", msg); - lua_pop(m_lua_state, 1); - /* force a complete garbage collection in case of errors */ - lua_gc(m_lua_state, LUA_GCCOLLECT, 0); - } - return status; -} - -/* mark in error messages for incomplete statements */ -#define EOFMARK "" -#define marklen (sizeof(EOFMARK)/sizeof(char) - 1) - -int lua_engine::incomplete(int status) -{ - if (status == LUA_ERRSYNTAX) - { - size_t lmsg; - const char *msg = lua_tolstring(m_lua_state, -1, &lmsg); - if (lmsg >= marklen && strcmp(msg + lmsg - marklen, EOFMARK) == 0) - { - lua_pop(m_lua_state, 1); - return 1; - } - } - return 0; /* else... */ -} - -void lua_engine::start_console() -{ - std::thread th(::serve_lua, this); - th.detach(); -} - //------------------------------------------------- // mem_read - templated memory readers for , // -> manager:machine().devices[":maincpu"].spaces["program"]:read_i8(0xC000) @@ -729,9 +529,6 @@ lua_engine::lua_engine() sol()["package"]["preload"]["lfs"] = &luaopen_lfs; lua_gc(m_lua_state, LUA_GCRESTART, 0); - msg.ready = 0; - msg.status = 0; - msg.done = 0; } //------------------------------------------------- diff --git a/src/frontend/mame/luaengine.h b/src/frontend/mame/luaengine.h index 8bda7ca143a..f381edcfc87 100644 --- a/src/frontend/mame/luaengine.h +++ b/src/frontend/mame/luaengine.h @@ -32,12 +32,9 @@ public: ~lua_engine(); void initialize(); - void start_console(); void load_script(const char *filename); void load_string(const char *value); - void serve_lua(); - void periodic_check(); bool frame_hook(); void menu_populate(const std::string &menu, std::vector> &menu_list); @@ -116,8 +113,6 @@ private: running_machine &machine() const { return *m_machine; } - void update_machine(); - void on_machine_prestart(); void on_machine_start(); void on_machine_stop(); @@ -157,9 +152,6 @@ private: void close(); - int report(int status); - int incomplete(int status) ; - int docall(int narg, int nres); void run(sol::load_result res); }; diff --git a/src/frontend/mame/mame.cpp b/src/frontend/mame/mame.cpp index 5a8b0c01581..155b949f181 100644 --- a/src/frontend/mame/mame.cpp +++ b/src/frontend/mame/mame.cpp @@ -326,7 +326,6 @@ void emulator_info::draw_user_interface(running_machine& machine) void emulator_info::periodic_check() { - mame_machine_manager::instance()->lua()->periodic_check(); } bool emulator_info::frame_hook()