Merge branch 'rr1-maint'

This commit is contained in:
Ilari Liusvaara 2013-09-27 10:47:19 +03:00
commit 59ef6961e3
16 changed files with 141 additions and 24 deletions

View file

@ -109,6 +109,10 @@ public:
* Get long help for command.
*/
virtual std::string get_long_help() throw(std::bad_alloc);
/**
* Get name of command.
*/
const std::string& get_name() { return commandname; }
private:
command(const command&);
command& operator=(const command&);

View file

@ -582,6 +582,19 @@ struct render_queue
{
create_add<T>(*obj);
}
/**
* Get number of objects.
*/
size_t get_object_count()
{
size_t c = 0;
struct node* n = queue_head;
while(n != queue_tail) {
n = n->next;
c++;
}
return c;
}
/**
* Constructor.
*/

View file

@ -16,8 +16,16 @@ extern "C"
class lua_state;
std::list<std::string(*)(lua_state& state, int index)>& userdata_recogn_fns();
struct luaclass_methods
{
bool (*is)(lua_state& state, int index);
const std::string& (*name)();
std::string (*print)(lua_state& state, int index);
};
std::list<luaclass_methods>& userdata_recogn_fns();
std::string try_recognize_userdata(lua_state& state, int index);
std::string try_print_userdata(lua_state& state, int index);
struct lua_function;
@ -716,11 +724,6 @@ badtype:
return ret;
}
std::string _recognize(lua_state& state, int arg)
{
return _is(state, arg) ? name : "";
}
lua_obj_pin<T> _pin(lua_state& state, int arg, const std::string& fname)
{
T* obj = get(state, arg, fname);
@ -736,7 +739,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);
}
/**
@ -810,16 +817,20 @@ public:
return objclass<T>()._is(state, arg);
}
/**
* Identify if object is of this type.
* Parameter state: The Lua state.
* Parameter arg: Argument index.
* Returns: Name of type if object is of specified type, "" if not.
* Get name of class.
*/
static std::string recognize(lua_state& state, int arg)
static const std::string& get_name()
{
return objclass<T>()._recognize(state, arg);
return objclass<T>().name;
}
/**
* Format instance of this class as string.
*/
static std::string print(lua_state& state, int index)
{
T* obj = get(state, index, "__internal_print");
return obj->print();
}
/**
* Get a pin of object against Lua GC.
*

View file

@ -8,6 +8,7 @@
#include "library/luabase.hpp"
#include "library/framebuffer.hpp"
#include "library/threadtypes.hpp"
#include "library/string.hpp"
struct lua_bitmap
{
@ -16,6 +17,7 @@ struct lua_bitmap
size_t width;
size_t height;
std::vector<uint16_t> pixels;
std::string print();
};
struct lua_dbitmap
@ -25,6 +27,7 @@ struct lua_dbitmap
size_t width;
size_t height;
std::vector<premultiplied_color> pixels;
std::string print();
};
struct lua_palette
@ -33,6 +36,7 @@ struct lua_palette
lua_palette(lua_state& L);
~lua_palette();
mutex_class palette_mutex;
std::string print();
};
struct lua_loaded_bitmap

View file

@ -2,6 +2,7 @@
#define _lua__unsaferewind__hpp__included__
#include "library/luabase.hpp"
#include "library/string.hpp"
struct lua_unsaferewind
{
@ -14,6 +15,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

View file

@ -308,19 +308,17 @@ void lua_function_group::do_unregister(const std::string& name)
i.second(name, NULL);
}
std::list<std::string(*)(lua_state& state, int index)>& userdata_recogn_fns()
std::list<luaclass_methods>& userdata_recogn_fns()
{
static std::list<std::string(*)(lua_state& state, int index)> x;
static std::list<luaclass_methods> x;
return x;
}
std::string try_recognize_userdata(lua_state& state, int index)
{
for(auto i : userdata_recogn_fns()) {
std::string x = i(state, index);
if(x != "")
return x;
}
for(auto i : userdata_recogn_fns())
if(i.is(state, index))
return i.name();
//Hack: Lua builtin file objects.
state.pushstring("FILE*");
state.rawget(LUA_REGISTRYINDEX);
@ -334,3 +332,11 @@ std::string try_recognize_userdata(lua_state& state, int index)
state.pop(1);
return "unknown";
}
std::string try_print_userdata(lua_state& L, int index)
{
for(auto i : userdata_recogn_fns())
if(i.is(L, index))
return i.print(L, index);
return "no data available";
}

View file

@ -10,6 +10,10 @@ namespace
lua_callbacks_list(lua_state& L);
int index(lua_state& L, const std::string& fname);
int newindex(lua_state& L, const std::string& fname);
std::string print()
{
return "";
}
};
class lua_callback_obj
@ -19,6 +23,13 @@ namespace
int _register(lua_state& L, const std::string& fname);
int _unregister(lua_state& L, const std::string& fname);
int _call(lua_state& L, const std::string& fname);
std::string print()
{
if(callback)
return callback->get_name();
else
return "(null)";
}
private:
lua_state::lua_callback_list* callback;
int special;

View file

@ -38,8 +38,8 @@ namespace
return (stringfmt() << "Thread:" << L.topointer(index)).str();
break;
case LUA_TUSERDATA:
return (stringfmt() << "Userdata<" << try_recognize_userdata(L, index) << ">:"
<< L.touserdata(index)).str();
return (stringfmt() << "Userdata<" << try_recognize_userdata(L, index) << "@"
<< L.touserdata(index) << ">:[" << try_print_userdata(L, index) << "]").str();
case LUA_TTABLE: {
//Fun with recursion.
const void* ptr = L.topointer(index);

View file

@ -22,6 +22,11 @@ lua_bitmap::~lua_bitmap()
render_kill_request(this);
}
std::string lua_bitmap::print()
{
return (stringfmt() << width << "*" << height).str();
}
lua_dbitmap::lua_dbitmap(lua_state& L, uint32_t w, uint32_t h)
{
width = w;
@ -34,6 +39,11 @@ lua_dbitmap::~lua_dbitmap()
render_kill_request(this);
}
std::string lua_dbitmap::print()
{
return (stringfmt() << width << "*" << height).str();
}
lua_palette::lua_palette(lua_state& L)
{
}
@ -42,6 +52,12 @@ lua_palette::~lua_palette()
{
}
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

View file

@ -22,6 +22,11 @@ namespace
}
~render_queue_obj() throw() {}
lua_render_context* get() { return &lctx; }
std::string print()
{
size_t s = rqueue.get_object_count();
return (stringfmt() << s << " " << ((s != 1) ? "objects" : "object")).str();
}
private:
render_queue rqueue;
lua_render_context lctx;

View file

@ -16,6 +16,10 @@ namespace
~lua_customfont() throw();
int draw(lua_state& L, const std::string& fname);
const custom_font& get_font() { return font; }
std::string print()
{
return "";
}
private:
custom_font font;
};

View file

@ -7,6 +7,10 @@ class lua_inverse_bind
{
public:
lua_inverse_bind(lua_state& L, const std::string& name, const std::string& cmd);
std::string print()
{
return ikey.getname();
}
private:
inverse_bind ikey;
};
@ -49,6 +53,13 @@ class lua_command_bind
public:
lua_command_bind(lua_state& L, const std::string& cmd, int idx1, int idx2);
~lua_command_bind();
std::string print()
{
if(b)
return a->get_name() + "," + b->get_name();
else
return a->get_name();
}
private:
lua_command_binding* a;
lua_command_binding* b;

View file

@ -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)
{
@ -477,6 +483,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;

View file

@ -208,6 +208,10 @@ namespace
{
reinterpret_cast<lua_file_reader*>(lua_touserdata(L, lua_upvalueindex(1)))->lines_helper(L);
}
std::string print()
{
return "";
}
private:
std::istream& s;
};

View file

@ -123,8 +123,12 @@ public:
x.first->write(L, x.second);
return 0;
}
int map(lua_state& L, const std::string& fname);
std::string print()
{
size_t s = mappings.size();
return (stringfmt() << s << " " << ((s != 1) ? "mappings" : "mapping")).str();
}
private:
std::map<std::string, std::pair<mmap_base*, uint64_t>> mappings;
};

View file

@ -53,6 +53,10 @@ namespace
int info(lua_state& L, const std::string& fname);
template<class T, bool _bswap> int rw(lua_state& L, const std::string& fname);
template<bool write, bool sign> int scattergather(lua_state& L, const std::string& fname);
std::string print()
{
return vma;
}
private:
std::string vma;
uint64_t vmabase;
@ -67,6 +71,10 @@ namespace
int index(lua_state& L, const std::string& fname);
int newindex(lua_state& L, const std::string& fname);
int call(lua_state& L, const std::string& fname);
std::string print()
{
return "";
}
};
}