diff --git a/include/lua/bitmap.hpp b/include/lua/bitmap.hpp index 12c0e7d4..46af7997 100644 --- a/include/lua/bitmap.hpp +++ b/include/lua/bitmap.hpp @@ -6,6 +6,7 @@ #include #include "core/window.hpp" #include "library/framebuffer.hpp" +#include "library/string.hpp" struct lua_bitmap { @@ -14,6 +15,7 @@ struct lua_bitmap size_t width; size_t height; std::vector pixels; + std::string print(); }; struct lua_dbitmap @@ -23,6 +25,7 @@ struct lua_dbitmap size_t width; size_t height; std::vector pixels; + std::string print(); }; struct lua_palette @@ -31,6 +34,7 @@ struct lua_palette lua_palette(); ~lua_palette(); mutex* palette_mutex; + std::string print(); }; struct lua_loaded_bitmap diff --git a/include/lua/internal.hpp b/include/lua/internal.hpp index 88cd0ad4..aa30cbea 100644 --- a/include/lua/internal.hpp +++ b/include/lua/internal.hpp @@ -21,8 +21,16 @@ extern bool lua_booted_flag; extern uint64_t lua_idle_hook_time; extern uint64_t lua_timer_hook_time; -std::list& userdata_recogn_fns(); +struct luaclass_methods +{ + bool (*is)(lua_State* LS, int index); + const std::string& (*name)(); + std::string (*print)(lua_State* LS, int index); +}; + +std::list& userdata_recogn_fns(); std::string try_recognize_userdata(lua_State* LS, int index); +std::string try_print_userdata(lua_State* LS, int index); template T get_numeric_argument(lua_State* LS, unsigned argindex, const char* fname) @@ -95,7 +103,11 @@ public: lua_class(const std::string& _name) { name = _name; - userdata_recogn_fns().push_back(lua_class::recognize); + luaclass_methods m; + m.is = lua_class::is; + m.name = lua_class::get_name; + m.print = lua_class::print; + userdata_recogn_fns().push_back(m); } template T* _create(lua_State* LS, U... args) @@ -235,6 +247,17 @@ badtype: { return objclass()._pin(LS, arg, fname); } + + static const std::string& get_name() + { + return objclass().name; + } + + static std::string print(lua_State* LS, int index) + { + T* obj = get(LS, index, "__internal_print"); + return obj->print(); + } private: static int dogc(lua_State* LS) { diff --git a/include/lua/unsaferewind.hpp b/include/lua/unsaferewind.hpp index 0199f031..56842c8d 100644 --- a/include/lua/unsaferewind.hpp +++ b/include/lua/unsaferewind.hpp @@ -1,6 +1,8 @@ #ifndef _lua__unsaferewind__hpp__included__ #define _lua__unsaferewind__hpp__included__ +#include "library/string.hpp" + struct lua_unsaferewind { std::vector state; @@ -11,6 +13,10 @@ struct lua_unsaferewind uint64_t ssecs; std::vector pollcounters; std::vector hostmemory; + std::string print() + { + return (stringfmt() << "to frame " << frame).str(); + } }; #endif diff --git a/src/lua/core.cpp b/src/lua/core.cpp index f3c785ec..b9829678 100644 --- a/src/lua/core.cpp +++ b/src/lua/core.cpp @@ -36,8 +36,8 @@ namespace return (stringfmt() << "Thread:" << lua_topointer(LS, index)).str(); break; case LUA_TUSERDATA: - return (stringfmt() << "Userdata<" << try_recognize_userdata(LS, index) << ">:" - << lua_touserdata(LS, index)).str(); + return (stringfmt() << "Userdata<" << try_recognize_userdata(LS, index) << "@" + << lua_touserdata(LS, index) << ">:[" << try_print_userdata(LS, index) << "]").str(); case LUA_TTABLE: { //Fun with recursion. const void* ptr = lua_topointer(LS, index); diff --git a/src/lua/gui-bitmap.cpp b/src/lua/gui-bitmap.cpp index f1bdc097..076fe397 100644 --- a/src/lua/gui-bitmap.cpp +++ b/src/lua/gui-bitmap.cpp @@ -21,6 +21,11 @@ lua_bitmap::~lua_bitmap() render_kill_request(this); } +std::string lua_bitmap::print() +{ + return (stringfmt() << width << "*" << height).str(); +} + lua_dbitmap::lua_dbitmap(uint32_t w, uint32_t h) { width = w; @@ -33,6 +38,11 @@ lua_dbitmap::~lua_dbitmap() render_kill_request(this); } +std::string lua_dbitmap::print() +{ + return (stringfmt() << width << "*" << height).str(); +} + lua_palette::lua_palette() { palette_mutex = &mutex::aquire(); @@ -43,6 +53,12 @@ lua_palette::~lua_palette() delete palette_mutex; } +std::string lua_palette::print() +{ + size_t s = colors.size(); + return (stringfmt() << s << " " << ((s != 1) ? "colors" : "color")).str(); +} + namespace { struct render_object_bitmap : public render_object diff --git a/src/lua/gui-text-cf.cpp b/src/lua/gui-text-cf.cpp index dc187be7..3382bbfd 100644 --- a/src/lua/gui-text-cf.cpp +++ b/src/lua/gui-text-cf.cpp @@ -15,6 +15,10 @@ namespace ~lua_customfont() throw(); int draw(lua_State* LS); const custom_font& get_font() { return font; } + std::string print() + { + return ""; + } private: custom_font font; }; diff --git a/src/lua/ibind.cpp b/src/lua/ibind.cpp index da263830..ed7a083f 100644 --- a/src/lua/ibind.cpp +++ b/src/lua/ibind.cpp @@ -7,6 +7,10 @@ class lua_inverse_bind { public: lua_inverse_bind(const std::string name, const std::string cmd); + std::string print() + { + return ikey.getname(); + } private: inverse_key ikey; }; diff --git a/src/lua/inputmovie.cpp b/src/lua/inputmovie.cpp index 5d1ce24c..5d1dd926 100644 --- a/src/lua/inputmovie.cpp +++ b/src/lua/inputmovie.cpp @@ -72,6 +72,12 @@ namespace { return f; } + std::string print() + { + char buf[MAX_SERIALIZED_SIZE]; + f.serialize(buf); + return buf; + } private: short getbutton(unsigned port, unsigned controller, unsigned index) { @@ -531,6 +537,11 @@ namespace { return &v; } + std::string print() + { + size_t s = v.size(); + return (stringfmt() << s << " " << ((s != 1) ? "frames" : "frame")).str(); + } private: void common_init(lua_State* L); controller_frame_vector v; diff --git a/src/lua/lua.cpp b/src/lua/lua.cpp index 6913a448..033a117b 100644 --- a/src/lua/lua.cpp +++ b/src/lua/lua.cpp @@ -670,19 +670,17 @@ bool lua_do_once(lua_State* LS, void* key) } } -std::list& userdata_recogn_fns() +std::list& userdata_recogn_fns() { - static std::list x; + static std::list x; return x; } std::string try_recognize_userdata(lua_State* LS, int index) { - for(auto i : userdata_recogn_fns()) { - std::string x = i(LS, index); - if(x != "") - return x; - } + for(auto i : userdata_recogn_fns()) + if(i.is(LS, index)) + return i.name(); //Hack: Lua builtin file objects. lua_pushstring(LS, "FILE*"); lua_rawget(LS, LUA_REGISTRYINDEX); @@ -697,6 +695,14 @@ std::string try_recognize_userdata(lua_State* LS, int index) return "unknown"; } +std::string try_print_userdata(lua_State* LS, int index) +{ + for(auto i : userdata_recogn_fns()) + if(i.is(LS, index)) + return i.print(LS, index); + return "no data available"; +} + bool lua_requests_repaint = false; bool lua_requests_subframe_paint = false; bool lua_supported = true; diff --git a/src/lua/memory.cpp b/src/lua/memory.cpp index eb436e0f..b46a63bd 100644 --- a/src/lua/memory.cpp +++ b/src/lua/memory.cpp @@ -99,7 +99,11 @@ public: x.first->write(LS, x.second); return 0; } - + std::string print() + { + size_t s = mappings.size(); + return (stringfmt() << s << " " << ((s != 1) ? "mappings" : "mapping")).str(); + } int map(lua_State* LS); private: std::map> mappings;