Lua: Reset Lua VM function

This commit is contained in:
Ilari Liusvaara 2012-06-06 21:58:03 +03:00
parent a0495d018f
commit 3548315ccb
4 changed files with 27 additions and 3 deletions

View file

@ -67,7 +67,7 @@ struct lua_render_context
uint32_t height;
};
void init_lua() throw();
void init_lua(bool soft = false) throw();
void quit_lua() throw();
void lua_callback_do_paint(struct lua_render_context* ctx, bool non_synthethic) throw();
void lua_callback_do_video(struct lua_render_context* ctx) throw();

View file

@ -24,7 +24,7 @@ void lua_callback_post_save(const std::string& name, bool is_state) throw() {}
void lua_callback_snoop_input(uint32_t port, uint32_t controller, uint32_t index, short value) throw() {}
void lua_callback_quit() throw() {}
void lua_callback_keyhook(const std::string& key, const struct keygroup::parameters& p) throw() {}
void init_lua() throw() {}
void init_lua(bool soft) throw() {}
void quit_lua() throw() {}
uint64_t lua_timed_hook(int timer) throw() { return 0x7EFFFFFFFFFFFFFFULL; }
void lua_callback_do_unsafe_rewind(const std::vector<char>& save, uint64_t secs, uint64_t ssecs, movie& mov, void* u)

View file

@ -506,6 +506,22 @@ namespace
{
do_run_lua(args);
});
function_ptr_command<> reset_lua("reset-lua", "Reset the Lua VM",
"Syntax: reset-lua\nReset the Lua VM.\n",
[]() throw(std::bad_alloc, std::runtime_error)
{
lua_State* L = lua_initialized;
lua_initialized = NULL;
init_lua(true);
if(!lua_initialized) {
lua_initialized = L;
return;
}
lua_close(L);
messages << "Lua VM reset" << std::endl;
});
}
void lua_callback_quit() throw()
@ -524,11 +540,13 @@ void lua_callback_keyhook(const std::string& key, const struct keygroup::paramet
run_lua_cb(2);
}
void init_lua() throw()
void init_lua(bool soft) throw()
{
L = lua_newstate(alloc, NULL);
if(!L) {
messages << "Can't initialize Lua." << std::endl;
if(soft)
return;
fatal_error();
}
luaL_openlibs(L);

View file

@ -57,6 +57,7 @@ enum
wxID_LOAD_MOVIE,
wxID_RUN_SCRIPT,
wxID_RUN_LUA,
wxID_RESET_LUA,
wxID_EVAL_LUA,
wxID_SAVE_SCREENSHOT,
wxID_READONLY_MODE,
@ -706,6 +707,8 @@ wxwin_mainwindow::wxwin_mainwindow()
menu_separator();
menu_entry(wxID_EVAL_LUA, wxT("Evaluate Lua statement..."));
menu_entry(wxID_RUN_LUA, wxT("Run Lua script..."));
menu_separator();
menu_entry(wxID_RESET_LUA, wxT("Reset Lua VM"));
}
menu_separator();
menu_entry(wxID_EDIT_MEMORYWATCH, wxT("Edit memory watch..."));
@ -849,6 +852,9 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e)
case wxID_RUN_LUA:
platform::queue("run-lua " + pick_file(this, "Select Lua Script", "."));
return;
case wxID_RESET_LUA:
platform::queue("reset-lua");
return;
case wxID_EVAL_LUA:
platform::queue("evaluate-lua " + pick_text(this, "Evaluate Lua", "Enter Lua Statement:"));
return;