Extend userdata printing
This commit is contained in:
parent
ba1d20dda5
commit
a42c0bf6ea
10 changed files with 90 additions and 12 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <cstdint>
|
||||
#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<uint16_t> pixels;
|
||||
std::string print();
|
||||
};
|
||||
|
||||
struct lua_dbitmap
|
||||
|
@ -23,6 +25,7 @@ struct lua_dbitmap
|
|||
size_t width;
|
||||
size_t height;
|
||||
std::vector<premultiplied_color> 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
|
||||
|
|
|
@ -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<std::string(*)(lua_State* LS, int index)>& 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<luaclass_methods>& userdata_recogn_fns();
|
||||
std::string try_recognize_userdata(lua_State* LS, int index);
|
||||
std::string try_print_userdata(lua_State* LS, int index);
|
||||
|
||||
template<typename T>
|
||||
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<T>::recognize);
|
||||
luaclass_methods m;
|
||||
m.is = lua_class<T>::is;
|
||||
m.name = lua_class<T>::get_name;
|
||||
m.print = lua_class<T>::print;
|
||||
userdata_recogn_fns().push_back(m);
|
||||
}
|
||||
|
||||
template<typename... U> T* _create(lua_State* LS, U... args)
|
||||
|
@ -235,6 +247,17 @@ badtype:
|
|||
{
|
||||
return objclass<T>()._pin(LS, arg, fname);
|
||||
}
|
||||
|
||||
static const std::string& get_name()
|
||||
{
|
||||
return objclass<T>().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)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef _lua__unsaferewind__hpp__included__
|
||||
#define _lua__unsaferewind__hpp__included__
|
||||
|
||||
#include "library/string.hpp"
|
||||
|
||||
struct lua_unsaferewind
|
||||
{
|
||||
std::vector<char> state;
|
||||
|
@ -11,6 +13,10 @@ struct lua_unsaferewind
|
|||
uint64_t ssecs;
|
||||
std::vector<uint32_t> pollcounters;
|
||||
std::vector<char> hostmemory;
|
||||
std::string print()
|
||||
{
|
||||
return (stringfmt() << "to frame " << frame).str();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -670,19 +670,17 @@ bool lua_do_once(lua_State* LS, void* key)
|
|||
}
|
||||
}
|
||||
|
||||
std::list<std::string(*)(lua_State* LS, int index)>& userdata_recogn_fns()
|
||||
std::list<luaclass_methods>& userdata_recogn_fns()
|
||||
{
|
||||
static std::list<std::string(*)(lua_State* LS, int index)> x;
|
||||
static std::list<luaclass_methods> 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;
|
||||
|
|
|
@ -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<std::string, std::pair<mmap_base*, uint64_t>> mappings;
|
||||
|
|
Loading…
Add table
Reference in a new issue