Lua: Automatically pass Lua state to lua class ctors
This commit is contained in:
parent
17f8603ec5
commit
9092dea931
13 changed files with 107 additions and 99 deletions
|
@ -645,7 +645,7 @@ template<class T> class lua_class
|
||||||
load_metatable(state);
|
load_metatable(state);
|
||||||
state.setmetatable(-2);
|
state.setmetatable(-2);
|
||||||
T* _obj = reinterpret_cast<T*>(obj);
|
T* _obj = reinterpret_cast<T*>(obj);
|
||||||
new(_obj) T(args...);
|
new(_obj) T(state, args...);
|
||||||
return _obj;
|
return _obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,13 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include "core/window.hpp"
|
#include "core/window.hpp"
|
||||||
|
#include "library/luabase.hpp"
|
||||||
#include "library/framebuffer.hpp"
|
#include "library/framebuffer.hpp"
|
||||||
#include "library/threadtypes.hpp"
|
#include "library/threadtypes.hpp"
|
||||||
|
|
||||||
struct lua_bitmap
|
struct lua_bitmap
|
||||||
{
|
{
|
||||||
lua_bitmap(uint32_t w, uint32_t h);
|
lua_bitmap(lua_state& L, uint32_t w, uint32_t h);
|
||||||
~lua_bitmap();
|
~lua_bitmap();
|
||||||
size_t width;
|
size_t width;
|
||||||
size_t height;
|
size_t height;
|
||||||
|
@ -19,7 +20,7 @@ struct lua_bitmap
|
||||||
|
|
||||||
struct lua_dbitmap
|
struct lua_dbitmap
|
||||||
{
|
{
|
||||||
lua_dbitmap(uint32_t w, uint32_t h);
|
lua_dbitmap(lua_state& L, uint32_t w, uint32_t h);
|
||||||
~lua_dbitmap();
|
~lua_dbitmap();
|
||||||
size_t width;
|
size_t width;
|
||||||
size_t height;
|
size_t height;
|
||||||
|
@ -29,7 +30,7 @@ struct lua_dbitmap
|
||||||
struct lua_palette
|
struct lua_palette
|
||||||
{
|
{
|
||||||
std::vector<premultiplied_color> colors;
|
std::vector<premultiplied_color> colors;
|
||||||
lua_palette();
|
lua_palette(lua_state& L);
|
||||||
~lua_palette();
|
~lua_palette();
|
||||||
mutex_class palette_mutex;
|
mutex_class palette_mutex;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
#ifndef _lua__unsaferewind__hpp__included__
|
#ifndef _lua__unsaferewind__hpp__included__
|
||||||
#define _lua__unsaferewind__hpp__included__
|
#define _lua__unsaferewind__hpp__included__
|
||||||
|
|
||||||
|
#include "library/luabase.hpp"
|
||||||
|
|
||||||
struct lua_unsaferewind
|
struct lua_unsaferewind
|
||||||
{
|
{
|
||||||
|
lua_unsaferewind(lua_state& L);
|
||||||
std::vector<char> state;
|
std::vector<char> state;
|
||||||
uint64_t frame;
|
uint64_t frame;
|
||||||
uint64_t lag;
|
uint64_t lag;
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace
|
||||||
class lua_callbacks_list
|
class lua_callbacks_list
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
lua_callbacks_list(lua_state* L);
|
lua_callbacks_list(lua_state& L);
|
||||||
int index(lua_state& L);
|
int index(lua_state& L);
|
||||||
int newindex(lua_state& L);
|
int newindex(lua_state& L);
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,7 @@ namespace
|
||||||
class lua_callback_obj
|
class lua_callback_obj
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
lua_callback_obj(lua_state* L, const std::string& name);
|
lua_callback_obj(lua_state& L, const std::string& name);
|
||||||
int _register(lua_state& L);
|
int _register(lua_state& L);
|
||||||
int _unregister(lua_state& L);
|
int _unregister(lua_state& L);
|
||||||
int _call(lua_state& L);
|
int _call(lua_state& L);
|
||||||
|
@ -30,19 +30,19 @@ DECLARE_LUACLASS(lua_callback_obj, "CALLBACK_OBJ");
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
lua_callbacks_list::lua_callbacks_list(lua_state* L)
|
lua_callbacks_list::lua_callbacks_list(lua_state& L)
|
||||||
{
|
{
|
||||||
static char doonce_key;
|
static char doonce_key;
|
||||||
if(L->do_once(&doonce_key)) {
|
if(L.do_once(&doonce_key)) {
|
||||||
objclass<lua_callbacks_list>().bind(*L, "__index", &lua_callbacks_list::index, true);
|
objclass<lua_callbacks_list>().bind(L, "__index", &lua_callbacks_list::index, true);
|
||||||
objclass<lua_callbacks_list>().bind(*L, "__newindex", &lua_callbacks_list::newindex, true);
|
objclass<lua_callbacks_list>().bind(L, "__newindex", &lua_callbacks_list::newindex, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int lua_callbacks_list::index(lua_state& L)
|
int lua_callbacks_list::index(lua_state& L)
|
||||||
{
|
{
|
||||||
std::string name = L.get_string(2, "CALLBACKS_LIST::__index");
|
std::string name = L.get_string(2, "CALLBACKS_LIST::__index");
|
||||||
lua_class<lua_callback_obj>::create(L, &L, name);
|
lua_class<lua_callback_obj>::create(L, name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,17 +51,17 @@ namespace
|
||||||
throw std::runtime_error("Writing is not allowed");
|
throw std::runtime_error("Writing is not allowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_callback_obj::lua_callback_obj(lua_state* L, const std::string& name)
|
lua_callback_obj::lua_callback_obj(lua_state& L, const std::string& name)
|
||||||
{
|
{
|
||||||
static char doonce_key;
|
static char doonce_key;
|
||||||
if(L->do_once(&doonce_key)) {
|
if(L.do_once(&doonce_key)) {
|
||||||
objclass<lua_callback_obj>().bind(*L, "register", &lua_callback_obj::_register);
|
objclass<lua_callback_obj>().bind(L, "register", &lua_callback_obj::_register);
|
||||||
objclass<lua_callback_obj>().bind(*L, "unregister", &lua_callback_obj::_unregister);
|
objclass<lua_callback_obj>().bind(L, "unregister", &lua_callback_obj::_unregister);
|
||||||
objclass<lua_callback_obj>().bind(*L, "__call", &lua_callback_obj::_call);
|
objclass<lua_callback_obj>().bind(L, "__call", &lua_callback_obj::_call);
|
||||||
}
|
}
|
||||||
callback = NULL;
|
callback = NULL;
|
||||||
special = 0;
|
special = 0;
|
||||||
for(auto i : L->get_callbacks())
|
for(auto i : L.get_callbacks())
|
||||||
if(i->get_name() == name)
|
if(i->get_name() == name)
|
||||||
callback = i;
|
callback = i;
|
||||||
if(name == "register") {
|
if(name == "register") {
|
||||||
|
@ -129,7 +129,7 @@ namespace
|
||||||
|
|
||||||
function_ptr_luafun callback(lua_func_callback, "callback", [](lua_state& L, const std::string& fname)
|
function_ptr_luafun callback(lua_func_callback, "callback", [](lua_state& L, const std::string& fname)
|
||||||
-> int {
|
-> int {
|
||||||
lua_class<lua_callbacks_list>::create(L, &L);
|
lua_class<lua_callbacks_list>::create(L);
|
||||||
return 1;
|
return 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
lua_bitmap::lua_bitmap(uint32_t w, uint32_t h)
|
lua_bitmap::lua_bitmap(lua_state& L, uint32_t w, uint32_t h)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
|
@ -22,7 +22,7 @@ lua_bitmap::~lua_bitmap()
|
||||||
render_kill_request(this);
|
render_kill_request(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_dbitmap::lua_dbitmap(uint32_t w, uint32_t h)
|
lua_dbitmap::lua_dbitmap(lua_state& L, uint32_t w, uint32_t h)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h;
|
height = h;
|
||||||
|
@ -34,7 +34,7 @@ lua_dbitmap::~lua_dbitmap()
|
||||||
render_kill_request(this);
|
render_kill_request(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_palette::lua_palette()
|
lua_palette::lua_palette(lua_state& L)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,15 +10,15 @@ namespace
|
||||||
|
|
||||||
struct render_queue_obj
|
struct render_queue_obj
|
||||||
{
|
{
|
||||||
render_queue_obj(uint32_t width, uint32_t height) throw()
|
render_queue_obj(lua_state& L, uint32_t width, uint32_t height) throw()
|
||||||
{
|
{
|
||||||
lctx.left_gap = std::numeric_limits<uint32_t>::max();
|
lctx.left_gap = std::numeric_limits<uint32_t>::max();
|
||||||
lctx.right_gap = std::numeric_limits<uint32_t>::max();
|
lctx.right_gap = std::numeric_limits<uint32_t>::max();
|
||||||
lctx.bottom_gap = std::numeric_limits<uint32_t>::max();
|
lctx.bottom_gap = std::numeric_limits<uint32_t>::max();
|
||||||
lctx.top_gap = std::numeric_limits<uint32_t>::max();
|
lctx.top_gap = std::numeric_limits<uint32_t>::max();
|
||||||
lctx.queue = &rqueue;
|
lctx.queue = &rqueue;
|
||||||
lctx.width = 512;
|
lctx.width = width;
|
||||||
lctx.height = 448;
|
lctx.height = height;
|
||||||
}
|
}
|
||||||
~render_queue_obj() throw() {}
|
~render_queue_obj() throw() {}
|
||||||
lua_render_context* get() { return &lctx; }
|
lua_render_context* get() { return &lctx; }
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace
|
||||||
struct lua_customfont
|
struct lua_customfont
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
lua_customfont(lua_state* L, const std::string& filename);
|
lua_customfont(lua_state& L, const std::string& filename);
|
||||||
~lua_customfont() throw();
|
~lua_customfont() throw();
|
||||||
int draw(lua_state& L);
|
int draw(lua_state& L);
|
||||||
const custom_font& get_font() { return font; }
|
const custom_font& get_font() { return font; }
|
||||||
|
@ -85,12 +85,12 @@ namespace
|
||||||
lua_obj_pin<lua_customfont> font;
|
lua_obj_pin<lua_customfont> font;
|
||||||
};
|
};
|
||||||
|
|
||||||
lua_customfont::lua_customfont(lua_state* L, const std::string& filename)
|
lua_customfont::lua_customfont(lua_state& L, const std::string& filename)
|
||||||
: font(filename)
|
: font(filename)
|
||||||
{
|
{
|
||||||
static char done_key;
|
static char done_key;
|
||||||
if(L->do_once(&done_key)) {
|
if(L.do_once(&done_key)) {
|
||||||
objclass<lua_customfont>().bind(*L, "__call", &lua_customfont::draw);
|
objclass<lua_customfont>().bind(L, "__call", &lua_customfont::draw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ namespace
|
||||||
-> int {
|
-> int {
|
||||||
std::string filename = L.get_string(1, fname.c_str());
|
std::string filename = L.get_string(1, fname.c_str());
|
||||||
try {
|
try {
|
||||||
lua_class<lua_customfont>::create(L, &L, filename);
|
lua_class<lua_customfont>::create(L, filename);
|
||||||
return 1;
|
return 1;
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
L.pushstring(e.what());
|
L.pushstring(e.what());
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
class lua_inverse_bind
|
class lua_inverse_bind
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
lua_inverse_bind(const std::string& name, const std::string& cmd);
|
lua_inverse_bind(lua_state& L, const std::string& name, const std::string& cmd);
|
||||||
private:
|
private:
|
||||||
inverse_bind ikey;
|
inverse_bind ikey;
|
||||||
};
|
};
|
||||||
|
@ -47,25 +47,25 @@ private:
|
||||||
class lua_command_bind
|
class lua_command_bind
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
lua_command_bind(lua_state* L, const std::string& cmd, int idx1, int idx2);
|
lua_command_bind(lua_state& L, const std::string& cmd, int idx1, int idx2);
|
||||||
~lua_command_bind();
|
~lua_command_bind();
|
||||||
private:
|
private:
|
||||||
lua_command_binding* a;
|
lua_command_binding* a;
|
||||||
lua_command_binding* b;
|
lua_command_binding* b;
|
||||||
};
|
};
|
||||||
|
|
||||||
lua_inverse_bind::lua_inverse_bind(const std::string& name, const std::string& cmd)
|
lua_inverse_bind::lua_inverse_bind(lua_state& L, const std::string& name, const std::string& cmd)
|
||||||
: ikey(lsnes_mapper, cmd, "Lua‣" + name)
|
: ikey(lsnes_mapper, cmd, "Lua‣" + name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_command_bind::lua_command_bind(lua_state* L, const std::string& cmd, int idx1, int idx2)
|
lua_command_bind::lua_command_bind(lua_state& L, const std::string& cmd, int idx1, int idx2)
|
||||||
{
|
{
|
||||||
if(L->type(idx2) == LUA_TFUNCTION) {
|
if(L.type(idx2) == LUA_TFUNCTION) {
|
||||||
a = new lua_command_binding(*L, "+" + cmd, idx1);
|
a = new lua_command_binding(L, "+" + cmd, idx1);
|
||||||
b = new lua_command_binding(*L, "-" + cmd, idx2);
|
b = new lua_command_binding(L, "-" + cmd, idx2);
|
||||||
} else {
|
} else {
|
||||||
a = new lua_command_binding(*L, cmd, idx1);
|
a = new lua_command_binding(L, cmd, idx1);
|
||||||
b = NULL;
|
b = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ namespace
|
||||||
if(L.type(3) != LUA_TFUNCTION && L.type(3) != LUA_TNIL && L.type(3) != LUA_TNONE)
|
if(L.type(3) != LUA_TFUNCTION && L.type(3) != LUA_TNIL && L.type(3) != LUA_TNONE)
|
||||||
throw std::runtime_error("Argument 2 of create_command must be function or nil");
|
throw std::runtime_error("Argument 2 of create_command must be function or nil");
|
||||||
std::string name = L.get_string(1, fname.c_str());
|
std::string name = L.get_string(1, fname.c_str());
|
||||||
lua_command_bind* b = lua_class<lua_command_bind>::create(L, &L, name, 2, 3);
|
lua_command_bind* b = lua_class<lua_command_bind>::create(L, name, 2, 3);
|
||||||
return 1;
|
return 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace
|
||||||
{
|
{
|
||||||
friend class lua_inputmovie;
|
friend class lua_inputmovie;
|
||||||
public:
|
public:
|
||||||
lua_inputframe(lua_state* L, controller_frame _f);
|
lua_inputframe(lua_state& L, controller_frame _f);
|
||||||
int get_button(lua_state& L)
|
int get_button(lua_state& L)
|
||||||
{
|
{
|
||||||
unsigned port = L.get_numeric_argument<unsigned>(2, "INPUTFRAME::get_button");
|
unsigned port = L.get_numeric_argument<unsigned>(2, "INPUTFRAME::get_button");
|
||||||
|
@ -141,7 +141,7 @@ namespace
|
||||||
int ptr = 1;
|
int ptr = 1;
|
||||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||||
|
|
||||||
lua_inputmovie* m = lua_class<lua_inputmovie>::create(L, &L, v);
|
lua_inputmovie* m = lua_class<lua_inputmovie>::create(L, v);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ namespace
|
||||||
if(n >= v.size())
|
if(n >= v.size())
|
||||||
throw std::runtime_error("Requested frame outside movie");
|
throw std::runtime_error("Requested frame outside movie");
|
||||||
controller_frame _f = v[n];
|
controller_frame _f = v[n];
|
||||||
lua_inputframe* f = lua_class<lua_inputframe>::create(L, &L, _f);
|
lua_inputframe* f = lua_class<lua_inputframe>::create(L, _f);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ namespace
|
||||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||||
|
|
||||||
controller_frame _f = v.blank_frame(true);
|
controller_frame _f = v.blank_frame(true);
|
||||||
lua_inputframe* f = lua_class<lua_inputframe>::create(L, &L, _f);
|
lua_inputframe* f = lua_class<lua_inputframe>::create(L, _f);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,8 +410,8 @@ namespace
|
||||||
class lua_inputmovie
|
class lua_inputmovie
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
lua_inputmovie(lua_state* L, const controller_frame_vector& _v);
|
lua_inputmovie(lua_state& L, const controller_frame_vector& _v);
|
||||||
lua_inputmovie(lua_state* L, controller_frame& _f);
|
lua_inputmovie(lua_state& L, controller_frame& _f);
|
||||||
int copy_movie(lua_state& L)
|
int copy_movie(lua_state& L)
|
||||||
{
|
{
|
||||||
return _copy_movie(L, "INPUTMOVIE::copy_movie");
|
return _copy_movie(L, "INPUTMOVIE::copy_movie");
|
||||||
|
@ -560,7 +560,7 @@ namespace
|
||||||
std::ifstream file(filename, binary ? std::ios_base::binary : std::ios_base::in);
|
std::ifstream file(filename, binary ? std::ios_base::binary : std::ios_base::in);
|
||||||
if(!file)
|
if(!file)
|
||||||
throw std::runtime_error("Can't open file to read input from");
|
throw std::runtime_error("Can't open file to read input from");
|
||||||
lua_inputmovie* m = lua_class<lua_inputmovie>::create(L, &L, f->get_frame());
|
lua_inputmovie* m = lua_class<lua_inputmovie>::create(L, f->get_frame());
|
||||||
controller_frame_vector& v = *m->get_frame_vector();
|
controller_frame_vector& v = *m->get_frame_vector();
|
||||||
if(binary) {
|
if(binary) {
|
||||||
uint64_t stride = v.get_stride();
|
uint64_t stride = v.get_stride();
|
||||||
|
@ -608,18 +608,18 @@ DECLARE_LUACLASS(lua_inputframe, "INPUTFRAME");
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
lua_inputframe::lua_inputframe(lua_state* L, controller_frame _f)
|
lua_inputframe::lua_inputframe(lua_state& L, controller_frame _f)
|
||||||
{
|
{
|
||||||
f = _f;
|
f = _f;
|
||||||
static char done_key;
|
static char done_key;
|
||||||
if(L->do_once(&done_key)) {
|
if(L.do_once(&done_key)) {
|
||||||
objclass<lua_inputframe>().bind(*L, "get_button", &lua_inputframe::get_button);
|
objclass<lua_inputframe>().bind(L, "get_button", &lua_inputframe::get_button);
|
||||||
objclass<lua_inputframe>().bind(*L, "get_axis", &lua_inputframe::get_axis);
|
objclass<lua_inputframe>().bind(L, "get_axis", &lua_inputframe::get_axis);
|
||||||
objclass<lua_inputframe>().bind(*L, "set_axis", &lua_inputframe::set_axis);
|
objclass<lua_inputframe>().bind(L, "set_axis", &lua_inputframe::set_axis);
|
||||||
objclass<lua_inputframe>().bind(*L, "set_button", &lua_inputframe::set_axis);
|
objclass<lua_inputframe>().bind(L, "set_button", &lua_inputframe::set_axis);
|
||||||
objclass<lua_inputframe>().bind(*L, "serialize", &lua_inputframe::serialize);
|
objclass<lua_inputframe>().bind(L, "serialize", &lua_inputframe::serialize);
|
||||||
objclass<lua_inputframe>().bind(*L, "unserialize", &lua_inputframe::unserialize);
|
objclass<lua_inputframe>().bind(L, "unserialize", &lua_inputframe::unserialize);
|
||||||
objclass<lua_inputframe>().bind(*L, "get_stride", &lua_inputframe::get_stride);
|
objclass<lua_inputframe>().bind(L, "get_stride", &lua_inputframe::get_stride);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,15 +644,15 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_inputmovie::lua_inputmovie(lua_state* L, const controller_frame_vector& _v)
|
lua_inputmovie::lua_inputmovie(lua_state& L, const controller_frame_vector& _v)
|
||||||
{
|
{
|
||||||
v = _v;
|
v = _v;
|
||||||
common_init(*L);
|
common_init(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_inputmovie::lua_inputmovie(lua_state* L, controller_frame& f)
|
lua_inputmovie::lua_inputmovie(lua_state& L, controller_frame& f)
|
||||||
{
|
{
|
||||||
v.clear(f.porttypes());
|
v.clear(f.porttypes());
|
||||||
common_init(*L);
|
common_init(L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,7 +149,7 @@ namespace
|
||||||
class lua_file_reader
|
class lua_file_reader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
lua_file_reader(lua_state* L, std::istream* strm);
|
lua_file_reader(lua_state& L, std::istream* strm);
|
||||||
~lua_file_reader()
|
~lua_file_reader()
|
||||||
{
|
{
|
||||||
delete &s;
|
delete &s;
|
||||||
|
@ -303,7 +303,7 @@ namespace
|
||||||
file2 = L.get_string(2, fname.c_str());
|
file2 = L.get_string(2, fname.c_str());
|
||||||
std::istream& s = open_file_relative(file1, file2);
|
std::istream& s = open_file_relative(file1, file2);
|
||||||
try {
|
try {
|
||||||
lua_class<lua_file_reader>::create(L, &L, &s);
|
lua_class<lua_file_reader>::create(L, &s);
|
||||||
return 1;
|
return 1;
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
delete &s;
|
delete &s;
|
||||||
|
@ -317,13 +317,13 @@ DECLARE_LUACLASS(lua_file_reader, "FILEREADER");
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
lua_file_reader::lua_file_reader(lua_state* L, std::istream* strm)
|
lua_file_reader::lua_file_reader(lua_state& L, std::istream* strm)
|
||||||
: s(*strm)
|
: s(*strm)
|
||||||
{
|
{
|
||||||
static char doonce_key;
|
static char doonce_key;
|
||||||
if(L->do_once(&doonce_key)) {
|
if(L.do_once(&doonce_key)) {
|
||||||
objclass<lua_file_reader>().bind(*L, "__call", &lua_file_reader::read);
|
objclass<lua_file_reader>().bind(L, "__call", &lua_file_reader::read);
|
||||||
objclass<lua_file_reader>().bind(*L, "lines", &lua_file_reader::lines);
|
objclass<lua_file_reader>().bind(L, "lines", &lua_file_reader::lines);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -507,3 +507,7 @@ bool lua_requests_repaint = false;
|
||||||
bool lua_requests_subframe_paint = false;
|
bool lua_requests_subframe_paint = false;
|
||||||
|
|
||||||
DECLARE_LUACLASS(lua_unsaferewind, "UNSAFEREWIND");
|
DECLARE_LUACLASS(lua_unsaferewind, "UNSAFEREWIND");
|
||||||
|
|
||||||
|
lua_unsaferewind::lua_unsaferewind(lua_state& L)
|
||||||
|
{
|
||||||
|
}
|
|
@ -88,7 +88,7 @@ namespace
|
||||||
class lua_mmap_struct
|
class lua_mmap_struct
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
lua_mmap_struct(lua_state* L);
|
lua_mmap_struct(lua_state& L);
|
||||||
|
|
||||||
~lua_mmap_struct()
|
~lua_mmap_struct()
|
||||||
{
|
{
|
||||||
|
@ -381,7 +381,7 @@ namespace
|
||||||
|
|
||||||
function_ptr_luafun gui_cbitmap(lua_func_misc, "memory.map_structure", [](lua_state& L,
|
function_ptr_luafun gui_cbitmap(lua_func_misc, "memory.map_structure", [](lua_state& L,
|
||||||
const std::string& fname) -> int {
|
const std::string& fname) -> int {
|
||||||
lua_class<lua_mmap_struct>::create(L, &L);
|
lua_class<lua_mmap_struct>::create(L);
|
||||||
return 1;
|
return 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -472,12 +472,12 @@ int lua_mmap_struct::map(lua_state& L)
|
||||||
|
|
||||||
DECLARE_LUACLASS(lua_mmap_struct, "MMAP_STRUCT");
|
DECLARE_LUACLASS(lua_mmap_struct, "MMAP_STRUCT");
|
||||||
|
|
||||||
lua_mmap_struct::lua_mmap_struct(lua_state* L)
|
lua_mmap_struct::lua_mmap_struct(lua_state& L)
|
||||||
{
|
{
|
||||||
static char done_key;
|
static char done_key;
|
||||||
if(L->do_once(&done_key)) {
|
if(L.do_once(&done_key)) {
|
||||||
objclass<lua_mmap_struct>().bind(*L, "__index", &lua_mmap_struct::index, true);
|
objclass<lua_mmap_struct>().bind(L, "__index", &lua_mmap_struct::index, true);
|
||||||
objclass<lua_mmap_struct>().bind(*L, "__newindex", &lua_mmap_struct::newindex, true);
|
objclass<lua_mmap_struct>().bind(L, "__newindex", &lua_mmap_struct::newindex, true);
|
||||||
objclass<lua_mmap_struct>().bind(*L, "__call", &lua_mmap_struct::map);
|
objclass<lua_mmap_struct>().bind(L, "__call", &lua_mmap_struct::map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace
|
||||||
class lua_vma
|
class lua_vma
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
lua_vma(lua_state* L, memory_region* r);
|
lua_vma(lua_state& L, memory_region* r);
|
||||||
int info(lua_state& L);
|
int info(lua_state& L);
|
||||||
template<class T, bool _bswap> int rw(lua_state& L);
|
template<class T, bool _bswap> int rw(lua_state& L);
|
||||||
private:
|
private:
|
||||||
|
@ -63,7 +63,7 @@ namespace
|
||||||
class lua_vma_list
|
class lua_vma_list
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
lua_vma_list(lua_state* L);
|
lua_vma_list(lua_state& L);
|
||||||
int index(lua_state& L);
|
int index(lua_state& L);
|
||||||
int newindex(lua_state& L);
|
int newindex(lua_state& L);
|
||||||
int call(lua_state& L);
|
int call(lua_state& L);
|
||||||
|
@ -75,27 +75,27 @@ DECLARE_LUACLASS(lua_vma_list, "VMALIST");
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
lua_vma::lua_vma(lua_state* L, memory_region* r)
|
lua_vma::lua_vma(lua_state& L, memory_region* r)
|
||||||
{
|
{
|
||||||
static char doonce_key;
|
static char doonce_key;
|
||||||
if(L->do_once(&doonce_key)) {
|
if(L.do_once(&doonce_key)) {
|
||||||
objclass<lua_vma>().bind(*L, "info", &lua_vma::info);
|
objclass<lua_vma>().bind(L, "info", &lua_vma::info);
|
||||||
objclass<lua_vma>().bind(*L, "sbyte", &lua_vma::rw<int8_t, false>);
|
objclass<lua_vma>().bind(L, "sbyte", &lua_vma::rw<int8_t, false>);
|
||||||
objclass<lua_vma>().bind(*L, "byte", &lua_vma::rw<uint8_t, false>);
|
objclass<lua_vma>().bind(L, "byte", &lua_vma::rw<uint8_t, false>);
|
||||||
objclass<lua_vma>().bind(*L, "sword", &lua_vma::rw<int16_t, false>);
|
objclass<lua_vma>().bind(L, "sword", &lua_vma::rw<int16_t, false>);
|
||||||
objclass<lua_vma>().bind(*L, "word", &lua_vma::rw<uint16_t, false>);
|
objclass<lua_vma>().bind(L, "word", &lua_vma::rw<uint16_t, false>);
|
||||||
objclass<lua_vma>().bind(*L, "sdword", &lua_vma::rw<int32_t, false>);
|
objclass<lua_vma>().bind(L, "sdword", &lua_vma::rw<int32_t, false>);
|
||||||
objclass<lua_vma>().bind(*L, "dword", &lua_vma::rw<uint32_t, false>);
|
objclass<lua_vma>().bind(L, "dword", &lua_vma::rw<uint32_t, false>);
|
||||||
objclass<lua_vma>().bind(*L, "sqword", &lua_vma::rw<int64_t, false>);
|
objclass<lua_vma>().bind(L, "sqword", &lua_vma::rw<int64_t, false>);
|
||||||
objclass<lua_vma>().bind(*L, "qword", &lua_vma::rw<uint64_t, false>);
|
objclass<lua_vma>().bind(L, "qword", &lua_vma::rw<uint64_t, false>);
|
||||||
objclass<lua_vma>().bind(*L, "isbyte", &lua_vma::rw<int8_t, true>);
|
objclass<lua_vma>().bind(L, "isbyte", &lua_vma::rw<int8_t, true>);
|
||||||
objclass<lua_vma>().bind(*L, "ibyte", &lua_vma::rw<uint8_t, true>);
|
objclass<lua_vma>().bind(L, "ibyte", &lua_vma::rw<uint8_t, true>);
|
||||||
objclass<lua_vma>().bind(*L, "isword", &lua_vma::rw<int16_t, true>);
|
objclass<lua_vma>().bind(L, "isword", &lua_vma::rw<int16_t, true>);
|
||||||
objclass<lua_vma>().bind(*L, "iword", &lua_vma::rw<uint16_t, true>);
|
objclass<lua_vma>().bind(L, "iword", &lua_vma::rw<uint16_t, true>);
|
||||||
objclass<lua_vma>().bind(*L, "isdword", &lua_vma::rw<int32_t, true>);
|
objclass<lua_vma>().bind(L, "isdword", &lua_vma::rw<int32_t, true>);
|
||||||
objclass<lua_vma>().bind(*L, "idword", &lua_vma::rw<uint32_t, true>);
|
objclass<lua_vma>().bind(L, "idword", &lua_vma::rw<uint32_t, true>);
|
||||||
objclass<lua_vma>().bind(*L, "isqword", &lua_vma::rw<int64_t, true>);
|
objclass<lua_vma>().bind(L, "isqword", &lua_vma::rw<int64_t, true>);
|
||||||
objclass<lua_vma>().bind(*L, "iqword", &lua_vma::rw<uint64_t, true>);
|
objclass<lua_vma>().bind(L, "iqword", &lua_vma::rw<uint64_t, true>);
|
||||||
}
|
}
|
||||||
vmabase = r->base;
|
vmabase = r->base;
|
||||||
vmasize = r->size;
|
vmasize = r->size;
|
||||||
|
@ -134,13 +134,13 @@ namespace
|
||||||
throw std::runtime_error("VMA::rw<T>: Parameter #3 must be integer if present");
|
throw std::runtime_error("VMA::rw<T>: Parameter #3 must be integer if present");
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_vma_list::lua_vma_list(lua_state* L)
|
lua_vma_list::lua_vma_list(lua_state& L)
|
||||||
{
|
{
|
||||||
static char doonce_key;
|
static char doonce_key;
|
||||||
if(L->do_once(&doonce_key)) {
|
if(L.do_once(&doonce_key)) {
|
||||||
objclass<lua_vma_list>().bind(*L, "__index", &lua_vma_list::index, true);
|
objclass<lua_vma_list>().bind(L, "__index", &lua_vma_list::index, true);
|
||||||
objclass<lua_vma_list>().bind(*L, "__newindex", &lua_vma_list::newindex, true);
|
objclass<lua_vma_list>().bind(L, "__newindex", &lua_vma_list::newindex, true);
|
||||||
objclass<lua_vma_list>().bind(*L, "__call", &lua_vma_list::call);
|
objclass<lua_vma_list>().bind(L, "__call", &lua_vma_list::call);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ namespace
|
||||||
std::list<memory_region*>::iterator i;
|
std::list<memory_region*>::iterator i;
|
||||||
for(i = l.begin(), j = 0; i != l.end(); i++, j++)
|
for(i = l.begin(), j = 0; i != l.end(); i++, j++)
|
||||||
if((*i)->name == vma) {
|
if((*i)->name == vma) {
|
||||||
lua_class<lua_vma>::create(L, &L, *i);
|
lua_class<lua_vma>::create(L, *i);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
throw std::runtime_error("VMALIST::__index: No such VMA");
|
throw std::runtime_error("VMALIST::__index: No such VMA");
|
||||||
|
@ -177,7 +177,7 @@ namespace
|
||||||
|
|
||||||
function_ptr_luafun memory2(lua_func_misc, "memory2", [](lua_state& L, const std::string& fname) ->
|
function_ptr_luafun memory2(lua_func_misc, "memory2", [](lua_state& L, const std::string& fname) ->
|
||||||
int {
|
int {
|
||||||
lua_class<lua_vma_list>::create(L, &L);
|
lua_class<lua_vma_list>::create(L);
|
||||||
return 1;
|
return 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue