diff --git a/include/core/memorywatch.hpp b/include/core/memorywatch.hpp index f03d936c..7794bb88 100644 --- a/include/core/memorywatch.hpp +++ b/include/core/memorywatch.hpp @@ -167,9 +167,17 @@ struct lsnes_memorywatch_set * Parameter rq: The render queue to use. */ void watch(struct framebuffer::queue& rq); +/** + * Get memory watch vars that go to window. + */ + const std::map& get_window_vars() { return window_vars; } private: void rebuild(std::map& nitems); std::map items; + std::map window_vars; + std::map used_memorywatches; + void erase_unused_watches(); + void memorywatch_output(const std::string& name, const std::string& value); memorywatch_set watch_set; }; diff --git a/include/lua/lua.hpp b/include/lua/lua.hpp index 7166f63d..b9ee9a4e 100644 --- a/include/lua/lua.hpp +++ b/include/lua/lua.hpp @@ -1,6 +1,8 @@ #ifndef _lua__hpp__included__ #define _lua__hpp__included__ +#include +#include #include "core/controllerframe.hpp" #include "library/movie.hpp" #include "library/framebuffer.hpp" @@ -35,10 +37,12 @@ void lua_callback_do_latch(std::list& args); void lua_run_startup_scripts(); void lua_add_startup_script(const std::string& file); + #define LUA_TIMED_HOOK_IDLE 0 #define LUA_TIMED_HOOK_TIMER 1 uint64_t lua_timed_hook(int timer) throw(); +const std::map& get_lua_watch_vars(); extern bool lua_requests_repaint; extern bool lua_requests_subframe_paint; diff --git a/src/core/mainloop.cpp b/src/core/mainloop.cpp index d1699d30..7c3f80d3 100644 --- a/src/core/mainloop.cpp +++ b/src/core/mainloop.cpp @@ -426,6 +426,29 @@ void update_movie_state() } _status.set((stringfmt() << "P" << (i + 1)).str(), _buffer); } + //Lua variables. + { + static std::map old_luavars; + auto& lvars = get_lua_watch_vars(); + for(auto i : old_luavars) + if(!lvars.count(i.first)) + _status.erase("L[" + i.first + "]"); + for(auto i : lvars) + _status.set("L[" + i.first + "]", i.second); + old_luavars = lvars; + } + //Memory watches. + { + static std::map old_memvars; + auto& mvars = lsnes_memorywatch.get_window_vars(); + for(auto i : old_memvars) + if(!mvars.count(i.first)) + _status.erase("M[" + i.first + "]"); + for(auto i : mvars) + _status.set("M[" + i.first + "]", i.second); + old_memvars = mvars; + } + notify_status_update(); } diff --git a/src/core/memorywatch.cpp b/src/core/memorywatch.cpp index 135a8296..dc04bcce 100644 --- a/src/core/memorywatch.cpp +++ b/src/core/memorywatch.cpp @@ -27,6 +27,7 @@ namespace { std::map> fonts_in_use; + std::map memorywatch_vars; framebuffer::font2& get_builtin_font2() { @@ -72,24 +73,6 @@ namespace } } - std::map used_memorywatches; - void memorywatch_output_fn(const std::string& name, const std::string& value) - { - auto& status = platform::get_emustatus(); - used_memorywatches[name] = true; - status.set("M[" + name + "]", value); - } - - void erase_unused_watches() - { - auto& status = platform::get_emustatus(); - for(auto& i : used_memorywatches) { - if(!i.second) - status.erase("M[" + i.first + "]"); - i.second = false; - } - } - std::string json_string_default(const JSON::node& node, const std::string& pointer, const std::string& dflt) { return (node.type_of(pointer) == JSON::string) ? node[pointer].as_string8() : dflt; @@ -109,6 +92,8 @@ namespace { return (node.type_of(pointer) == JSON::boolean) ? node[pointer].as_bool() : dflt; } + + void dummy_target_fn(const std::string& n, const std::string& v) {} } lsnes_memorywatch_printer::lsnes_memorywatch_printer() @@ -193,7 +178,7 @@ gcroot_pointer lsnes_memorywatch_printer::get_printer_ } catch(std::exception& e) { (stringfmt() << "Error while parsing conditional: " << e.what()).throwex(); } - l->set_output(memorywatch_output_fn); + l->set_output(dummy_target_fn); break; case PC_ONSCREEN: ptr = gcroot_pointer(new memorywatch_output_fb); @@ -530,6 +515,14 @@ void lsnes_memorywatch_set::rebuild(std::map(rt_printer.as_pointer()); + if(list_obj) + list_obj->set_output([this](const std::string& n, const std::string& v) { + this->memorywatch_output(n, v); + }); + memorywatch_item it(*expression_value()); *vars_fn(i.first) = *rt_expr; it.expr = vars_fn(i.first); @@ -546,4 +539,19 @@ void lsnes_memorywatch_set::rebuild(std::map lua_watch_vars; + template int lua_gui_set_gap(lua::state& L, lua::parameters& P) { @@ -70,11 +74,11 @@ namespace P(name, value); - auto& w = platform::get_emustatus(); if(value == "") - w.erase("L[" + name + "]"); + lua_watch_vars.erase(name); else - w.set("L[" + name + "]", value); + lua_watch_vars[name] = utf8::to32(value); + update_movie_state(); return 1; } @@ -130,3 +134,8 @@ namespace {"set_video_scale", set_video_scale}, }); } + +const std::map& get_lua_watch_vars() +{ + return lua_watch_vars; +} \ No newline at end of file