Add base support for Lua object overcommit

This commit is contained in:
Ilari Liusvaara 2014-03-31 11:31:25 +03:00
parent 2498bad58d
commit e0827ce54f
15 changed files with 25 additions and 1 deletions

View file

@ -211,7 +211,8 @@ template<class T> class _class : public class_base
{
template<typename... U> T* _create(state& _state, U... args)
{
void* obj = _state.newuserdata(sizeof(T));
size_t overcommit = T::overcommit(args...);
void* obj = _state.newuserdata(sizeof(T) + overcommit);
load_metatable(_state);
_state.setmetatable(-2);
T* _obj = reinterpret_cast<T*>(obj);

View file

@ -16,6 +16,7 @@ struct lua_palette
{
std::vector<framebuffer::color> colors;
lua_palette(lua::state& L);
static size_t overcommit() { return 0; }
~lua_palette();
threads::lock palette_mutex;
std::string print();
@ -31,6 +32,7 @@ struct lua_palette
struct lua_bitmap
{
lua_bitmap(lua::state& L, uint32_t w, uint32_t h);
static size_t overcommit(uint32_t w, uint32_t h) { return 0; }
~lua_bitmap();
size_t width;
size_t height;
@ -52,6 +54,7 @@ struct lua_bitmap
struct lua_dbitmap
{
lua_dbitmap(lua::state& L, uint32_t w, uint32_t h);
static size_t overcommit(uint32_t w, uint32_t h) { return 0; }
~lua_dbitmap();
size_t width;
size_t height;

View file

@ -7,6 +7,7 @@
struct lua_unsaferewind
{
lua_unsaferewind(lua::state& L);
static size_t overcommit() { return 0; }
std::vector<char> state;
uint64_t frame;
uint64_t lag;

View file

@ -8,6 +8,7 @@ namespace
{
public:
lua_callbacks_list(lua::state& L);
static size_t overcommit() { return 0; }
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);
@ -17,6 +18,7 @@ namespace
{
public:
lua_callback_obj(lua::state& L, const std::string& name);
static size_t overcommit(const std::string& name) { return 0; }
int _register(lua::state& L, lua::parameters& P);
int _unregister(lua::state& L, lua::parameters& P);
int _call(lua::state& L, lua::parameters& P);

View file

@ -12,6 +12,7 @@ namespace
struct lua_renderqueue
{
lua_renderqueue(lua::state& L, uint32_t width, uint32_t height) throw();
static size_t overcommit(uint32_t width, uint32_t height) { return 0; }
~lua_renderqueue() throw() {}
lua_render_context* get() { return &lctx; }
std::string print()

View file

@ -19,6 +19,9 @@ namespace
lua_customfont(lua::state& L, const std::string& filename, const std::string& filename2);
lua_customfont(lua::state& L);
lua_customfont(lua::state& L, empty_font_tag tag);
static size_t overcommit() { return 0; }
static size_t overcommit(const std::string& filename, const std::string& filename2) { return 0; }
static size_t overcommit(empty_font_tag tag) { return 0; }
~lua_customfont() throw();
static int create(lua::state& L, lua::parameters& P);
static int load(lua::state& L, lua::parameters& P);

View file

@ -31,6 +31,7 @@ namespace
struct tilemap
{
tilemap(lua::state& L, size_t _width, size_t _height, size_t _cwidth, size_t _cheight);
static size_t overcommit(size_t _width, size_t _height, size_t _cwidth, size_t _cheight) { return 0; }
~tilemap()
{
threads::alock h(lock);

View file

@ -7,6 +7,7 @@ class lua_inverse_bind
{
public:
lua_inverse_bind(lua::state& L, const std::string& name, const std::string& cmd);
static size_t overcommit(const std::string& name, const std::string& cmd) { return 0; }
std::string print()
{
return ikey.getname();
@ -53,6 +54,7 @@ class lua_command_bind
{
public:
lua_command_bind(lua::state& L, const std::string& cmd, int idx1, int idx2);
static size_t overcommit(const std::string& cmd, int idx1, int idx2) { return 0; }
~lua_command_bind();
std::string print()
{

View file

@ -58,6 +58,7 @@ namespace
{
public:
lua_iconv(lua::state& L, const char* from, const char* to);
static size_t overcommit(const char* from, const char* to) { return 0; }
~lua_iconv() throw();
int call(lua::state& L, lua::parameters& P);
static int create(lua::state& L, lua::parameters& P);

View file

@ -17,6 +17,7 @@ namespace
friend class lua_inputmovie;
public:
lua_inputframe(lua::state& L, controller_frame _f);
static size_t overcommit(controller_frame _f) { return 0; }
int get_button(lua::state& L, lua::parameters& P)
{
unsigned port, controller, button;
@ -391,6 +392,8 @@ namespace
public:
lua_inputmovie(lua::state& L, const controller_frame_vector& _v);
lua_inputmovie(lua::state& L, controller_frame& _f);
static size_t overcommit(const controller_frame_vector& _v) { return 0; }
static size_t overcommit(controller_frame& _f) { return 0; }
int copy_movie(lua::state& L, lua::parameters& P)
{
return _copy_movie(L, P);

View file

@ -150,6 +150,7 @@ namespace
{
public:
lua_file_reader(lua::state& L, std::istream* strm);
static size_t overcommit(std::istream* strm) { return 0; }
~lua_file_reader()
{
delete &s;

View file

@ -25,6 +25,7 @@ namespace
{
public:
compare_obj(lua::state& L, uint64_t addr, uint64_t size, uint64_t rows, uint64_t stride);
static size_t overcommit(uint64_t addr, uint64_t size, uint64_t rows, uint64_t stride) { return 0; }
static int create(lua::state& L, lua::parameters& P);
int call(lua::state& L, lua::parameters& P);
private:

View file

@ -65,6 +65,7 @@ class lua_mmap_struct
{
public:
lua_mmap_struct(lua::state& L);
static size_t overcommit() { return 0; }
~lua_mmap_struct()
{

View file

@ -52,6 +52,7 @@ namespace
{
public:
lua_vma(lua::state& L, memory_region* r);
static size_t overcommit(memory_region* r) { return 0; }
int info(lua::state& L, lua::parameters& P);
template<class T, bool _bswap> int rw(lua::state& L, lua::parameters& P);
template<bool write, bool sign> int scattergather(lua::state& L, lua::parameters& P);
@ -76,6 +77,7 @@ namespace
{
public:
lua_vma_list(lua::state& L);
static size_t overcommit() { return 0; }
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);

View file

@ -8,6 +8,7 @@ namespace
{
public:
lua_zip_writer(lua::state& L, const std::string& filename, unsigned compression);
static size_t overcommit(const std::string& filename, unsigned compression) { return 0; }
~lua_zip_writer()
{
if(w) delete w;