Lua: Make class methods take lua::parameters

This commit is contained in:
Ilari Liusvaara 2014-01-28 14:38:25 +02:00
parent 59113ed24d
commit 53d7bbd633
13 changed files with 127 additions and 171 deletions

View file

@ -73,7 +73,7 @@ template<class T> struct class_binding
/**
* The pointer to call.
*/
int (T::*fn)(state& lstate, const std::string& _fname);
int (T::*fn)(state& lstate, lua::parameters& P);
/**
* The state to call it in.
*/
@ -128,7 +128,7 @@ template<class T> struct class_method
/**
* Function.
*/
int (T::*fn)(state& LS, const std::string& fname);
int (T::*fn)(state& LS, lua::parameters& P);
};
/**
@ -221,7 +221,8 @@ template<class T> class _class : public class_base
class_binding<T>* b = (class_binding<T>*)lua_touserdata(LS, lua_upvalueindex(1));
state L(*b->_state, LS);
T* p = _class<T>::get(L, 1, b->fname);
return (p->*(b->fn))(L, b->fname);
lua::parameters P(L, b->fname);
return (p->*(b->fn))(L, P);
} catch(std::exception& e) {
std::string err = e.what();
lua_pushlstring(LS, err.c_str(), err.length());
@ -272,7 +273,7 @@ badtype:
return t;
}
void bind(state& _state, const char* keyname, int (T::*fn)(state& LS, const std::string& fname))
void bind(state& _state, const char* keyname, int (T::*fn)(state& LS, lua::parameters& P))
{
load_metatable(_state);
_state.pushstring(keyname);

View file

@ -22,10 +22,10 @@ struct lua_palette
static int create(lua::state& L, lua::parameters& P);
static int load(lua::state& L, lua::parameters& P);
static int load_str(lua::state& L, lua::parameters& P);
int set(lua::state& L, const std::string& fname);
int hash(lua::state& L, const std::string& fname);
int debug(lua::state& L, const std::string& fname);
int adjust_transparency(lua::state& L, const std::string& fname);
int set(lua::state& L, lua::parameters& P);
int hash(lua::state& L, lua::parameters& P);
int debug(lua::state& L, lua::parameters& P);
int adjust_transparency(lua::state& L, lua::parameters& P);
};
struct lua_bitmap
@ -38,15 +38,15 @@ struct lua_bitmap
std::vector<char> save_png(const lua_palette& pal) const;
std::string print();
static int create(lua::state& L, lua::parameters& P);
int draw(lua::state& L, const std::string& fname);
int pset(lua::state& L, const std::string& fname);
int pget(lua::state& L, const std::string& fname);
int size(lua::state& L, const std::string& fname);
int hash(lua::state& L, const std::string& fname);
template<bool scaled, bool porterduff> int blit(lua::state& L, const std::string& fname);
template<bool scaled> int blit_priority(lua::state& L, const std::string& fname);
int save_png(lua::state& L, const std::string& fname);
int _save_png(lua::state& L, const std::string& fname, bool is_method);
int draw(lua::state& L, lua::parameters& P);
int pset(lua::state& L, lua::parameters& P);
int pget(lua::state& L, lua::parameters& P);
int size(lua::state& L, lua::parameters& P);
int hash(lua::state& L, lua::parameters& P);
template<bool scaled, bool porterduff> int blit(lua::state& L, lua::parameters& P);
template<bool scaled> int blit_priority(lua::state& L, lua::parameters& P);
int save_png(lua::state& L, lua::parameters& P);
int _save_png(lua::state& L, lua::parameters& P, bool is_method);
};
struct lua_dbitmap
@ -59,15 +59,15 @@ struct lua_dbitmap
std::vector<char> save_png() const;
std::string print();
static int create(lua::state& L, lua::parameters& P);
int draw(lua::state& L, const std::string& fname);
int pset(lua::state& L, const std::string& fname);
int pget(lua::state& L, const std::string& fname);
int size(lua::state& L, const std::string& fname);
int hash(lua::state& L, const std::string& fname);
template<bool scaled, bool porterduff> int blit(lua::state& L, const std::string& fname);
int save_png(lua::state& L, const std::string& fname);
int adjust_transparency(lua::state& L, const std::string& fname);
int _save_png(lua::state& L, const std::string& fname, bool is_method);
int draw(lua::state& L, lua::parameters& P);
int pset(lua::state& L, lua::parameters& P);
int pget(lua::state& L, lua::parameters& P);
int size(lua::state& L, lua::parameters& P);
int hash(lua::state& L, lua::parameters& P);
template<bool scaled, bool porterduff> int blit(lua::state& L, lua::parameters& P);
int save_png(lua::state& L, lua::parameters& P);
int adjust_transparency(lua::state& L, lua::parameters& P);
int _save_png(lua::state& L, lua::parameters& P, bool is_method);
};
struct lua_loaded_bitmap

View file

@ -9,8 +9,8 @@ namespace
public:
lua_callbacks_list(lua::state& L);
static int create(lua::state& L, lua::parameters& P);
int index(lua::state& L, const std::string& fname);
int newindex(lua::state& L, const std::string& fname);
int index(lua::state& L, lua::parameters& P);
int newindex(lua::state& L, lua::parameters& P);
std::string print()
{
return "";
@ -21,9 +21,9 @@ namespace
{
public:
lua_callback_obj(lua::state& L, const std::string& name);
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);
int _register(lua::state& L, lua::parameters& P);
int _unregister(lua::state& L, lua::parameters& P);
int _call(lua::state& L, lua::parameters& P);
std::string print()
{
if(callback)
@ -58,9 +58,8 @@ namespace
return 1;
}
int lua_callbacks_list::index(lua::state& L, const std::string& fname)
int lua_callbacks_list::index(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
std::string name;
P(P.skipped(), name);
@ -69,7 +68,7 @@ namespace
return 1;
}
int lua_callbacks_list::newindex(lua::state& L, const std::string& fname)
int lua_callbacks_list::newindex(lua::state& L, lua::parameters& P)
{
throw std::runtime_error("Writing is not allowed");
}
@ -93,9 +92,8 @@ namespace
throw std::runtime_error("Unknown callback type '" + name + "' for callback.<foo>");
}
int lua_callback_obj::_register(lua::state& L, const std::string& fname)
int lua_callback_obj::_register(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
int lfn;
if(!callback) throw std::runtime_error(P.get_fname() + ": not valid");
@ -109,10 +107,9 @@ namespace
return 1;
}
int lua_callback_obj::_unregister(lua::state& L, const std::string& fname)
int lua_callback_obj::_unregister(lua::state& L, lua::parameters& P)
{
int lfn;
lua::parameters P(L, fname);
if(!callback) throw std::runtime_error(P.get_fname() + ": not valid");
@ -125,9 +122,8 @@ namespace
return 1;
}
int lua_callback_obj::_call(lua::state& L, const std::string& fname)
int lua_callback_obj::_call(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
std::string name;
int lfn;

View file

@ -801,10 +801,13 @@ int lua_palette::load_str(lua::state& L, lua::parameters& P)
return bitmap_palette_fn(L, s);
}
int lua_palette::set(lua::state& L, const std::string& fname)
int lua_palette::set(lua::state& L, lua::parameters& P)
{
uint16_t c = L.get_numeric_argument<uint16_t>(2, fname.c_str());
auto nc = lua_get_fb_color(L, 3, fname);
framebuffer::color nc;
uint16_t c;
P(P.skipped(), c, nc);
//The mutex lock protects only the internals of colors array.
if(this->colors.size() <= c) {
this->palette_mutex.lock();
@ -815,7 +818,7 @@ int lua_palette::set(lua::state& L, const std::string& fname)
return 0;
}
int lua_palette::hash(lua::state& L, const std::string& fname)
int lua_palette::hash(lua::state& L, lua::parameters& P)
{
sha256 h;
const int buffersize = 256;
@ -838,7 +841,7 @@ int lua_palette::hash(lua::state& L, const std::string& fname)
return 1;
}
int lua_palette::debug(lua::state& L, const std::string& fname)
int lua_palette::debug(lua::state& L, lua::parameters& P)
{
size_t i = 0;
for(auto c : this->colors)
@ -846,9 +849,12 @@ int lua_palette::debug(lua::state& L, const std::string& fname)
return 0;
}
int lua_palette::adjust_transparency(lua::state& L, const std::string& fname)
int lua_palette::adjust_transparency(lua::state& L, lua::parameters& P)
{
uint16_t tadj = L.get_numeric_argument<uint16_t>(2, fname.c_str());
uint16_t tadj;
P(P.skipped(), tadj);
for(auto& c : this->colors)
c = tadjust(c, tadj);
return 0;
@ -886,9 +892,8 @@ int lua_bitmap::create(lua::state& L, lua::parameters& P)
return 1;
}
int lua_bitmap::draw(lua::state& L, const std::string& fname)
int lua_bitmap::draw(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
int32_t x, y;
lua::objpin<lua_bitmap> b;
lua::objpin<lua_palette> p;
@ -901,9 +906,8 @@ int lua_bitmap::draw(lua::state& L, const std::string& fname)
return 0;
}
int lua_bitmap::pset(lua::state& L, const std::string& fname)
int lua_bitmap::pset(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint32_t x, y;
uint16_t c;
@ -915,9 +919,8 @@ int lua_bitmap::pset(lua::state& L, const std::string& fname)
return 0;
}
int lua_bitmap::pget(lua::state& L, const std::string& fname)
int lua_bitmap::pget(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint32_t x, y;
P(P.skipped(), x, y);
@ -928,14 +931,14 @@ int lua_bitmap::pget(lua::state& L, const std::string& fname)
return 1;
}
int lua_bitmap::size(lua::state& L, const std::string& fname)
int lua_bitmap::size(lua::state& L, lua::parameters& P)
{
L.pushnumber(this->width);
L.pushnumber(this->height);
return 2;
}
int lua_bitmap::hash(lua::state& L, const std::string& fname)
int lua_bitmap::hash(lua::state& L, lua::parameters& P)
{
sha256 h;
const int buffersize = 256;
@ -958,9 +961,8 @@ int lua_bitmap::hash(lua::state& L, const std::string& fname)
return 1;
}
template<bool scaled, bool porterduff> int lua_bitmap::blit(lua::state& L, const std::string& fname)
template<bool scaled, bool porterduff> int lua_bitmap::blit(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint32_t dx, dy, sx, sy, w, h, hscl, vscl;
lua_bitmap* src_p;
@ -980,9 +982,8 @@ template<bool scaled, bool porterduff> int lua_bitmap::blit(lua::state& L, const
return 0;
}
template<bool scaled> int lua_bitmap::blit_priority(lua::state& L, const std::string& fname)
template<bool scaled> int lua_bitmap::blit_priority(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint32_t dx, dy, sx, sy, w, h, hscl, vscl;
lua_bitmap* src_p;
@ -994,9 +995,8 @@ template<bool scaled> int lua_bitmap::blit_priority(lua::state& L, const std::st
return 0;
}
int lua_bitmap::save_png(lua::state& L, const std::string& fname)
int lua_bitmap::save_png(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
std::string name, name2;
lua_palette* p;
bool was_filename;
@ -1055,9 +1055,8 @@ int lua_dbitmap::create(lua::state& L, lua::parameters& P)
return 1;
}
int lua_dbitmap::draw(lua::state& L, const std::string& fname)
int lua_dbitmap::draw(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
int32_t x, y;
lua::objpin<lua_dbitmap> b;
@ -1069,9 +1068,8 @@ int lua_dbitmap::draw(lua::state& L, const std::string& fname)
return 0;
}
int lua_dbitmap::pset(lua::state& L, const std::string& fname)
int lua_dbitmap::pset(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint32_t x, y;
framebuffer::color c;
@ -1083,9 +1081,8 @@ int lua_dbitmap::pset(lua::state& L, const std::string& fname)
return 0;
}
int lua_dbitmap::pget(lua::state& L, const std::string& fname)
int lua_dbitmap::pget(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint32_t x, y;
P(P.skipped(), x, y);
@ -1096,14 +1093,14 @@ int lua_dbitmap::pget(lua::state& L, const std::string& fname)
return 1;
}
int lua_dbitmap::size(lua::state& L, const std::string& fname)
int lua_dbitmap::size(lua::state& L, lua::parameters& P)
{
L.pushnumber(this->width);
L.pushnumber(this->height);
return 2;
}
int lua_dbitmap::hash(lua::state& L, const std::string& fname)
int lua_dbitmap::hash(lua::state& L, lua::parameters& P)
{
sha256 h;
const int buffersize = 256;
@ -1127,9 +1124,8 @@ int lua_dbitmap::hash(lua::state& L, const std::string& fname)
return 1;
}
template<bool scaled, bool porterduff> int lua_dbitmap::blit(lua::state& L, const std::string& fname)
template<bool scaled, bool porterduff> int lua_dbitmap::blit(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint32_t dx, dy, sx, sy, w, h, hscl, vscl;
P(P.skipped(), dx, dy);
@ -1180,9 +1176,8 @@ template<bool scaled, bool porterduff> int lua_dbitmap::blit(lua::state& L, cons
return 0;
}
int lua_dbitmap::save_png(lua::state& L, const std::string& fname)
int lua_dbitmap::save_png(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
std::string name, name2;
lua_palette* p;
bool was_filename;
@ -1209,9 +1204,8 @@ int lua_dbitmap::save_png(lua::state& L, const std::string& fname)
}
}
int lua_dbitmap::adjust_transparency(lua::state& L, const std::string& fname)
int lua_dbitmap::adjust_transparency(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint16_t tadj;
P(P.skipped(), tadj);

View file

@ -21,7 +21,7 @@ namespace
}
static int create(lua::state& L, lua::parameters& P);
static int setnull(lua::state& L, lua::parameters& P);
int run(lua::state& L, const std::string& fname)
int run(lua::state& L, lua::parameters& P)
{
if(!lua_render_ctx) return 0;
@ -37,9 +37,8 @@ namespace
lua_render_ctx->queue->copy_from(*ptr->queue);
return 0;
}
int synchronous_repaint(lua::state& L, const std::string& fname)
int synchronous_repaint(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
lua::objpin<lua_renderqueue> q;
P(q);
@ -49,7 +48,7 @@ namespace
synchronous_paint_ctx = NULL;
return 0;
}
int clear(lua::state& L, const std::string& fname)
int clear(lua::state& L, lua::parameters& P)
{
lua_render_context* ptr = get();
ptr->top_gap = std::numeric_limits<uint32_t>::max();
@ -58,9 +57,8 @@ namespace
ptr->left_gap = std::numeric_limits<uint32_t>::max();
ptr->queue->clear();
}
int set(lua::state& L, const std::string& fname)
int set(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
lua::objpin<lua_renderqueue> q;
P(q);
@ -71,7 +69,7 @@ namespace
lua_render_ctx = last = ptr;
redirect = true;
}
int render(lua::state& L, const std::string& fname)
int render(lua::state& L, lua::parameters& P)
{
uint32_t rwidth = lctx.width + rdgap(lctx.left_gap) + rdgap(lctx.right_gap);
uint32_t rheight = lctx.height + rdgap(lctx.top_gap) + rdgap(lctx.bottom_gap);

View file

@ -22,8 +22,8 @@ namespace
~lua_customfont() throw();
static int create(lua::state& L, lua::parameters& P);
static int load(lua::state& L, lua::parameters& P);
int draw(lua::state& L, const std::string& fname);
int edit(lua::state& L, const std::string& fname);
int draw(lua::state& L, lua::parameters& P);
int edit(lua::state& L, lua::parameters& P);
const framebuffer::font2& get_font() { return font; }
std::string print()
{
@ -118,9 +118,8 @@ namespace
render_kill_request(this);
}
int lua_customfont::draw(lua::state& L, const std::string& fname)
int lua_customfont::draw(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
int32_t _x, _y;
framebuffer::color fg, bg, hl;
std::string text;
@ -140,9 +139,8 @@ namespace
orig_filename = "<empty>";
}
int lua_customfont::edit(lua::state& L, const std::string& fname)
int lua_customfont::edit(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
std::string text;
lua_bitmap* _glyph;

View file

@ -37,10 +37,9 @@ namespace
render_kill_request(this);
}
static int create(lua::state& L, lua::parameters& P);
int draw(lua::state& L, const std::string& fname);
int get(lua::state& L, const std::string& fname)
int draw(lua::state& L, lua::parameters& P);
int get(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint32_t x, y;
P(P.skipped(), x, y);
@ -59,9 +58,8 @@ namespace
} else
return 0;
}
int set(lua::state& L, const std::string& fname)
int set(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint32_t x, y;
P(P.skipped(), x, y);
@ -87,13 +85,13 @@ namespace
P.expected("BITMAP, DBITMAP or nil", oidx);
return 0;
}
int getsize(lua::state& L, const std::string& fname)
int getsize(lua::state& L, lua::parameters& P)
{
L.pushnumber(width);
L.pushnumber(height);
return 2;
}
int getcsize(lua::state& L, const std::string& fname)
int getcsize(lua::state& L, lua::parameters& P)
{
L.pushnumber(cwidth);
L.pushnumber(cheight);
@ -118,9 +116,8 @@ namespace
} else
return orig + shift;
}
int scroll(lua::state& L, const std::string& fname)
int scroll(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
int32_t ox, oy;
size_t x0, y0, w, h;
bool circx, circy;
@ -282,9 +279,8 @@ namespace
lua::objpin<tilemap> map;
};
int tilemap::draw(lua::state& L, const std::string& fname)
int tilemap::draw(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint32_t x, y, w, h;
int32_t x0, y0;
lua::objpin<tilemap> t;

View file

@ -59,7 +59,7 @@ namespace
public:
lua_iconv(lua::state& L, const char* from, const char* to);
~lua_iconv() throw();
int call(lua::state& L, const std::string& fname);
int call(lua::state& L, lua::parameters& P);
static int create(lua::state& L, lua::parameters& P);
std::string print()
{
@ -94,9 +94,8 @@ namespace
iconv_close(ctx);
}
int lua_iconv::call(lua::state& L, const std::string& fname)
int lua_iconv::call(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
std::string src;
P(P.skipped(), src);

View file

@ -17,9 +17,8 @@ namespace
friend class lua_inputmovie;
public:
lua_inputframe(lua::state& L, controller_frame _f);
int get_button(lua::state& L, const std::string& fname)
int get_button(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
unsigned port, controller, button;
P(P.skipped(), port, controller, button);
@ -28,9 +27,8 @@ namespace
L.pushboolean(value ? 1 : 0);
return 1;
}
int get_axis(lua::state& L, const std::string& fname)
int get_axis(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
unsigned port, controller, button;
P(P.skipped(), port, controller, button);
@ -39,9 +37,8 @@ namespace
L.pushnumber(value);
return 1;
}
int set_axis(lua::state& L, const std::string& fname)
int set_axis(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
unsigned port, controller, button;
short value;
@ -54,16 +51,15 @@ namespace
setbutton(port, controller, button, value);
return 0;
}
int serialize(lua::state& L, const std::string& fname)
int serialize(lua::state& L, lua::parameters& P)
{
char buf[MAX_SERIALIZED_SIZE];
f.serialize(buf);
L.pushstring(buf);
return 1;
}
int unserialize(lua::state& L, const std::string& fname)
int unserialize(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
std::string buf;
P(P.skipped(), buf);
@ -71,7 +67,7 @@ namespace
f.deserialize(buf.c_str());
return 0;
}
int get_stride(lua::state& L, const std::string& fname)
int get_stride(lua::state& L, lua::parameters& P)
{
L.pushnumber(f.size());
return 1;
@ -411,72 +407,59 @@ namespace
public:
lua_inputmovie(lua::state& L, const controller_frame_vector& _v);
lua_inputmovie(lua::state& L, controller_frame& _f);
int copy_movie(lua::state& L, const std::string& fname)
int copy_movie(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _copy_movie(L, P);
}
int get_frame(lua::state& L, const std::string& fname)
int get_frame(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _get_frame(L, P);
}
int set_frame(lua::state& L, const std::string& fname)
int set_frame(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _set_frame(L, P);
}
int get_size(lua::state& L, const std::string& fname)
int get_size(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _get_size(L, P);
}
int count_frames(lua::state& L, const std::string& fname)
int count_frames(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _count_frames(L, P);
}
int find_frame(lua::state& L, const std::string& fname)
int find_frame(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _find_frame(L, P);
}
int blank_frame(lua::state& L, const std::string& fname)
int blank_frame(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _blank_frame(L, P);
}
int append_frames(lua::state& L, const std::string& fname)
int append_frames(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _append_frames(L, P);
}
int append_frame(lua::state& L, const std::string& fname)
int append_frame(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _append_frame(L, P);
}
int truncate(lua::state& L, const std::string& fname)
int truncate(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _truncate(L, P);
}
int edit(lua::state& L, const std::string& fname)
int edit(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _edit(L, P);
}
int copy_frames(lua::state& L, const std::string& fname)
int copy_frames(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _copy_frames<true>(L, P);
}
int serialize(lua::state& L, const std::string& fname)
int serialize(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
return _serialize(L, P);
}
int debugdump(lua::state& L, const std::string& fname)
int debugdump(lua::state& L, lua::parameters& P)
{
char buf[MAX_SERIALIZED_SIZE];
for(uint64_t i = 0; i < v.size(); i++) {

View file

@ -167,9 +167,8 @@ namespace
throw;
}
}
int read(lua::state& L, const std::string& fname)
int read(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
P(P.skipped());
if(P.is_number()) {
@ -199,7 +198,7 @@ namespace
} else
P.expected("number or nil");
}
int lines(lua::state& L, const std::string& fname)
int lines(lua::state& L, lua::parameters& P)
{
L.pushlightuserdata(this);
L.pushcclosure(lua_file_reader::lines_helper2, 1);

View file

@ -84,7 +84,7 @@ public:
{
}
int index(lua::state& L, const std::string& fname)
int index(lua::state& L, lua::parameters& P)
{
const char* c = L.tostring(2);
if(!c) {
@ -100,7 +100,7 @@ public:
x.first->read(L, x.second);
return 1;
}
int newindex(lua::state& L, const std::string& fname)
int newindex(lua::state& L, lua::parameters& P)
{
const char* c = L.tostring(2);
if(!c)
@ -117,7 +117,7 @@ public:
lua::_class<lua_mmap_struct>::create(L);
return 1;
}
int map(lua::state& L, const std::string& fname);
int map(lua::state& L, lua::parameters& P);
std::string print()
{
size_t s = mappings.size();
@ -637,9 +637,8 @@ namespace
});
}
int lua_mmap_struct::map(lua::state& L, const std::string& fname)
int lua_mmap_struct::map(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
std::string name, type;
uint64_t vmabase = 0, addr;

View file

@ -50,9 +50,9 @@ namespace
{
public:
lua_vma(lua::state& L, memory_region* r);
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);
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);
std::string print()
{
return vma;
@ -69,9 +69,9 @@ namespace
public:
lua_vma_list(lua::state& L);
static int create(lua::state& L, lua::parameters& P);
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);
int index(lua::state& L, lua::parameters& P);
int newindex(lua::state& L, lua::parameters& P);
int call(lua::state& L, lua::parameters& P);
std::string print()
{
return "";
@ -124,19 +124,16 @@ namespace
ro = r->readonly;
}
int lua_vma::info(lua::state& L, const std::string& fname)
int lua_vma::info(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
for(auto i : lsnes_memory.get_regions())
if(i->name == vma)
return handle_push_vma(L, *i);
(stringfmt() << P.get_fname() << ": Stale region").throwex();
}
template<class T, bool _bswap> int lua_vma::rw(lua::state& L, const std::string& fname)
template<class T, bool _bswap> int lua_vma::rw(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint64_t addr;
T val;
@ -162,9 +159,8 @@ namespace
P.expected("number or nil");
}
template<bool write, bool sign> int lua_vma::scattergather(lua::state& L, const std::string& fname)
template<bool write, bool sign> int lua_vma::scattergather(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
uint64_t val = 0;
unsigned shift = 0;
uint64_t addr = 0;
@ -205,7 +201,7 @@ namespace
return 1;
}
int lua_vma_list::call(lua::state& L, const std::string& fname)
int lua_vma_list::call(lua::state& L, lua::parameters& P)
{
L.newtable();
size_t key = 1;
@ -217,9 +213,8 @@ namespace
return 1;
}
int lua_vma_list::index(lua::state& L, const std::string& fname)
int lua_vma_list::index(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
std::string vma;
P(P.skipped(), vma);
@ -235,7 +230,7 @@ namespace
(stringfmt() << P.get_fname() << ": No such VMA").throwex();
}
int lua_vma_list::newindex(lua::state& L, const std::string& fname)
int lua_vma_list::newindex(lua::state& L, lua::parameters& P)
{
throw std::runtime_error("Writing is not allowed");
}

View file

@ -24,7 +24,7 @@ namespace
lua::_class<lua_zip_writer>::create(L, filename, compression);
return 1;
}
int commit(lua::state& L, const std::string& fname)
int commit(lua::state& L, lua::parameters& P)
{
if(!w) throw std::runtime_error("Zip writer already finished");
@ -35,14 +35,14 @@ namespace
delete w;
w = NULL;
}
int rollback(lua::state& L, const std::string& fname)
int rollback(lua::state& L, lua::parameters& P)
{
if(!w) throw std::runtime_error("Zip writer already finished");
delete w;
w = NULL;
}
int close_file(lua::state& L, const std::string& fname)
int close_file(lua::state& L, lua::parameters& P)
{
if(!w) throw std::runtime_error("Zip writer already finished");
if(!file_open) throw std::runtime_error("Zip writer doesn't have file open");
@ -50,9 +50,8 @@ namespace
w->close_file();
file_open = NULL;
}
int create_file(lua::state& L, const std::string& fname)
int create_file(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
std::string filename;
if(!w) throw std::runtime_error("Zip writer already finished");
@ -65,9 +64,8 @@ namespace
}
file_open = &w->create_file(filename);
}
int write(lua::state& L, const std::string& fname)
int write(lua::state& L, lua::parameters& P)
{
lua::parameters P(L, fname);
std::string _data;
if(!w) throw std::runtime_error("Zip writer already finished");