Lua: Give the print method as pointer instead of assuming T::print

This commit is contained in:
Ilari Liusvaara 2014-01-29 11:32:52 +02:00
parent 5f6b59b766
commit 85d78e2632
14 changed files with 38 additions and 33 deletions

View file

@ -305,13 +305,15 @@ public:
* Parameter _name: The name of the class.
* Parameter _smethods: Static methods of the class.
* Parameter _cmethods: Class methods of the class.
* Parameter _print: The print method.
*/
_class(class_group& _group, const std::string& _name, std::initializer_list<static_method> _smethods,
std::initializer_list<class_method<T>> _cmethods)
std::initializer_list<class_method<T>> _cmethods = {}, std::string (T::*_print)() = NULL)
: class_base(_group, _name), smethods(_smethods), cmethods(_cmethods)
{
name = _name;
class_ops m;
printmeth = _print;
m.is = _class<T>::is;
m.name = _class<T>::get_name;
m.print = _class<T>::print;
@ -394,7 +396,15 @@ public:
static std::string print(state& _state, int index)
{
T* obj = get(_state, index, "__internal_print");
return obj->print();
try {
auto pmeth = objclass<T>().printmeth;
if(pmeth)
return (obj->*pmeth)();
else
return "";
} catch(...) {
return "";
}
}
/**
* Get a pin of object against Lua GC.
@ -483,6 +493,7 @@ again:
std::string name;
std::list<static_method> smethods;
std::list<class_method<T>> cmethods;
std::string (T::*printmeth)();
_class(const _class<T>&);
_class& operator=(const _class<T>&);
};

View file

@ -72,7 +72,6 @@ struct lua_dbitmap
struct lua_loaded_bitmap
{
std::string print();
size_t w;
size_t h;
bool d;

View file

@ -11,10 +11,6 @@ namespace
static int create(lua::state& L, lua::parameters& P);
int index(lua::state& L, lua::parameters& P);
int newindex(lua::state& L, lua::parameters& P);
std::string print()
{
return "";
}
};
class lua_callback_obj
@ -26,7 +22,11 @@ namespace
int _call(lua::state& L, lua::parameters& P);
std::string print()
{
if(callback)
if(special == 1)
return "global register";
else if(special == 2)
return "global unregister";
else if(callback)
return callback->get_name();
else
return "(null)";
@ -46,7 +46,7 @@ namespace
{"register", &lua_callback_obj::_register},
{"unregister", &lua_callback_obj::_unregister},
{"__call", &lua_callback_obj::_call},
});
}, &lua_callback_obj::print);
lua_callbacks_list::lua_callbacks_list(lua::state& L)
{

View file

@ -707,7 +707,6 @@ namespace
{"load_str", lua_loaded_bitmap::load_str<false>},
{"load_png", lua_loaded_bitmap::load<true>},
{"load_png_str", lua_loaded_bitmap::load_str<true>},
}, {
});
lua::_class<lua_palette> class_palette(lua_class_gui, "PALETTE", {
@ -719,7 +718,8 @@ namespace
{"hash", &lua_palette::hash},
{"debug", &lua_palette::debug},
{"adjust_transparency", &lua_palette::adjust_transparency},
});
}, &lua_palette::print);
lua::_class<lua_bitmap> class_bitmap(lua_class_gui, "BITMAP", {
{"new", lua_bitmap::create},
}, {
@ -735,7 +735,8 @@ namespace
{"blit_porterduff", &lua_bitmap::blit<false, true>},
{"blit_scaled_porterduff", &lua_bitmap::blit<true, true>},
{"save_png", &lua_bitmap::save_png},
});
}, &lua_bitmap::print);
lua::_class<lua_dbitmap> class_dbitmap(lua_class_gui, "DBITMAP", {
{"new", lua_dbitmap::create},
}, {
@ -750,7 +751,7 @@ namespace
{"blit_scaled_porterduff", &lua_dbitmap::blit<true, true>},
{"save_png", &lua_dbitmap::save_png},
{"adjust_transparency", &lua_dbitmap::adjust_transparency},
});
}, &lua_dbitmap::print);
}
/** Palette **/
@ -1248,8 +1249,3 @@ template<bool png> int lua_loaded_bitmap::load_str(lua::state& L, lua::parameter
return lua_loaded_bitmap::load(strm);
});
}
std::string lua_loaded_bitmap::print()
{
return "";
}

View file

@ -143,7 +143,7 @@ namespace
{"clear", &lua_renderqueue::clear},
{"set", &lua_renderqueue::set},
{"render", &lua_renderqueue::render},
});
}, &lua_renderqueue::print);
}
void lua_renderq_run(lua_render_context* ctx, void* _sctx)

View file

@ -40,7 +40,7 @@ namespace
}, {
{"__call", &lua_customfont::draw},
{"edit", &lua_customfont::edit},
});
}, &lua_customfont::print);
struct render_object_text_cf : public framebuffer::object
{

View file

@ -148,10 +148,10 @@ namespace
lua::_class<lua_inverse_bind> class_inverse_bind(lua_class_bind, "INVERSEBIND", {
{"new", lua_inverse_bind::create},
}, {});
}, {}, &lua_inverse_bind::print);
lua::_class<lua_command_bind> class_command_bind(lua_class_bind, "COMMANDBIND", {
{"new", lua_command_bind::create},
}, {});
}, {}, &lua_command_bind::print);
}
int lua_inverse_bind::create(lua::state& L, lua::parameters& P)

View file

@ -75,7 +75,7 @@ namespace
{"new", lua_iconv::create},
}, {
{"__call", &lua_iconv::call},
});
}, &lua_iconv::print);
lua_iconv::lua_iconv(lua::state& L, const char* from, const char* to)

View file

@ -612,7 +612,8 @@ namespace
{"debugdump", &lua_inputmovie::debugdump},
{"copy_frames", &lua_inputmovie::copy_frames},
{"serialize", &lua_inputmovie::serialize},
});
}, &lua_inputmovie::print);
lua::_class<lua_inputframe> class_inputframe(lua_class_movie, "INPUTFRAME", {}, {
{"get_button", &lua_inputframe::get_button},
{"get_axis", &lua_inputframe::get_axis},
@ -621,7 +622,7 @@ namespace
{"serialize", &lua_inputframe::serialize},
{"unserialize", &lua_inputframe::unserialize},
{"get_stride", &lua_inputframe::get_stride},
});
}, &lua_inputframe::print);
lua_inputframe::lua_inputframe(lua::state& L, controller_frame _f)
{

View file

@ -224,10 +224,6 @@ 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

@ -436,7 +436,8 @@ namespace
messages << "Lua VM reset" << std::endl;
});
lua::_class<lua_unsaferewind> class_unsaferewind(lua_class_movie, "UNSAFEREWIND", {}, {});
lua::_class<lua_unsaferewind> class_unsaferewind(lua_class_movie, "UNSAFEREWIND", {}, {
}, &lua_unsaferewind::print);
}
void lua_callback_quit() throw()

View file

@ -634,7 +634,7 @@ namespace
{"__index", &lua_mmap_struct::index},
{"__newindex", &lua_mmap_struct::newindex},
{"__call", &lua_mmap_struct::map},
});
}, &lua_mmap_struct::print);
}
int lua_mmap_struct::map(lua::state& L, lua::parameters& P)

View file

@ -107,7 +107,8 @@ namespace
{"iqword", &lua_vma::rw<uint64_t, true>},
{"ifloat", &lua_vma::rw<float, true>},
{"idouble", &lua_vma::rw<double, true>},
});
}, &lua_vma::print);
lua::_class<lua_vma_list> class_vmalist(lua_class_memory, "VMALIST", {
{"new", lua_vma_list::create},
}, {

View file

@ -95,7 +95,7 @@ namespace
{"close_file", &lua_zip_writer::close_file},
{"create_file", &lua_zip_writer::create_file},
{"write", &lua_zip_writer::write}
});
}, &lua_zip_writer::print);
lua_zip_writer::lua_zip_writer(lua::state& L, const std::string& filename, unsigned compression)
{