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 <cstdint>
|
||||||
#include "core/window.hpp"
|
#include "core/window.hpp"
|
||||||
#include "library/framebuffer.hpp"
|
#include "library/framebuffer.hpp"
|
||||||
|
#include "library/string.hpp"
|
||||||
|
|
||||||
struct lua_bitmap
|
struct lua_bitmap
|
||||||
{
|
{
|
||||||
|
@ -14,6 +15,7 @@ struct lua_bitmap
|
||||||
size_t width;
|
size_t width;
|
||||||
size_t height;
|
size_t height;
|
||||||
std::vector<uint16_t> pixels;
|
std::vector<uint16_t> pixels;
|
||||||
|
std::string print();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lua_dbitmap
|
struct lua_dbitmap
|
||||||
|
@ -23,6 +25,7 @@ struct lua_dbitmap
|
||||||
size_t width;
|
size_t width;
|
||||||
size_t height;
|
size_t height;
|
||||||
std::vector<premultiplied_color> pixels;
|
std::vector<premultiplied_color> pixels;
|
||||||
|
std::string print();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lua_palette
|
struct lua_palette
|
||||||
|
@ -31,6 +34,7 @@ struct lua_palette
|
||||||
lua_palette();
|
lua_palette();
|
||||||
~lua_palette();
|
~lua_palette();
|
||||||
mutex* palette_mutex;
|
mutex* palette_mutex;
|
||||||
|
std::string print();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lua_loaded_bitmap
|
struct lua_loaded_bitmap
|
||||||
|
|
|
@ -21,8 +21,16 @@ extern bool lua_booted_flag;
|
||||||
extern uint64_t lua_idle_hook_time;
|
extern uint64_t lua_idle_hook_time;
|
||||||
extern uint64_t lua_timer_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_recognize_userdata(lua_State* LS, int index);
|
||||||
|
std::string try_print_userdata(lua_State* LS, int index);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T get_numeric_argument(lua_State* LS, unsigned argindex, const char* fname)
|
T get_numeric_argument(lua_State* LS, unsigned argindex, const char* fname)
|
||||||
|
@ -95,7 +103,11 @@ public:
|
||||||
lua_class(const std::string& _name)
|
lua_class(const std::string& _name)
|
||||||
{
|
{
|
||||||
name = _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)
|
template<typename... U> T* _create(lua_State* LS, U... args)
|
||||||
|
@ -235,6 +247,17 @@ badtype:
|
||||||
{
|
{
|
||||||
return objclass<T>()._pin(LS, arg, fname);
|
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:
|
private:
|
||||||
static int dogc(lua_State* LS)
|
static int dogc(lua_State* LS)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef _lua__unsaferewind__hpp__included__
|
#ifndef _lua__unsaferewind__hpp__included__
|
||||||
#define _lua__unsaferewind__hpp__included__
|
#define _lua__unsaferewind__hpp__included__
|
||||||
|
|
||||||
|
#include "library/string.hpp"
|
||||||
|
|
||||||
struct lua_unsaferewind
|
struct lua_unsaferewind
|
||||||
{
|
{
|
||||||
std::vector<char> state;
|
std::vector<char> state;
|
||||||
|
@ -11,6 +13,10 @@ struct lua_unsaferewind
|
||||||
uint64_t ssecs;
|
uint64_t ssecs;
|
||||||
std::vector<uint32_t> pollcounters;
|
std::vector<uint32_t> pollcounters;
|
||||||
std::vector<char> hostmemory;
|
std::vector<char> hostmemory;
|
||||||
|
std::string print()
|
||||||
|
{
|
||||||
|
return (stringfmt() << "to frame " << frame).str();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,8 +36,8 @@ namespace
|
||||||
return (stringfmt() << "Thread:" << lua_topointer(LS, index)).str();
|
return (stringfmt() << "Thread:" << lua_topointer(LS, index)).str();
|
||||||
break;
|
break;
|
||||||
case LUA_TUSERDATA:
|
case LUA_TUSERDATA:
|
||||||
return (stringfmt() << "Userdata<" << try_recognize_userdata(LS, index) << ">:"
|
return (stringfmt() << "Userdata<" << try_recognize_userdata(LS, index) << "@"
|
||||||
<< lua_touserdata(LS, index)).str();
|
<< lua_touserdata(LS, index) << ">:[" << try_print_userdata(LS, index) << "]").str();
|
||||||
case LUA_TTABLE: {
|
case LUA_TTABLE: {
|
||||||
//Fun with recursion.
|
//Fun with recursion.
|
||||||
const void* ptr = lua_topointer(LS, index);
|
const void* ptr = lua_topointer(LS, index);
|
||||||
|
|
|
@ -21,6 +21,11 @@ lua_bitmap::~lua_bitmap()
|
||||||
render_kill_request(this);
|
render_kill_request(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string lua_bitmap::print()
|
||||||
|
{
|
||||||
|
return (stringfmt() << width << "*" << height).str();
|
||||||
|
}
|
||||||
|
|
||||||
lua_dbitmap::lua_dbitmap(uint32_t w, uint32_t h)
|
lua_dbitmap::lua_dbitmap(uint32_t w, uint32_t h)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
|
@ -33,6 +38,11 @@ lua_dbitmap::~lua_dbitmap()
|
||||||
render_kill_request(this);
|
render_kill_request(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string lua_dbitmap::print()
|
||||||
|
{
|
||||||
|
return (stringfmt() << width << "*" << height).str();
|
||||||
|
}
|
||||||
|
|
||||||
lua_palette::lua_palette()
|
lua_palette::lua_palette()
|
||||||
{
|
{
|
||||||
palette_mutex = &mutex::aquire();
|
palette_mutex = &mutex::aquire();
|
||||||
|
@ -43,6 +53,12 @@ lua_palette::~lua_palette()
|
||||||
delete palette_mutex;
|
delete palette_mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string lua_palette::print()
|
||||||
|
{
|
||||||
|
size_t s = colors.size();
|
||||||
|
return (stringfmt() << s << " " << ((s != 1) ? "colors" : "color")).str();
|
||||||
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
struct render_object_bitmap : public render_object
|
struct render_object_bitmap : public render_object
|
||||||
|
|
|
@ -15,6 +15,10 @@ namespace
|
||||||
~lua_customfont() throw();
|
~lua_customfont() throw();
|
||||||
int draw(lua_State* LS);
|
int draw(lua_State* LS);
|
||||||
const custom_font& get_font() { return font; }
|
const custom_font& get_font() { return font; }
|
||||||
|
std::string print()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
custom_font font;
|
custom_font font;
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,10 @@ class lua_inverse_bind
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
lua_inverse_bind(const std::string name, const std::string cmd);
|
lua_inverse_bind(const std::string name, const std::string cmd);
|
||||||
|
std::string print()
|
||||||
|
{
|
||||||
|
return ikey.getname();
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
inverse_key ikey;
|
inverse_key ikey;
|
||||||
};
|
};
|
||||||
|
|
|
@ -72,6 +72,12 @@ namespace
|
||||||
{
|
{
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
std::string print()
|
||||||
|
{
|
||||||
|
char buf[MAX_SERIALIZED_SIZE];
|
||||||
|
f.serialize(buf);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
short getbutton(unsigned port, unsigned controller, unsigned index)
|
short getbutton(unsigned port, unsigned controller, unsigned index)
|
||||||
{
|
{
|
||||||
|
@ -531,6 +537,11 @@ namespace
|
||||||
{
|
{
|
||||||
return &v;
|
return &v;
|
||||||
}
|
}
|
||||||
|
std::string print()
|
||||||
|
{
|
||||||
|
size_t s = v.size();
|
||||||
|
return (stringfmt() << s << " " << ((s != 1) ? "frames" : "frame")).str();
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
void common_init(lua_State* L);
|
void common_init(lua_State* L);
|
||||||
controller_frame_vector v;
|
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;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string try_recognize_userdata(lua_State* LS, int index)
|
std::string try_recognize_userdata(lua_State* LS, int index)
|
||||||
{
|
{
|
||||||
for(auto i : userdata_recogn_fns()) {
|
for(auto i : userdata_recogn_fns())
|
||||||
std::string x = i(LS, index);
|
if(i.is(LS, index))
|
||||||
if(x != "")
|
return i.name();
|
||||||
return x;
|
|
||||||
}
|
|
||||||
//Hack: Lua builtin file objects.
|
//Hack: Lua builtin file objects.
|
||||||
lua_pushstring(LS, "FILE*");
|
lua_pushstring(LS, "FILE*");
|
||||||
lua_rawget(LS, LUA_REGISTRYINDEX);
|
lua_rawget(LS, LUA_REGISTRYINDEX);
|
||||||
|
@ -697,6 +695,14 @@ std::string try_recognize_userdata(lua_State* LS, int index)
|
||||||
return "unknown";
|
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_repaint = false;
|
||||||
bool lua_requests_subframe_paint = false;
|
bool lua_requests_subframe_paint = false;
|
||||||
bool lua_supported = true;
|
bool lua_supported = true;
|
||||||
|
|
|
@ -99,7 +99,11 @@ public:
|
||||||
x.first->write(LS, x.second);
|
x.first->write(LS, x.second);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
std::string print()
|
||||||
|
{
|
||||||
|
size_t s = mappings.size();
|
||||||
|
return (stringfmt() << s << " " << ((s != 1) ? "mappings" : "mapping")).str();
|
||||||
|
}
|
||||||
int map(lua_State* LS);
|
int map(lua_State* LS);
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::pair<mmap_base*, uint64_t>> mappings;
|
std::map<std::string, std::pair<mmap_base*, uint64_t>> mappings;
|
||||||
|
|
Loading…
Add table
Reference in a new issue