Get rid of DECLARE_LUACLASS
This commit is contained in:
parent
51aae81c78
commit
007ef21d7a
14 changed files with 36 additions and 49 deletions
|
@ -3,7 +3,10 @@
|
|||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <typeinfo>
|
||||
#include <typeindex>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <cassert>
|
||||
|
@ -29,6 +32,8 @@ std::string try_print_userdata(lua_state& state, int index);
|
|||
|
||||
struct lua_function;
|
||||
|
||||
std::unordered_map<std::type_index, void*>& lua_class_types();
|
||||
|
||||
/**
|
||||
* Group of functions.
|
||||
*/
|
||||
|
@ -680,7 +685,10 @@ template<class T> class lua_class;
|
|||
/**
|
||||
* Function to obtain class object for given Lua class.
|
||||
*/
|
||||
template<class T> lua_class<T>& objclass();
|
||||
template<class T> lua_class<T>& objclass()
|
||||
{
|
||||
return *reinterpret_cast<lua_class<T>*>(lua_class_types()[typeid(T)]);
|
||||
}
|
||||
|
||||
template<class T> struct lua_class_binding
|
||||
{
|
||||
|
@ -777,6 +785,7 @@ public:
|
|||
m.name = lua_class<T>::get_name;
|
||||
m.print = lua_class<T>::print;
|
||||
userdata_recogn_fns().push_back(m);
|
||||
lua_class_types()[typeid(T)] = this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -929,9 +938,6 @@ again:
|
|||
lua_class& operator=(const lua_class<T>&);
|
||||
};
|
||||
|
||||
#define DECLARE_LUACLASS(x, X) template<> lua_class< x >& objclass() { static lua_class< x > clazz( X ); \
|
||||
return clazz; }
|
||||
|
||||
/**
|
||||
* Function implemented in C++ exported to Lua.
|
||||
*/
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
std::unordered_map<std::type_index, void*>& lua_class_types()
|
||||
{
|
||||
static std::unordered_map<std::type_index, void*> x;
|
||||
return x;
|
||||
}
|
||||
namespace
|
||||
{
|
||||
int lua_trampoline_function(lua_State* L)
|
||||
|
|
|
@ -34,13 +34,10 @@ namespace
|
|||
lua_state::lua_callback_list* callback;
|
||||
int special;
|
||||
};
|
||||
}
|
||||
|
||||
DECLARE_LUACLASS(lua_callbacks_list, "CALLBACKS_LIST");
|
||||
DECLARE_LUACLASS(lua_callback_obj, "CALLBACK_OBJ");
|
||||
lua_class<lua_callbacks_list> class_callbacks_list("CALLBACKS_LIST");
|
||||
lua_class<lua_callback_obj> class_callback_obj("CALLBACK_OBJ");
|
||||
|
||||
namespace
|
||||
{
|
||||
lua_callbacks_list::lua_callbacks_list(lua_state& L)
|
||||
{
|
||||
objclass<lua_callbacks_list>().bind_multi(L, {
|
||||
|
|
|
@ -896,8 +896,8 @@ namespace
|
|||
}
|
||||
return 2;
|
||||
});
|
||||
}
|
||||
|
||||
DECLARE_LUACLASS(lua_palette, "PALETTE");
|
||||
DECLARE_LUACLASS(lua_bitmap, "BITMAP");
|
||||
DECLARE_LUACLASS(lua_dbitmap, "DBITMAP");
|
||||
lua_class<lua_palette> class_palette("PALETTE");
|
||||
lua_class<lua_bitmap> class_bitmap("BITMAP");
|
||||
lua_class<lua_dbitmap> class_dbitmap("DBITMAP");
|
||||
}
|
||||
|
|
|
@ -111,9 +111,9 @@ namespace
|
|||
throw std::runtime_error("Expected RENDERCTX or nil as argument 1 for gui.renderq_set.");
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
DECLARE_LUACLASS(render_queue_obj, "RENDERCTX");
|
||||
lua_class<render_queue_obj> class_render_queue_obj("RENDERCTX");
|
||||
}
|
||||
|
||||
void lua_renderq_run(lua_render_context* ctx, void* _sctx)
|
||||
{
|
||||
|
|
|
@ -26,12 +26,9 @@ namespace
|
|||
std::string orig_filename;
|
||||
framebuffer::font2 font;
|
||||
};
|
||||
}
|
||||
|
||||
DECLARE_LUACLASS(lua_customfont, "CUSTOMFONT");
|
||||
lua_class<lua_customfont> class_customfont("CUSTOMFONT");
|
||||
|
||||
namespace
|
||||
{
|
||||
struct render_object_text_cf : public framebuffer::object
|
||||
{
|
||||
render_object_text_cf(int32_t _x, int32_t _y, const std::string& _text, framebuffer::color _fg,
|
||||
|
|
|
@ -301,12 +301,9 @@ namespace
|
|||
tilemap* t = lua_class<tilemap>::create(LS, w, h, px, py);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
DECLARE_LUACLASS(tilemap, "TILEMAP");
|
||||
lua_class<tilemap> class_tilemap("TILEMAP");
|
||||
|
||||
namespace
|
||||
{
|
||||
tilemap::tilemap(lua_state& L, size_t _width, size_t _height, size_t _cwidth, size_t _cheight)
|
||||
: width(_width), height(_height), cwidth(_cwidth), cheight(_cheight)
|
||||
{
|
||||
|
|
|
@ -160,7 +160,6 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
lua_class<lua_inverse_bind> class_inverse_bind("INVERSEBIND");
|
||||
lua_class<lua_command_bind> class_command_bind("COMMANDBIND");
|
||||
}
|
||||
|
||||
DECLARE_LUACLASS(lua_inverse_bind, "INVERSEBIND");
|
||||
DECLARE_LUACLASS(lua_command_bind, "COMMANDBIND");
|
||||
|
|
|
@ -615,13 +615,10 @@ namespace
|
|||
else
|
||||
return movb.get_movie().get_frame_vector();
|
||||
}
|
||||
}
|
||||
|
||||
DECLARE_LUACLASS(lua_inputmovie, "INPUTMOVIE");
|
||||
DECLARE_LUACLASS(lua_inputframe, "INPUTFRAME");
|
||||
lua_class<lua_inputmovie> class_inputmovie("INPUTMOVIE");
|
||||
lua_class<lua_inputframe> class_inputframe("INPUTFRAME");
|
||||
|
||||
namespace
|
||||
{
|
||||
lua_inputframe::lua_inputframe(lua_state& L, controller_frame _f)
|
||||
{
|
||||
f = _f;
|
||||
|
|
|
@ -313,13 +313,9 @@ namespace
|
|||
throw;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
DECLARE_LUACLASS(lua_file_reader, "FILEREADER");
|
||||
lua_class<lua_file_reader> class_filreader("FILEREADER");
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
lua_file_reader::lua_file_reader(lua_state& L, std::istream* strm)
|
||||
: s(*strm)
|
||||
{
|
||||
|
|
|
@ -421,6 +421,7 @@ namespace
|
|||
messages << "Lua VM reset" << std::endl;
|
||||
});
|
||||
|
||||
lua_class<lua_unsaferewind> class_unsaferewind("UNSAFEREWIND");
|
||||
}
|
||||
|
||||
void lua_callback_quit() throw()
|
||||
|
@ -515,8 +516,6 @@ void lua_callback_do_latch(std::list<std::string>& args)
|
|||
bool lua_requests_repaint = false;
|
||||
bool lua_requests_subframe_paint = false;
|
||||
|
||||
DECLARE_LUACLASS(lua_unsaferewind, "UNSAFEREWIND");
|
||||
|
||||
lua_unsaferewind::lua_unsaferewind(lua_state& L)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -658,6 +658,8 @@ namespace
|
|||
lua_registerX<DEBUG_EXEC, false> murx("memory.unregisterexec");
|
||||
lua_registerX<DEBUG_TRACE, true> mrt("memory.registertrace");
|
||||
lua_registerX<DEBUG_TRACE, false> murt("memory.unregistertrace");
|
||||
|
||||
lua_class<lua_mmap_struct> class_mmap_struct("MMAP_STRUCT");
|
||||
}
|
||||
|
||||
int lua_mmap_struct::map(lua_state& L, const std::string& fname)
|
||||
|
@ -706,8 +708,6 @@ int lua_mmap_struct::map(lua_state& L, const std::string& fname)
|
|||
return 0;
|
||||
}
|
||||
|
||||
DECLARE_LUACLASS(lua_mmap_struct, "MMAP_STRUCT");
|
||||
|
||||
lua_mmap_struct::lua_mmap_struct(lua_state& L)
|
||||
{
|
||||
objclass<lua_mmap_struct>().bind_multi(L, {
|
||||
|
|
|
@ -76,13 +76,10 @@ namespace
|
|||
return "";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
DECLARE_LUACLASS(lua_vma, "VMA");
|
||||
DECLARE_LUACLASS(lua_vma_list, "VMALIST");
|
||||
lua_class<lua_vma> class_vma("VMA");
|
||||
lua_class<lua_vma_list> class_vmalist("VMALIST");
|
||||
|
||||
namespace
|
||||
{
|
||||
lua_vma::lua_vma(lua_state& L, memory_region* r)
|
||||
{
|
||||
objclass<lua_vma>().bind_multi(L, {
|
||||
|
|
|
@ -69,12 +69,9 @@ namespace
|
|||
std::ostream* file_open;
|
||||
std::string file;
|
||||
};
|
||||
}
|
||||
|
||||
DECLARE_LUACLASS(lua_zip_writer, "ZIPWRITER");
|
||||
lua_class<lua_zip_writer> class_zipwriter("ZIPWRITER");
|
||||
|
||||
namespace
|
||||
{
|
||||
lua_zip_writer::lua_zip_writer(lua_state& L, const std::string& filename, unsigned compression)
|
||||
{
|
||||
file = filename;
|
||||
|
|
Loading…
Add table
Reference in a new issue