Refactor library Lua base to dedicated namespace
This commit is contained in:
parent
9df05e03a9
commit
2c4a3a5f84
41 changed files with 825 additions and 818 deletions
|
@ -1,5 +1,5 @@
|
|||
#ifndef _library__luabase__hpp__included__
|
||||
#define _library__luabase__hpp__included__
|
||||
#ifndef _library__lua_base__hpp__included__
|
||||
#define _library__lua_base__hpp__included__
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
@ -17,41 +17,43 @@ extern "C"
|
|||
#include <lua.h>
|
||||
}
|
||||
|
||||
class lua_state;
|
||||
|
||||
struct luaclass_methods
|
||||
namespace lua
|
||||
{
|
||||
bool (*is)(lua_state& state, int index);
|
||||
class state;
|
||||
|
||||
struct class_ops
|
||||
{
|
||||
bool (*is)(state& _state, int index);
|
||||
const std::string& (*name)();
|
||||
std::string (*print)(lua_state& state, int index);
|
||||
std::string (*print)(state& _state, int index);
|
||||
};
|
||||
|
||||
std::list<luaclass_methods>& userdata_recogn_fns();
|
||||
std::string try_recognize_userdata(lua_state& state, int index);
|
||||
std::string try_print_userdata(lua_state& state, int index);
|
||||
std::list<class_ops>& userdata_recogn_fns();
|
||||
std::string try_recognize_userdata(state& _state, int index);
|
||||
std::string try_print_userdata(state& _state, int index);
|
||||
|
||||
struct lua_function;
|
||||
struct function;
|
||||
|
||||
std::unordered_map<std::type_index, void*>& lua_class_types();
|
||||
std::unordered_map<std::type_index, void*>& class_types();
|
||||
|
||||
/**
|
||||
* Group of functions.
|
||||
*/
|
||||
class lua_function_group
|
||||
class function_group
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create a group.
|
||||
*/
|
||||
lua_function_group();
|
||||
function_group();
|
||||
/**
|
||||
* Destroy a group.
|
||||
*/
|
||||
~lua_function_group();
|
||||
~function_group();
|
||||
/**
|
||||
* Add a function to group.
|
||||
*/
|
||||
void do_register(const std::string& name, lua_function& fun);
|
||||
void do_register(const std::string& name, function& fun);
|
||||
/**
|
||||
* Drop a function from group.
|
||||
*/
|
||||
|
@ -59,29 +61,29 @@ public:
|
|||
/**
|
||||
* Request callbacks on all currently registered functions.
|
||||
*/
|
||||
void request_callback(std::function<void(std::string, lua_function*)> cb);
|
||||
void request_callback(std::function<void(std::string, function*)> cb);
|
||||
/**
|
||||
* Bind a callback.
|
||||
*
|
||||
* Callbacks for all registered functions are immediately called.
|
||||
*/
|
||||
int add_callback(std::function<void(std::string, lua_function*)> cb,
|
||||
std::function<void(lua_function_group*)> dcb);
|
||||
int add_callback(std::function<void(std::string, function*)> cb,
|
||||
std::function<void(function_group*)> dcb);
|
||||
/**
|
||||
* Unbind a calback.
|
||||
*/
|
||||
void drop_callback(int handle);
|
||||
private:
|
||||
int next_handle;
|
||||
std::map<std::string, lua_function*> functions;
|
||||
std::map<int, std::function<void(std::string, lua_function*)>> callbacks;
|
||||
std::map<int, std::function<void(lua_function_group*)>> dcallbacks;
|
||||
std::map<std::string, function*> functions;
|
||||
std::map<int, std::function<void(std::string, function*)>> callbacks;
|
||||
std::map<int, std::function<void(function_group*)>> dcallbacks;
|
||||
};
|
||||
|
||||
/**
|
||||
* Lua state object.
|
||||
*/
|
||||
class lua_state
|
||||
class state
|
||||
{
|
||||
public:
|
||||
//Auxillary type for store-tag.
|
||||
|
@ -96,7 +98,7 @@ public:
|
|||
{
|
||||
std::list<std::string> args;
|
||||
vararg_tag(std::list<std::string>& _args) : args(_args) {}
|
||||
int pushargs(lua_state& L);
|
||||
int pushargs(state& L);
|
||||
};
|
||||
|
||||
//Auxillary type for numeric-tag.
|
||||
|
@ -109,9 +111,9 @@ public:
|
|||
//Auxillary type for fnptr-tag.
|
||||
template<typename T> struct _fnptr_tag
|
||||
{
|
||||
int(*fn)(lua_state& L, T v);
|
||||
int(*fn)(state& L, T v);
|
||||
T val;
|
||||
_fnptr_tag(int (*f)(lua_state& L, T v), T v) : fn(f), val(v) {}
|
||||
_fnptr_tag(int (*f)(state& L, T v), T v) : fn(f), val(v) {}
|
||||
};
|
||||
|
||||
//Auxillary type for fn-tag.
|
||||
|
@ -145,7 +147,7 @@ public:
|
|||
* Parameter v: The value to pass to function.
|
||||
* Returns: The parameter structure.
|
||||
*/
|
||||
template<typename T> static struct _fnptr_tag<T> fnptr_tag(int (*f)(lua_state& L, T v), T v)
|
||||
template<typename T> static struct _fnptr_tag<T> fnptr_tag(int (*f)(state& L, T v), T v)
|
||||
{
|
||||
return _fnptr_tag<T>(f, v);
|
||||
}
|
||||
|
@ -247,15 +249,15 @@ public:
|
|||
/**
|
||||
* Create a new state.
|
||||
*/
|
||||
lua_state() throw(std::bad_alloc);
|
||||
state() throw(std::bad_alloc);
|
||||
/**
|
||||
* Create a new state with specified master state.
|
||||
*/
|
||||
lua_state(lua_state& _master, lua_State* L);
|
||||
state(state& _master, lua_State* L);
|
||||
/**
|
||||
* Destroy a state.
|
||||
*/
|
||||
~lua_state() throw();
|
||||
~state() throw();
|
||||
/**
|
||||
* Get the internal state object.
|
||||
*
|
||||
|
@ -265,7 +267,7 @@ public:
|
|||
/**
|
||||
* Get the master state.
|
||||
*/
|
||||
lua_state& get_master() { return master ? master->get_master() : *this; }
|
||||
state& get_master() { return master ? master->get_master() : *this; }
|
||||
/**
|
||||
* Set the internal state object.
|
||||
*/
|
||||
|
@ -391,11 +393,11 @@ public:
|
|||
/**
|
||||
* Add a group of functions.
|
||||
*/
|
||||
void add_function_group(lua_function_group& group);
|
||||
void add_function_group(function_group& group);
|
||||
/**
|
||||
* Function callback.
|
||||
*/
|
||||
void function_callback(const std::string& name, lua_function* func);
|
||||
void function_callback(const std::string& name, function* func);
|
||||
/**
|
||||
* Do something just once per VM.
|
||||
*
|
||||
|
@ -406,13 +408,13 @@ public:
|
|||
/**
|
||||
* Callback list.
|
||||
*/
|
||||
class lua_callback_list
|
||||
class callback_list
|
||||
{
|
||||
public:
|
||||
lua_callback_list(lua_state& L, const std::string& name, const std::string& fn_cbname = "");
|
||||
~lua_callback_list();
|
||||
void _register(lua_state& L); //Reads callback from top of lua stack.
|
||||
void _unregister(lua_state& L); //Reads callback from top of lua stack.
|
||||
callback_list(state& L, const std::string& name, const std::string& fn_cbname = "");
|
||||
~callback_list();
|
||||
void _register(state& L); //Reads callback from top of lua stack.
|
||||
void _unregister(state& L); //Reads callback from top of lua stack.
|
||||
template<typename... T> bool callback(T... args) {
|
||||
bool any = L.callback(callbacks, args...);
|
||||
if(fn_cbname != "" && L.callback(fn_cbname, args...))
|
||||
|
@ -422,21 +424,21 @@ public:
|
|||
const std::string& get_name() { return name; }
|
||||
void clear() { callbacks.clear(); }
|
||||
private:
|
||||
lua_callback_list(const lua_callback_list&);
|
||||
lua_callback_list& operator=(const lua_callback_list&);
|
||||
callback_list(const callback_list&);
|
||||
callback_list& operator=(const callback_list&);
|
||||
std::list<char> callbacks;
|
||||
lua_state& L;
|
||||
state& L;
|
||||
std::string name;
|
||||
std::string fn_cbname;
|
||||
};
|
||||
/**
|
||||
* Enumerate all callbacks.
|
||||
*/
|
||||
std::list<lua_callback_list*> get_callbacks()
|
||||
std::list<callback_list*> get_callbacks()
|
||||
{
|
||||
if(master)
|
||||
return master->get_callbacks();
|
||||
std::list<lua_callback_list*> r;
|
||||
std::list<callback_list*> r;
|
||||
for(auto i : callbacks)
|
||||
r.push_back(i.second);
|
||||
return r;
|
||||
|
@ -447,8 +449,8 @@ public:
|
|||
class callback_proxy
|
||||
{
|
||||
public:
|
||||
callback_proxy(lua_state& _L) : parent(_L) {}
|
||||
void do_register(const std::string& name, lua_callback_list& callback)
|
||||
callback_proxy(state& _L) : parent(_L) {}
|
||||
void do_register(const std::string& name, callback_list& callback)
|
||||
{
|
||||
parent.do_register_cb(name, callback);
|
||||
}
|
||||
|
@ -460,10 +462,10 @@ public:
|
|||
parent.do_unregister_cb(name);
|
||||
}
|
||||
private:
|
||||
lua_state& parent;
|
||||
state& parent;
|
||||
};
|
||||
|
||||
void do_register_cb(const std::string& name, lua_callback_list& callback)
|
||||
void do_register_cb(const std::string& name, callback_list& callback)
|
||||
{
|
||||
callbacks[name] = &callback;
|
||||
}
|
||||
|
@ -531,25 +533,25 @@ private:
|
|||
static void builtin_oom();
|
||||
static void* builtin_alloc(void* user, void* old, size_t olds, size_t news);
|
||||
void (*oom_handler)();
|
||||
lua_state* master;
|
||||
state* master;
|
||||
lua_State* lua_handle;
|
||||
std::set<std::pair<lua_function_group*, int>> function_groups;
|
||||
std::map<std::string, lua_callback_list*> callbacks;
|
||||
lua_state(lua_state&);
|
||||
lua_state& operator=(lua_state&);
|
||||
std::set<std::pair<function_group*, int>> function_groups;
|
||||
std::map<std::string, callback_list*> callbacks;
|
||||
state(state&);
|
||||
state& operator=(state&);
|
||||
};
|
||||
|
||||
/**
|
||||
* Pin of an object against Lua GC.
|
||||
*/
|
||||
template<typename T> struct lua_obj_pin
|
||||
template<typename T> struct objpin
|
||||
{
|
||||
/**
|
||||
* Create a null pin.
|
||||
*/
|
||||
lua_obj_pin()
|
||||
objpin()
|
||||
{
|
||||
state = NULL;
|
||||
_state = NULL;
|
||||
obj = NULL;
|
||||
}
|
||||
/**
|
||||
|
@ -558,59 +560,59 @@ template<typename T> struct lua_obj_pin
|
|||
* Parameter _state: The state to pin the object in.
|
||||
* Parameter _object: The object to pin.
|
||||
*/
|
||||
lua_obj_pin(lua_state& _state, T* _object)
|
||||
: state(&_state.get_master())
|
||||
objpin(state& lstate, T* _object)
|
||||
: _state(&lstate.get_master())
|
||||
{
|
||||
_state.pushlightuserdata(this);
|
||||
_state.pushvalue(-2);
|
||||
_state.rawset(LUA_REGISTRYINDEX);
|
||||
_state->pushlightuserdata(this);
|
||||
_state->pushvalue(-2);
|
||||
_state->rawset(LUA_REGISTRYINDEX);
|
||||
obj = _object;
|
||||
}
|
||||
/**
|
||||
* Delete a pin.
|
||||
*/
|
||||
~lua_obj_pin() throw()
|
||||
~objpin() throw()
|
||||
{
|
||||
if(obj) {
|
||||
state->pushlightuserdata(this);
|
||||
state->pushnil();
|
||||
state->rawset(LUA_REGISTRYINDEX);
|
||||
_state->pushlightuserdata(this);
|
||||
_state->pushnil();
|
||||
_state->rawset(LUA_REGISTRYINDEX);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copy ctor.
|
||||
*/
|
||||
lua_obj_pin(const lua_obj_pin& p)
|
||||
objpin(const objpin& p)
|
||||
{
|
||||
state = p.state;
|
||||
_state = p._state;
|
||||
obj = p.obj;
|
||||
if(obj) {
|
||||
state->pushlightuserdata(this);
|
||||
state->pushlightuserdata(const_cast<lua_obj_pin*>(&p));
|
||||
state->rawget(LUA_REGISTRYINDEX);
|
||||
state->rawset(LUA_REGISTRYINDEX);
|
||||
_state->pushlightuserdata(this);
|
||||
_state->pushlightuserdata(const_cast<objpin*>(&p));
|
||||
_state->rawget(LUA_REGISTRYINDEX);
|
||||
_state->rawset(LUA_REGISTRYINDEX);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Assignment operator.
|
||||
*/
|
||||
lua_obj_pin& operator=(const lua_obj_pin& p)
|
||||
objpin& operator=(const objpin& p)
|
||||
{
|
||||
if(state == p.state && obj == p.obj)
|
||||
if(_state == p._state && obj == p.obj)
|
||||
return *this;
|
||||
if(obj == p.obj)
|
||||
throw std::logic_error("A Lua object can't be in two lua states at once");
|
||||
if(obj) {
|
||||
state->pushlightuserdata(this);
|
||||
state->pushnil();
|
||||
state->rawset(LUA_REGISTRYINDEX);
|
||||
_state->pushlightuserdata(this);
|
||||
_state->pushnil();
|
||||
_state->rawset(LUA_REGISTRYINDEX);
|
||||
}
|
||||
state = p.state;
|
||||
_state = p._state;
|
||||
if(p.obj) {
|
||||
state->pushlightuserdata(this);
|
||||
state->pushlightuserdata(const_cast<lua_obj_pin*>(&p));
|
||||
state->rawget(LUA_REGISTRYINDEX);
|
||||
state->rawset(LUA_REGISTRYINDEX);
|
||||
_state->pushlightuserdata(this);
|
||||
_state->pushlightuserdata(const_cast<objpin*>(&p));
|
||||
_state->rawget(LUA_REGISTRYINDEX);
|
||||
_state->rawset(LUA_REGISTRYINDEX);
|
||||
}
|
||||
obj = p.obj;
|
||||
return *this;
|
||||
|
@ -621,11 +623,11 @@ template<typename T> struct lua_obj_pin
|
|||
void clear()
|
||||
{
|
||||
if(obj) {
|
||||
state->pushlightuserdata(this);
|
||||
state->pushnil();
|
||||
state->rawset(LUA_REGISTRYINDEX);
|
||||
_state->pushlightuserdata(this);
|
||||
_state->pushnil();
|
||||
_state->rawset(LUA_REGISTRYINDEX);
|
||||
}
|
||||
state = NULL;
|
||||
_state = NULL;
|
||||
obj = NULL;
|
||||
}
|
||||
/**
|
||||
|
@ -646,17 +648,17 @@ template<typename T> struct lua_obj_pin
|
|||
/**
|
||||
* Push Lua value.
|
||||
*/
|
||||
void luapush(lua_state& state)
|
||||
void luapush(state& lstate)
|
||||
{
|
||||
state.pushlightuserdata(this);
|
||||
state.rawget(LUA_REGISTRYINDEX);
|
||||
lstate.pushlightuserdata(this);
|
||||
lstate.rawget(LUA_REGISTRYINDEX);
|
||||
}
|
||||
private:
|
||||
T* obj;
|
||||
lua_state* state;
|
||||
state* _state;
|
||||
};
|
||||
|
||||
template<typename T> void* unbox_any_pin(struct lua_obj_pin<T>* pin)
|
||||
template<typename T> void* unbox_any_pin(struct objpin<T>* pin)
|
||||
{
|
||||
return pin ? pin->object() : NULL;
|
||||
}
|
||||
|
@ -664,35 +666,36 @@ template<typename T> void* unbox_any_pin(struct lua_obj_pin<T>* pin)
|
|||
/**
|
||||
* Helper class containing binding data for Lua class call.
|
||||
*/
|
||||
template<class T> struct lua_class_bind_data
|
||||
template<class T> struct class_binding
|
||||
{
|
||||
/**
|
||||
* The pointer to call.
|
||||
*/
|
||||
int (T::*fn)(lua_state& state, const std::string& _fname);
|
||||
int (T::*fn)(state& lstate, const std::string& _fname);
|
||||
/**
|
||||
* The state to call it in.
|
||||
*/
|
||||
lua_state* state;
|
||||
state* _state;
|
||||
/**
|
||||
* The name of the method to pass.
|
||||
*/
|
||||
char fname[];
|
||||
};
|
||||
|
||||
template<class T> class lua_class;
|
||||
template<class T> class _class;
|
||||
|
||||
/**
|
||||
* Function to obtain class object for given Lua class.
|
||||
*/
|
||||
template<class T> lua_class<T>& objclass()
|
||||
template<class T> _class<T>& objclass()
|
||||
{
|
||||
if(lua_class_types().count(typeid(T)))
|
||||
auto& type = typeid(T);
|
||||
if(!class_types().count(type))
|
||||
throw std::runtime_error("Internal error: Lua class not found!");
|
||||
return *reinterpret_cast<lua_class<T>*>(lua_class_types()[typeid(T)]);
|
||||
return *reinterpret_cast<_class<T>*>(class_types()[type]);
|
||||
}
|
||||
|
||||
template<class T> struct lua_class_binding
|
||||
template<class T> struct class_method
|
||||
{
|
||||
/**
|
||||
* Name.
|
||||
|
@ -701,30 +704,30 @@ template<class T> struct lua_class_binding
|
|||
/**
|
||||
* Function.
|
||||
*/
|
||||
int (T::*fn)(lua_state& LS, const std::string& fname);
|
||||
int (T::*fn)(state& LS, const std::string& fname);
|
||||
};
|
||||
|
||||
/**
|
||||
* The type of Lua classes.
|
||||
*/
|
||||
template<class T> class lua_class
|
||||
template<class T> class _class
|
||||
{
|
||||
template<typename... U> T* _create(lua_state& state, U... args)
|
||||
template<typename... U> T* _create(state& _state, U... args)
|
||||
{
|
||||
void* obj = state.newuserdata(sizeof(T));
|
||||
load_metatable(state);
|
||||
state.setmetatable(-2);
|
||||
void* obj = _state.newuserdata(sizeof(T));
|
||||
load_metatable(_state);
|
||||
_state.setmetatable(-2);
|
||||
T* _obj = reinterpret_cast<T*>(obj);
|
||||
new(_obj) T(state, args...);
|
||||
new(_obj) T(_state, args...);
|
||||
return _obj;
|
||||
}
|
||||
|
||||
static int class_bind_trampoline(lua_State* LS)
|
||||
{
|
||||
try {
|
||||
lua_class_bind_data<T>* b = (lua_class_bind_data<T>*)lua_touserdata(LS, lua_upvalueindex(1));
|
||||
lua_state L(*b->state, LS);
|
||||
T* p = lua_class<T>::get(L, 1, b->fname);
|
||||
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);
|
||||
} catch(std::exception& e) {
|
||||
std::string err = e.what();
|
||||
|
@ -733,45 +736,45 @@ template<class T> class lua_class
|
|||
}
|
||||
}
|
||||
|
||||
T* _get(lua_state& state, int arg, const std::string& fname, bool optional = false)
|
||||
T* _get(state& _state, int arg, const std::string& fname, bool optional = false)
|
||||
{
|
||||
if(state.type(arg) == LUA_TNONE || state.type(arg) == LUA_TNIL) {
|
||||
if(_state.type(arg) == LUA_TNONE || _state.type(arg) == LUA_TNIL) {
|
||||
if(optional)
|
||||
return NULL;
|
||||
else
|
||||
goto badtype;
|
||||
}
|
||||
load_metatable(state);
|
||||
if(!state.getmetatable(arg))
|
||||
load_metatable(_state);
|
||||
if(!_state.getmetatable(arg))
|
||||
goto badtype;
|
||||
if(!state.rawequal(-1, -2))
|
||||
if(!_state.rawequal(-1, -2))
|
||||
goto badtype;
|
||||
state.pop(2);
|
||||
return reinterpret_cast<T*>(state.touserdata(arg));
|
||||
_state.pop(2);
|
||||
return reinterpret_cast<T*>(_state.touserdata(arg));
|
||||
badtype:
|
||||
(stringfmt() << "argument #" << arg << " to " << fname << " must be " << name).throwex();
|
||||
return NULL; //Never reached.
|
||||
}
|
||||
|
||||
bool _is(lua_state& state, int arg)
|
||||
bool _is(state& _state, int arg)
|
||||
{
|
||||
if(state.type(arg) != LUA_TUSERDATA)
|
||||
if(_state.type(arg) != LUA_TUSERDATA)
|
||||
return false;
|
||||
load_metatable(state);
|
||||
if(!state.getmetatable(arg)) {
|
||||
state.pop(1);
|
||||
load_metatable(_state);
|
||||
if(!_state.getmetatable(arg)) {
|
||||
_state.pop(1);
|
||||
return false;
|
||||
}
|
||||
bool ret = state.rawequal(-1, -2);
|
||||
state.pop(2);
|
||||
bool ret = _state.rawequal(-1, -2);
|
||||
_state.pop(2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
lua_obj_pin<T> _pin(lua_state& state, int arg, const std::string& fname)
|
||||
objpin<T> _pin(state& _state, int arg, const std::string& fname)
|
||||
{
|
||||
T* obj = get(state, arg, fname);
|
||||
state.pushvalue(arg);
|
||||
return lua_obj_pin<T>(state, obj);
|
||||
T* obj = get(_state, arg, fname);
|
||||
_state.pushvalue(arg);
|
||||
return objpin<T>(_state, obj);
|
||||
}
|
||||
public:
|
||||
/**
|
||||
|
@ -779,87 +782,88 @@ public:
|
|||
*
|
||||
* Parameter _name: The name of the class.
|
||||
*/
|
||||
lua_class(const std::string& _name)
|
||||
_class(const std::string& _name)
|
||||
{
|
||||
name = _name;
|
||||
luaclass_methods m;
|
||||
m.is = lua_class<T>::is;
|
||||
m.name = lua_class<T>::get_name;
|
||||
m.print = lua_class<T>::print;
|
||||
class_ops m;
|
||||
m.is = _class<T>::is;
|
||||
m.name = _class<T>::get_name;
|
||||
m.print = _class<T>::print;
|
||||
userdata_recogn_fns().push_back(m);
|
||||
lua_class_types()[typeid(T)] = this;
|
||||
auto& type = typeid(T);
|
||||
class_types()[type] = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of object.
|
||||
*
|
||||
* Parameter state: The Lua state to create the object in.
|
||||
* Parameter _state: The Lua state to create the object in.
|
||||
* Parameter args: The arguments to pass to class constructor.
|
||||
*/
|
||||
template<typename... U> static T* create(lua_state& state, U... args)
|
||||
template<typename... U> static T* create(state& _state, U... args)
|
||||
{
|
||||
return objclass<T>()._create(state, args...);
|
||||
return objclass<T>()._create(_state, args...);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind a method to class.
|
||||
*
|
||||
* Parameter state: The state to do the binding in.
|
||||
* Parameter _state: The state to do the binding in.
|
||||
* Parameter keyname: The name of the method.
|
||||
* Parameter fn: The method to call.
|
||||
* Parameter force: If true, overwrite existing method.
|
||||
*/
|
||||
void bind(lua_state& state, const char* keyname, int (T::*fn)(lua_state& LS, const std::string& fname))
|
||||
void bind(state& _state, const char* keyname, int (T::*fn)(state& LS, const std::string& fname))
|
||||
{
|
||||
load_metatable(state);
|
||||
state.pushstring(keyname);
|
||||
load_metatable(_state);
|
||||
_state.pushstring(keyname);
|
||||
std::string fname = name + std::string("::") + keyname;
|
||||
void* ptr = state.newuserdata(sizeof(lua_class_bind_data<T>) + fname.length() + 1);
|
||||
lua_class_bind_data<T>* bdata = reinterpret_cast<lua_class_bind_data<T>*>(ptr);
|
||||
void* ptr = _state.newuserdata(sizeof(class_binding<T>) + fname.length() + 1);
|
||||
class_binding<T>* bdata = reinterpret_cast<class_binding<T>*>(ptr);
|
||||
bdata->fn = fn;
|
||||
bdata->state = &state.get_master();
|
||||
bdata->_state = &_state.get_master();
|
||||
std::copy(fname.begin(), fname.end(), bdata->fname);
|
||||
bdata->fname[fname.length()] = 0;
|
||||
state.pushcclosure(class_bind_trampoline, 1);
|
||||
state.rawset(-3);
|
||||
state.pop(1);
|
||||
_state.pushcclosure(class_bind_trampoline, 1);
|
||||
_state.rawset(-3);
|
||||
_state.pop(1);
|
||||
}
|
||||
/**
|
||||
* Bind multiple at once.
|
||||
*/
|
||||
void bind_multi(lua_state& state, std::initializer_list<lua_class_binding<T>> list, void* doonce_key = NULL)
|
||||
void bind_multi(state& _state, std::initializer_list<class_method<T>> list, void* doonce_key = NULL)
|
||||
{
|
||||
static char once_key;
|
||||
if(state.do_once(doonce_key ? doonce_key : &once_key))
|
||||
if(_state.do_once(doonce_key ? doonce_key : &once_key))
|
||||
for(auto i : list)
|
||||
bind(state, i.name, i.fn);
|
||||
bind(_state, i.name, i.fn);
|
||||
}
|
||||
/**
|
||||
* Get a pointer to the object.
|
||||
*
|
||||
* Parameter state: The Lua state.
|
||||
* Parameter _state: The Lua state.
|
||||
* Parameter arg: Argument index.
|
||||
* Parameter fname: The name of function for error messages.
|
||||
* Parameter optional: If true and argument is NIL or none, return NULL.
|
||||
* Throws std::runtime_error: Wrong type.
|
||||
*/
|
||||
static T* get(lua_state& state, int arg, const std::string& fname, bool optional = false)
|
||||
static T* get(state& _state, int arg, const std::string& fname, bool optional = false)
|
||||
throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
return objclass<T>()._get(state, arg, fname, optional);
|
||||
return objclass<T>()._get(_state, arg, fname, optional);
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify if object is of this type.
|
||||
*
|
||||
* Parameter state: The Lua state.
|
||||
* Parameter _state: The Lua state.
|
||||
* Parameter arg: Argument index.
|
||||
* Returns: True if object is of specified type, false if not.
|
||||
*/
|
||||
static bool is(lua_state& state, int arg) throw()
|
||||
static bool is(state& _state, int arg) throw()
|
||||
{
|
||||
try {
|
||||
return objclass<T>()._is(state, arg);
|
||||
return objclass<T>()._is(_state, arg);
|
||||
} catch(...) {
|
||||
return false;
|
||||
}
|
||||
|
@ -879,23 +883,23 @@ public:
|
|||
/**
|
||||
* Format instance of this class as string.
|
||||
*/
|
||||
static std::string print(lua_state& state, int index)
|
||||
static std::string print(state& _state, int index)
|
||||
{
|
||||
T* obj = get(state, index, "__internal_print");
|
||||
T* obj = get(_state, index, "__internal_print");
|
||||
return obj->print();
|
||||
}
|
||||
/**
|
||||
* Get a pin of object against Lua GC.
|
||||
*
|
||||
* Parameter state: The Lua state.
|
||||
* Parameter _state: The Lua state.
|
||||
* Parameter arg: Argument index.
|
||||
* Parameter fname: Name of function for error message purposes.
|
||||
* Throws std::runtime_error: Wrong type.
|
||||
*/
|
||||
static lua_obj_pin<T> pin(lua_state& state, int arg, const std::string& fname) throw(std::bad_alloc,
|
||||
static objpin<T> pin(state& _state, int arg, const std::string& fname) throw(std::bad_alloc,
|
||||
std::runtime_error)
|
||||
{
|
||||
return objclass<T>()._pin(state, arg, fname);
|
||||
return objclass<T>()._pin(_state, arg, fname);
|
||||
}
|
||||
private:
|
||||
static int dogc(lua_State* LS)
|
||||
|
@ -920,84 +924,84 @@ private:
|
|||
return 1;
|
||||
}
|
||||
|
||||
void load_metatable(lua_state& state)
|
||||
void load_metatable(state& _state)
|
||||
{
|
||||
again:
|
||||
state.pushlightuserdata(this);
|
||||
state.rawget(LUA_REGISTRYINDEX);
|
||||
if(state.type(-1) == LUA_TNIL) {
|
||||
state.pop(1);
|
||||
state.pushlightuserdata(this);
|
||||
state.newtable();
|
||||
state.pushvalue(-1);
|
||||
state.setmetatable(-2);
|
||||
state.pushstring("__gc");
|
||||
state.pushcfunction(&lua_class<T>::dogc);
|
||||
state.rawset(-3);
|
||||
state.pushstring("__newindex");
|
||||
state.pushcfunction(&lua_class<T>::newindex);
|
||||
state.rawset(-3);
|
||||
state.pushstring("__index");
|
||||
state.pushcfunction(&lua_class<T>::index);
|
||||
state.rawset(-3);
|
||||
state.rawset(LUA_REGISTRYINDEX);
|
||||
_state.pushlightuserdata(this);
|
||||
_state.rawget(LUA_REGISTRYINDEX);
|
||||
if(_state.type(-1) == LUA_TNIL) {
|
||||
_state.pop(1);
|
||||
_state.pushlightuserdata(this);
|
||||
_state.newtable();
|
||||
_state.pushvalue(-1);
|
||||
_state.setmetatable(-2);
|
||||
_state.pushstring("__gc");
|
||||
_state.pushcfunction(&_class<T>::dogc);
|
||||
_state.rawset(-3);
|
||||
_state.pushstring("__newindex");
|
||||
_state.pushcfunction(&_class<T>::newindex);
|
||||
_state.rawset(-3);
|
||||
_state.pushstring("__index");
|
||||
_state.pushcfunction(&_class<T>::index);
|
||||
_state.rawset(-3);
|
||||
_state.rawset(LUA_REGISTRYINDEX);
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
std::string name;
|
||||
lua_class(const lua_class<T>&);
|
||||
lua_class& operator=(const lua_class<T>&);
|
||||
_class(const _class<T>&);
|
||||
_class& operator=(const _class<T>&);
|
||||
};
|
||||
|
||||
/**
|
||||
* Function implemented in C++ exported to Lua.
|
||||
*/
|
||||
class lua_function
|
||||
class function
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Register function.
|
||||
*/
|
||||
lua_function(lua_function_group& group, const std::string& name) throw(std::bad_alloc);
|
||||
function(function_group& group, const std::string& name) throw(std::bad_alloc);
|
||||
/**
|
||||
* Unregister function.
|
||||
*/
|
||||
virtual ~lua_function() throw();
|
||||
virtual ~function() throw();
|
||||
|
||||
/**
|
||||
* Invoke function.
|
||||
*/
|
||||
virtual int invoke(lua_state& L) = 0;
|
||||
virtual int invoke(state& L) = 0;
|
||||
protected:
|
||||
std::string fname;
|
||||
lua_function_group& group;
|
||||
function_group& group;
|
||||
};
|
||||
|
||||
/**
|
||||
* Register function pointer as lua function.
|
||||
*/
|
||||
class function_ptr_luafun : public lua_function
|
||||
class fnptr : public function
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Register.
|
||||
*/
|
||||
function_ptr_luafun(lua_function_group& group, const std::string& name,
|
||||
int (*_fn)(lua_state& L, const std::string& fname))
|
||||
: lua_function(group, name)
|
||||
fnptr(function_group& group, const std::string& name,
|
||||
int (*_fn)(state& L, const std::string& fname))
|
||||
: function(group, name)
|
||||
{
|
||||
fn = _fn;
|
||||
}
|
||||
/**
|
||||
* Invoke function.
|
||||
*/
|
||||
int invoke(lua_state& L)
|
||||
int invoke(state& L)
|
||||
{
|
||||
return fn(L, fname);
|
||||
}
|
||||
private:
|
||||
int (*fn)(lua_state& L, const std::string& fname);
|
||||
int (*fn)(state& L, const std::string& fname);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -5,7 +5,7 @@
|
|||
#include <string>
|
||||
#include <cstdint>
|
||||
#include "core/window.hpp"
|
||||
#include "library/luabase.hpp"
|
||||
#include "library/lua-base.hpp"
|
||||
#include "library/framebuffer.hpp"
|
||||
#include "library/threadtypes.hpp"
|
||||
#include "library/string.hpp"
|
||||
|
@ -13,7 +13,7 @@
|
|||
struct lua_palette
|
||||
{
|
||||
std::vector<framebuffer::color> colors;
|
||||
lua_palette(lua_state& L);
|
||||
lua_palette(lua::state& L);
|
||||
~lua_palette();
|
||||
mutex_class palette_mutex;
|
||||
std::string print();
|
||||
|
@ -21,7 +21,7 @@ struct lua_palette
|
|||
|
||||
struct lua_bitmap
|
||||
{
|
||||
lua_bitmap(lua_state& L, uint32_t w, uint32_t h);
|
||||
lua_bitmap(lua::state& L, uint32_t w, uint32_t h);
|
||||
~lua_bitmap();
|
||||
size_t width;
|
||||
size_t height;
|
||||
|
@ -32,7 +32,7 @@ struct lua_bitmap
|
|||
|
||||
struct lua_dbitmap
|
||||
{
|
||||
lua_dbitmap(lua_state& L, uint32_t w, uint32_t h);
|
||||
lua_dbitmap(lua::state& L, uint32_t w, uint32_t h);
|
||||
~lua_dbitmap();
|
||||
size_t width;
|
||||
size_t height;
|
||||
|
|
|
@ -5,17 +5,17 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include "library/luabase.hpp"
|
||||
#include "library/lua-base.hpp"
|
||||
#include "library/lua-framebuffer.hpp"
|
||||
|
||||
extern lua_state lsnes_lua_state;
|
||||
extern lua_function_group lua_func_bit;
|
||||
extern lua_function_group lua_func_misc;
|
||||
extern lua_function_group lua_func_callback;
|
||||
extern lua_function_group lua_func_load;
|
||||
extern lua_function_group lua_func_zip;
|
||||
extern lua::state lsnes_lua_state;
|
||||
extern lua::function_group lua_func_bit;
|
||||
extern lua::function_group lua_func_misc;
|
||||
extern lua::function_group lua_func_callback;
|
||||
extern lua::function_group lua_func_load;
|
||||
extern lua::function_group lua_func_zip;
|
||||
|
||||
void push_keygroup_parameters(lua_state& L, keyboard::key& p);
|
||||
void push_keygroup_parameters(lua::state& L, keyboard::key& p);
|
||||
extern lua_render_context* lua_render_ctx;
|
||||
extern controller_frame* lua_input_controllerdata;
|
||||
extern bool* lua_kill_frame;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#ifndef _lua__unsaferewind__hpp__included__
|
||||
#define _lua__unsaferewind__hpp__included__
|
||||
|
||||
#include "library/luabase.hpp"
|
||||
#include "library/lua-base.hpp"
|
||||
#include "library/string.hpp"
|
||||
|
||||
struct lua_unsaferewind
|
||||
{
|
||||
lua_unsaferewind(lua_state& L);
|
||||
lua_unsaferewind(lua::state& L);
|
||||
std::vector<char> state;
|
||||
uint64_t frame;
|
||||
uint64_t lag;
|
||||
|
|
|
@ -202,7 +202,7 @@ namespace
|
|||
keyboard::invbind _mtback(lsnes_mapper, "rotate-multitrack-backwards", "Multitrack‣Rotate backwards");
|
||||
keyboard::invbind _mtfwd(lsnes_mapper, "rotate-multitrack", "Multitrack‣Rotate forward");
|
||||
|
||||
function_ptr_luafun mtlua(lua_func_misc, "input.multitrack_state", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr mtlua(lua_func_misc, "input.multitrack_state", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
unsigned port = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(2, fname.c_str());
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
uint64_t get_vmabase(lua_state& L, const std::string& vma)
|
||||
uint64_t get_vmabase(lua::state& L, const std::string& vma)
|
||||
{
|
||||
for(auto i : lsnes_memory.get_regions())
|
||||
if(i->name == vma)
|
||||
|
@ -12,7 +12,7 @@ namespace
|
|||
throw std::runtime_error("No such VMA");
|
||||
}
|
||||
|
||||
function_ptr_luafun dump_memory_bitmap(lua_func_misc, "bsnes.dump_sprite", [](lua_state& L,
|
||||
lua::fnptr dump_memory_bitmap(lua_func_misc, "bsnes.dump_sprite", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
int index = 1;
|
||||
uint64_t vmabase = 0;
|
||||
|
@ -24,7 +24,7 @@ namespace
|
|||
uint64_t addr = L.get_numeric_argument<uint64_t>(index++, fname.c_str()) + vmabase;
|
||||
uint32_t width = L.get_numeric_argument<uint32_t>(index++, fname.c_str());
|
||||
uint32_t height = L.get_numeric_argument<uint32_t>(index++, fname.c_str());
|
||||
lua_bitmap* b = lua_class<lua_bitmap>::create(L, width * 8, height * 8);
|
||||
lua_bitmap* b = lua::_class<lua_bitmap>::create(L, width * 8, height * 8);
|
||||
size_t stride1 = 32;
|
||||
size_t stride2 = 512;
|
||||
L.get_numeric_argument<size_t>(index++, stride2, fname.c_str());
|
||||
|
@ -50,7 +50,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun dump_memory_palette(lua_func_misc, "bsnes.dump_palette", [](lua_state& L,
|
||||
lua::fnptr dump_memory_palette(lua_func_misc, "bsnes.dump_palette", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
int index = 1;
|
||||
uint64_t vmabase = 0;
|
||||
|
@ -63,7 +63,7 @@ namespace
|
|||
bool full = L.get_bool(index++, fname.c_str());
|
||||
bool ftrans = L.get_bool(index++, fname.c_str());
|
||||
size_t ps = full ? 256 : 16;
|
||||
lua_palette* p = lua_class<lua_palette>::create(L);
|
||||
lua_palette* p = lua::_class<lua_palette>::create(L);
|
||||
for(unsigned j = 0; j < ps; j++) {
|
||||
if(j == 0 && ftrans)
|
||||
p->colors.push_back(framebuffer::color(-1));
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include "library/string.hpp"
|
||||
#include "library/controller-data.hpp"
|
||||
#include "library/framebuffer.hpp"
|
||||
#include "library/luabase.hpp"
|
||||
#include "library/lua-base.hpp"
|
||||
#include "lua/internal.hpp"
|
||||
#ifdef BSNES_HAS_DEBUGGER
|
||||
#define DEBUGGER
|
||||
|
@ -1352,10 +1352,10 @@ again2:
|
|||
});
|
||||
|
||||
#ifdef BSNES_HAS_DEBUGGER
|
||||
lua_state* snes_debug_cb_keys[SNES::Debugger::Breakpoints];
|
||||
lua_state* snes_debug_cb_trace;
|
||||
lua::state* snes_debug_cb_keys[SNES::Debugger::Breakpoints];
|
||||
lua::state* snes_debug_cb_trace;
|
||||
|
||||
void snesdbg_execute_callback(lua_state*& cb, signed r)
|
||||
void snesdbg_execute_callback(lua::state*& cb, signed r)
|
||||
{
|
||||
if(!cb)
|
||||
return;
|
||||
|
@ -1387,7 +1387,7 @@ again2:
|
|||
snesdbg_execute_callback(snes_debug_cb_trace, -1);
|
||||
}
|
||||
|
||||
void snesdbg_set_callback(lua_state& L, lua_state*& cb)
|
||||
void snesdbg_set_callback(lua::state& L, lua::state*& cb)
|
||||
{
|
||||
cb = &L.get_master();
|
||||
L.pushlightuserdata(&cb);
|
||||
|
@ -1395,7 +1395,7 @@ again2:
|
|||
L.settable(LUA_REGISTRYINDEX);
|
||||
}
|
||||
|
||||
bool snesdbg_get_bp_enabled(lua_state& L)
|
||||
bool snesdbg_get_bp_enabled(lua::state& L)
|
||||
{
|
||||
bool r;
|
||||
L.getfield(-1, "addr");
|
||||
|
@ -1404,7 +1404,7 @@ again2:
|
|||
return r;
|
||||
}
|
||||
|
||||
uint32_t snesdbg_get_bp_addr(lua_state& L)
|
||||
uint32_t snesdbg_get_bp_addr(lua::state& L)
|
||||
{
|
||||
uint32_t r = 0;
|
||||
L.getfield(-1, "addr");
|
||||
|
@ -1414,7 +1414,7 @@ again2:
|
|||
return r;
|
||||
}
|
||||
|
||||
uint32_t snesdbg_get_bp_data(lua_state& L)
|
||||
uint32_t snesdbg_get_bp_data(lua::state& L)
|
||||
{
|
||||
signed r = -1;
|
||||
L.getfield(-1, "data");
|
||||
|
@ -1424,7 +1424,7 @@ again2:
|
|||
return r;
|
||||
}
|
||||
|
||||
SNES::Debugger::Breakpoint::Mode snesdbg_get_bp_mode(lua_state& L)
|
||||
SNES::Debugger::Breakpoint::Mode snesdbg_get_bp_mode(lua::state& L)
|
||||
{
|
||||
SNES::Debugger::Breakpoint::Mode r = SNES::Debugger::Breakpoint::Mode::Exec;
|
||||
L.getfield(-1, "mode");
|
||||
|
@ -1446,7 +1446,7 @@ again2:
|
|||
return r;
|
||||
}
|
||||
|
||||
SNES::Debugger::Breakpoint::Source snesdbg_get_bp_source(lua_state& L)
|
||||
SNES::Debugger::Breakpoint::Source snesdbg_get_bp_source(lua::state& L)
|
||||
{
|
||||
SNES::Debugger::Breakpoint::Source r = SNES::Debugger::Breakpoint::Source::CPUBus;
|
||||
L.getfield(-1, "source");
|
||||
|
@ -1464,12 +1464,12 @@ again2:
|
|||
return r;
|
||||
}
|
||||
|
||||
void snesdbg_get_bp_callback(lua_state& L)
|
||||
void snesdbg_get_bp_callback(lua::state& L)
|
||||
{
|
||||
L.getfield(-1, "callback");
|
||||
}
|
||||
|
||||
function_ptr_luafun lua_memory_setdebug(lua_func_misc, "memory.setdebug", [](lua_state& L,
|
||||
lua::fnptr lua_memory_setdebug(lua_func_misc, "memory.setdebug", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
unsigned r = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
if(r >= SNES::Debugger::Breakpoints)
|
||||
|
@ -1494,7 +1494,7 @@ again2:
|
|||
throw std::runtime_error("Expected argument 2 to memory.setdebug to be nil or table");
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_memory_setstep(lua_func_misc, "memory.setstep", [](lua_state& L,
|
||||
lua::fnptr lua_memory_setstep(lua_func_misc, "memory.setstep", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
uint64_t r = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
L.pushvalue(2);
|
||||
|
@ -1505,7 +1505,7 @@ again2:
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_memory_settrace(lua_func_misc, "memory.settrace", [](lua_state& L,
|
||||
lua::fnptr lua_memory_settrace(lua_func_misc, "memory.settrace", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
std::string r = L.get_string(1, fname.c_str());
|
||||
lsnes_cmd.invoke("tracelog cpu " + r);
|
||||
|
@ -1518,7 +1518,7 @@ again2:
|
|||
});
|
||||
|
||||
#ifdef BSNES_IS_COMPAT
|
||||
function_ptr_luafun lua_layerenabled(lua_func_misc, "snes.enablelayer", [](lua_state& L,
|
||||
lua::fnptr lua_layerenabled(lua_func_misc, "snes.enablelayer", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
unsigned layer = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
unsigned priority = L.get_numeric_argument<unsigned>(2, fname.c_str());
|
||||
|
@ -1528,7 +1528,7 @@ again2:
|
|||
});
|
||||
#endif
|
||||
|
||||
function_ptr_luafun lua_smpdiasm(lua_func_misc, "snes.smpdisasm", [](lua_state& L, const std::string& fname) ->
|
||||
lua::fnptr lua_smpdiasm(lua_func_misc, "snes.smpdisasm", [](lua::state& L, const std::string& fname) ->
|
||||
int {
|
||||
unsigned addr = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
nall::string _disasm = SNES::smp.disassemble_opcode(addr);
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include "luabase.hpp"
|
||||
#include "lua-base.hpp"
|
||||
#include "register-queue.hpp"
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
std::unordered_map<std::type_index, void*>& lua_class_types()
|
||||
namespace lua
|
||||
{
|
||||
std::unordered_map<std::type_index, void*>& class_types()
|
||||
{
|
||||
static std::unordered_map<std::type_index, void*> x;
|
||||
return x;
|
||||
|
@ -13,9 +15,9 @@ namespace
|
|||
int lua_trampoline_function(lua_State* L)
|
||||
{
|
||||
void* ptr = lua_touserdata(L, lua_upvalueindex(1));
|
||||
lua_state* state = reinterpret_cast<lua_state*>(lua_touserdata(L, lua_upvalueindex(2)));
|
||||
lua_function* f = reinterpret_cast<lua_function*>(ptr);
|
||||
lua_state _L(*state, L);
|
||||
state* lstate = reinterpret_cast<state*>(lua_touserdata(L, lua_upvalueindex(2)));
|
||||
function* f = reinterpret_cast<function*>(ptr);
|
||||
state _L(*lstate, L);
|
||||
try {
|
||||
return f->invoke(_L);
|
||||
} catch(std::exception& e) {
|
||||
|
@ -26,7 +28,7 @@ namespace
|
|||
}
|
||||
|
||||
//Pushes given table to top of stack, creating if needed.
|
||||
void recursive_lookup_table(lua_state& L, const std::string& tab)
|
||||
void recursive_lookup_table(state& L, const std::string& tab)
|
||||
{
|
||||
if(tab == "") {
|
||||
#if LUA_VERSION_NUM == 501
|
||||
|
@ -60,7 +62,7 @@ namespace
|
|||
L.pop(1);
|
||||
}
|
||||
|
||||
void register_lua_function(lua_state& L, const std::string& name, lua_function* fun)
|
||||
void register_function(state& L, const std::string& name, function* fun)
|
||||
{
|
||||
std::string u = name;
|
||||
size_t split = u.find_last_of(".");
|
||||
|
@ -82,13 +84,13 @@ namespace
|
|||
L.setfield(-2, u2.c_str());
|
||||
L.pop(1);
|
||||
}
|
||||
typedef register_queue<lua_state, lua_function> regqueue_t;
|
||||
typedef register_queue<lua_state::callback_proxy, lua_state::lua_callback_list> regqueue2_t;
|
||||
typedef register_queue<lua_function_group, lua_function> regqueue3_t;
|
||||
typedef register_queue<state, function> regqueue_t;
|
||||
typedef register_queue<state::callback_proxy, state::callback_list> regqueue2_t;
|
||||
typedef register_queue<function_group, function> regqueue3_t;
|
||||
}
|
||||
|
||||
|
||||
lua_state::lua_state() throw(std::bad_alloc)
|
||||
state::state() throw(std::bad_alloc)
|
||||
: cbproxy(*this)
|
||||
{
|
||||
master = NULL;
|
||||
|
@ -97,14 +99,14 @@ lua_state::lua_state() throw(std::bad_alloc)
|
|||
regqueue2_t::do_ready(cbproxy, true);
|
||||
}
|
||||
|
||||
lua_state::lua_state(lua_state& _master, lua_State* L)
|
||||
state::state(state& _master, lua_State* L)
|
||||
: cbproxy(*this)
|
||||
{
|
||||
master = &_master;
|
||||
lua_handle = L;
|
||||
}
|
||||
|
||||
lua_state::~lua_state() throw()
|
||||
state::~state() throw()
|
||||
{
|
||||
if(master)
|
||||
return;
|
||||
|
@ -115,18 +117,18 @@ lua_state::~lua_state() throw()
|
|||
lua_close(lua_handle);
|
||||
}
|
||||
|
||||
void lua_state::builtin_oom()
|
||||
void state::builtin_oom()
|
||||
{
|
||||
std::cerr << "PANIC: FATAL: Out of memory" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void* lua_state::builtin_alloc(void* user, void* old, size_t olds, size_t news)
|
||||
void* state::builtin_alloc(void* user, void* old, size_t olds, size_t news)
|
||||
{
|
||||
if(news) {
|
||||
void* m = realloc(old, news);
|
||||
if(!m)
|
||||
reinterpret_cast<lua_state*>(user)->oom_handler();
|
||||
reinterpret_cast<state*>(user)->oom_handler();
|
||||
return m;
|
||||
} else
|
||||
free(old);
|
||||
|
@ -134,23 +136,23 @@ void* lua_state::builtin_alloc(void* user, void* old, size_t olds, size_t news)
|
|||
}
|
||||
|
||||
|
||||
lua_function::lua_function(lua_function_group& _group, const std::string& func) throw(std::bad_alloc)
|
||||
function::function(function_group& _group, const std::string& func) throw(std::bad_alloc)
|
||||
: group(_group)
|
||||
{
|
||||
regqueue3_t::do_register(group, fname = func, *this);
|
||||
}
|
||||
|
||||
lua_function::~lua_function() throw()
|
||||
function::~function() throw()
|
||||
{
|
||||
regqueue3_t::do_unregister(group, fname);
|
||||
}
|
||||
|
||||
void lua_state::reset() throw(std::bad_alloc, std::runtime_error)
|
||||
void state::reset() throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
if(master)
|
||||
return master->reset();
|
||||
if(lua_handle) {
|
||||
lua_State* tmp = lua_newstate(lua_state::builtin_alloc, this);
|
||||
lua_State* tmp = lua_newstate(state::builtin_alloc, this);
|
||||
if(!tmp)
|
||||
throw std::runtime_error("Can't re-initialize Lua interpretter");
|
||||
lua_close(lua_handle);
|
||||
|
@ -159,17 +161,17 @@ void lua_state::reset() throw(std::bad_alloc, std::runtime_error)
|
|||
lua_handle = tmp;
|
||||
} else {
|
||||
//Initialize new.
|
||||
lua_handle = lua_newstate(lua_state::builtin_alloc, this);
|
||||
lua_handle = lua_newstate(state::builtin_alloc, this);
|
||||
if(!lua_handle)
|
||||
throw std::runtime_error("Can't initialize Lua interpretter");
|
||||
}
|
||||
for(auto i : function_groups)
|
||||
i.first->request_callback([this](std::string name, lua_function* func) -> void {
|
||||
register_lua_function(*this, name, func);
|
||||
i.first->request_callback([this](std::string name, function* func) -> void {
|
||||
register_function(*this, name, func);
|
||||
});
|
||||
}
|
||||
|
||||
void lua_state::deinit() throw()
|
||||
void state::deinit() throw()
|
||||
{
|
||||
if(master)
|
||||
return master->deinit();
|
||||
|
@ -178,12 +180,12 @@ void lua_state::deinit() throw()
|
|||
lua_handle = NULL;
|
||||
}
|
||||
|
||||
void lua_state::add_function_group(lua_function_group& group)
|
||||
void state::add_function_group(function_group& group)
|
||||
{
|
||||
function_groups.insert(std::make_pair(&group, group.add_callback([this](const std::string& name,
|
||||
lua_function* func) -> void {
|
||||
function* func) -> void {
|
||||
this->function_callback(name, func);
|
||||
}, [this](lua_function_group* x) {
|
||||
}, [this](function_group* x) {
|
||||
for(auto i = this->function_groups.begin(); i != this->function_groups.end();)
|
||||
if(i->first == x)
|
||||
i = this->function_groups.erase(i);
|
||||
|
@ -192,15 +194,15 @@ void lua_state::add_function_group(lua_function_group& group)
|
|||
})));
|
||||
}
|
||||
|
||||
void lua_state::function_callback(const std::string& name, lua_function* func)
|
||||
void state::function_callback(const std::string& name, function* func)
|
||||
{
|
||||
if(master)
|
||||
return master->function_callback(name, func);
|
||||
if(lua_handle)
|
||||
register_lua_function(*this, name, func);
|
||||
register_function(*this, name, func);
|
||||
}
|
||||
|
||||
bool lua_state::do_once(void* key)
|
||||
bool state::do_once(void* key)
|
||||
{
|
||||
if(master)
|
||||
return master->do_once(key);
|
||||
|
@ -218,13 +220,13 @@ bool lua_state::do_once(void* key)
|
|||
}
|
||||
}
|
||||
|
||||
lua_state::lua_callback_list::lua_callback_list(lua_state& _L, const std::string& _name, const std::string& fncbname)
|
||||
state::callback_list::callback_list(state& _L, const std::string& _name, const std::string& fncbname)
|
||||
: L(_L), name(_name), fn_cbname(fncbname)
|
||||
{
|
||||
regqueue2_t::do_register(L.cbproxy, name, *this);
|
||||
}
|
||||
|
||||
lua_state::lua_callback_list::~lua_callback_list()
|
||||
state::callback_list::~callback_list()
|
||||
{
|
||||
regqueue2_t::do_unregister(L.cbproxy, name);
|
||||
if(!L.handle())
|
||||
|
@ -236,7 +238,7 @@ lua_state::lua_callback_list::~lua_callback_list()
|
|||
}
|
||||
}
|
||||
|
||||
void lua_state::lua_callback_list::_register(lua_state& _L)
|
||||
void state::callback_list::_register(state& _L)
|
||||
{
|
||||
callbacks.push_back(0);
|
||||
_L.pushlightuserdata(&*callbacks.rbegin());
|
||||
|
@ -244,7 +246,7 @@ void lua_state::lua_callback_list::_register(lua_state& _L)
|
|||
_L.rawset(LUA_REGISTRYINDEX);
|
||||
}
|
||||
|
||||
void lua_state::lua_callback_list::_unregister(lua_state& _L)
|
||||
void state::callback_list::_unregister(state& _L)
|
||||
{
|
||||
for(auto i = callbacks.begin(); i != callbacks.end();) {
|
||||
_L.pushlightuserdata(&*i);
|
||||
|
@ -261,13 +263,13 @@ void lua_state::lua_callback_list::_unregister(lua_state& _L)
|
|||
}
|
||||
}
|
||||
|
||||
lua_function_group::lua_function_group()
|
||||
function_group::function_group()
|
||||
{
|
||||
next_handle = 0;
|
||||
regqueue3_t::do_ready(*this, true);
|
||||
}
|
||||
|
||||
lua_function_group::~lua_function_group()
|
||||
function_group::~function_group()
|
||||
{
|
||||
for(auto i : functions)
|
||||
for(auto j : callbacks)
|
||||
|
@ -277,14 +279,14 @@ lua_function_group::~lua_function_group()
|
|||
regqueue3_t::do_ready(*this, false);
|
||||
}
|
||||
|
||||
void lua_function_group::request_callback(std::function<void(std::string, lua_function*)> cb)
|
||||
void function_group::request_callback(std::function<void(std::string, function*)> cb)
|
||||
{
|
||||
for(auto i : functions)
|
||||
cb(i.first, i.second);
|
||||
}
|
||||
|
||||
int lua_function_group::add_callback(std::function<void(std::string, lua_function*)> cb,
|
||||
std::function<void(lua_function_group*)> dcb)
|
||||
int function_group::add_callback(std::function<void(std::string, function*)> cb,
|
||||
std::function<void(function_group*)> dcb)
|
||||
{
|
||||
int handle = next_handle++;
|
||||
callbacks[handle] = cb;
|
||||
|
@ -294,32 +296,32 @@ int lua_function_group::add_callback(std::function<void(std::string, lua_functio
|
|||
return handle;
|
||||
}
|
||||
|
||||
void lua_function_group::drop_callback(int handle)
|
||||
void function_group::drop_callback(int handle)
|
||||
{
|
||||
callbacks.erase(handle);
|
||||
}
|
||||
|
||||
void lua_function_group::do_register(const std::string& name, lua_function& fun)
|
||||
void function_group::do_register(const std::string& name, function& fun)
|
||||
{
|
||||
functions[name] = &fun;
|
||||
for(auto i : callbacks)
|
||||
i.second(name, &fun);
|
||||
}
|
||||
|
||||
void lua_function_group::do_unregister(const std::string& name)
|
||||
void function_group::do_unregister(const std::string& name)
|
||||
{
|
||||
functions.erase(name);
|
||||
for(auto i : callbacks)
|
||||
i.second(name, NULL);
|
||||
}
|
||||
|
||||
std::list<luaclass_methods>& userdata_recogn_fns()
|
||||
std::list<class_ops>& userdata_recogn_fns()
|
||||
{
|
||||
static std::list<luaclass_methods> x;
|
||||
static std::list<class_ops> x;
|
||||
return x;
|
||||
}
|
||||
|
||||
std::string try_recognize_userdata(lua_state& state, int index)
|
||||
std::string try_recognize_userdata(state& state, int index)
|
||||
{
|
||||
for(auto i : userdata_recogn_fns())
|
||||
if(i.is(state, index))
|
||||
|
@ -338,7 +340,7 @@ std::string try_recognize_userdata(lua_state& state, int index)
|
|||
return "unknown";
|
||||
}
|
||||
|
||||
std::string try_print_userdata(lua_state& L, int index)
|
||||
std::string try_print_userdata(state& L, int index)
|
||||
{
|
||||
for(auto i : userdata_recogn_fns())
|
||||
if(i.is(L, index))
|
||||
|
@ -346,7 +348,7 @@ std::string try_print_userdata(lua_state& L, int index)
|
|||
return "no data available";
|
||||
}
|
||||
|
||||
int lua_state::vararg_tag::pushargs(lua_state& L)
|
||||
int state::vararg_tag::pushargs(state& L)
|
||||
{
|
||||
int e = 0;
|
||||
for(auto i : args) {
|
||||
|
@ -366,3 +368,4 @@ int lua_state::vararg_tag::pushargs(lua_state& L)
|
|||
}
|
||||
return e;
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_luafun c_action(lua_func_misc, "memory.action", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr c_action(lua_func_misc, "memory.action", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
std::string name = L.get_string(1, fname.c_str());
|
||||
const interface_action* act = NULL;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_luafun kbind(lua_func_misc, "keyboard.bind", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr kbind(lua_func_misc, "keyboard.bind", [](lua::state& L, const std::string& fname) -> int {
|
||||
std::string mod = L.get_string(1, fname.c_str());
|
||||
std::string mask = L.get_string(2, fname.c_str());
|
||||
std::string key = L.get_string(3, fname.c_str());
|
||||
|
@ -14,7 +14,7 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun kunbind(lua_func_misc, "keyboard.unbind", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr kunbind(lua_func_misc, "keyboard.unbind", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
std::string mod = L.get_string(1, fname.c_str());
|
||||
std::string mask = L.get_string(2, fname.c_str());
|
||||
|
@ -23,7 +23,7 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun kalias(lua_func_misc, "keyboard.alias", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr kalias(lua_func_misc, "keyboard.alias", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
std::string alias = L.get_string(1, fname.c_str());
|
||||
std::string cmds = L.get_string(2, fname.c_str());
|
||||
|
|
|
@ -68,11 +68,11 @@ namespace
|
|||
}
|
||||
|
||||
template<uint64_t (*combine)(uint64_t chain, uint64_t arg), uint64_t init>
|
||||
class lua_symmetric_bitwise : public lua_function
|
||||
class lua_symmetric_bitwise : public lua::function
|
||||
{
|
||||
public:
|
||||
lua_symmetric_bitwise(const std::string& s) : lua_function(lua_func_bit, s) {};
|
||||
int invoke(lua_state& L)
|
||||
lua_symmetric_bitwise(const std::string& s) : lua::function(lua_func_bit, s) {};
|
||||
int invoke(lua::state& L)
|
||||
{
|
||||
int stacksize = 0;
|
||||
while(!L.isnone(stacksize + 1))
|
||||
|
@ -86,11 +86,11 @@ namespace
|
|||
};
|
||||
|
||||
template<uint64_t (*shift)(uint64_t base, uint64_t amount, uint64_t bits)>
|
||||
class lua_shifter : public lua_function
|
||||
class lua_shifter : public lua::function
|
||||
{
|
||||
public:
|
||||
lua_shifter(const std::string& s) : lua_function(lua_func_bit, s) {};
|
||||
int invoke(lua_state& L)
|
||||
lua_shifter(const std::string& s) : lua::function(lua_func_bit, s) {};
|
||||
int invoke(lua::state& L)
|
||||
{
|
||||
uint64_t base;
|
||||
uint64_t amount = 1;
|
||||
|
@ -103,7 +103,7 @@ namespace
|
|||
}
|
||||
};
|
||||
|
||||
function_ptr_luafun lua_bextract(lua_func_bit, "bit.extract", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr lua_bextract(lua_func_bit, "bit.extract", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint64_t num = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
uint64_t ret = 0;
|
||||
|
@ -121,7 +121,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_bvalue(lua_func_bit, "bit.value", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr lua_bvalue(lua_func_bit, "bit.value", [](lua::state& L, const std::string& fname) -> int {
|
||||
uint64_t ret = 0;
|
||||
for(size_t i = 0;; i++) {
|
||||
if(L.isnumber(i + 1)) {
|
||||
|
@ -135,7 +135,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_testany(lua_func_bit, "bit.test_any", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr lua_testany(lua_func_bit, "bit.test_any", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint64_t a = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
uint64_t b = L.get_numeric_argument<uint64_t>(2, fname.c_str());
|
||||
|
@ -143,7 +143,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_testall(lua_func_bit, "bit.test_all", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr lua_testall(lua_func_bit, "bit.test_all", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint64_t a = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
uint64_t b = L.get_numeric_argument<uint64_t>(2, fname.c_str());
|
||||
|
@ -163,14 +163,14 @@ namespace
|
|||
return c;
|
||||
}
|
||||
|
||||
function_ptr_luafun lua_popcount(lua_func_bit, "bit.popcount", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr lua_popcount(lua_func_bit, "bit.popcount", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint64_t a = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
L.pushnumber(popcount(a));
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_clshift(lua_func_bit, "bit.clshift", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr lua_clshift(lua_func_bit, "bit.clshift", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
unsigned amount = 1;
|
||||
unsigned bits = 48;
|
||||
|
@ -191,7 +191,7 @@ namespace
|
|||
return 2;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_crshift(lua_func_bit, "bit.crshift", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr lua_crshift(lua_func_bit, "bit.crshift", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
unsigned amount = 1;
|
||||
unsigned bits = 48;
|
||||
|
@ -211,7 +211,7 @@ namespace
|
|||
return 2;
|
||||
});
|
||||
|
||||
int flagdecode_core(lua_state& L, const std::string& fname, bool reverse)
|
||||
int flagdecode_core(lua::state& L, const std::string& fname, bool reverse)
|
||||
{
|
||||
uint64_t a = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
uint64_t b = L.get_numeric_argument<uint64_t>(2, fname.c_str());
|
||||
|
@ -237,12 +237,12 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
function_ptr_luafun lua_flagdecode(lua_func_bit, "bit.flagdecode", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr lua_flagdecode(lua_func_bit, "bit.flagdecode", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
return flagdecode_core(L, fname, false);
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_rflagdecode(lua_func_bit, "bit.rflagdecode", [](lua_state& L,
|
||||
lua::fnptr lua_rflagdecode(lua_func_bit, "bit.rflagdecode", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return flagdecode_core(L, fname, true);
|
||||
});
|
||||
|
|
|
@ -7,9 +7,9 @@ namespace
|
|||
class lua_callbacks_list
|
||||
{
|
||||
public:
|
||||
lua_callbacks_list(lua_state& L);
|
||||
int index(lua_state& L, const std::string& fname);
|
||||
int newindex(lua_state& L, const std::string& fname);
|
||||
lua_callbacks_list(lua::state& L);
|
||||
int index(lua::state& L, const std::string& fname);
|
||||
int newindex(lua::state& L, const std::string& fname);
|
||||
std::string print()
|
||||
{
|
||||
return "";
|
||||
|
@ -19,10 +19,10 @@ namespace
|
|||
class lua_callback_obj
|
||||
{
|
||||
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);
|
||||
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);
|
||||
std::string print()
|
||||
{
|
||||
if(callback)
|
||||
|
@ -31,36 +31,36 @@ namespace
|
|||
return "(null)";
|
||||
}
|
||||
private:
|
||||
lua_state::lua_callback_list* callback;
|
||||
lua::state::callback_list* callback;
|
||||
int special;
|
||||
};
|
||||
|
||||
lua_class<lua_callbacks_list> class_callbacks_list("CALLBACKS_LIST");
|
||||
lua_class<lua_callback_obj> class_callback_obj("CALLBACK_OBJ");
|
||||
lua::_class<lua_callbacks_list> class_callbacks_list("CALLBACKS_LIST");
|
||||
lua::_class<lua_callback_obj> class_callback_obj("CALLBACK_OBJ");
|
||||
|
||||
lua_callbacks_list::lua_callbacks_list(lua_state& L)
|
||||
lua_callbacks_list::lua_callbacks_list(lua::state& L)
|
||||
{
|
||||
objclass<lua_callbacks_list>().bind_multi(L, {
|
||||
lua::objclass<lua_callbacks_list>().bind_multi(L, {
|
||||
{"__index", &lua_callbacks_list::index},
|
||||
{"__newindex", &lua_callbacks_list::newindex},
|
||||
});
|
||||
}
|
||||
|
||||
int lua_callbacks_list::index(lua_state& L, const std::string& fname)
|
||||
int lua_callbacks_list::index(lua::state& L, const std::string& fname)
|
||||
{
|
||||
std::string name = L.get_string(2, fname.c_str());
|
||||
lua_class<lua_callback_obj>::create(L, name);
|
||||
lua::_class<lua_callback_obj>::create(L, name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_callbacks_list::newindex(lua_state& L, const std::string& fname)
|
||||
int lua_callbacks_list::newindex(lua::state& L, const std::string& fname)
|
||||
{
|
||||
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)
|
||||
{
|
||||
objclass<lua_callback_obj>().bind_multi(L, {
|
||||
lua::objclass<lua_callback_obj>().bind_multi(L, {
|
||||
{"register", &lua_callback_obj::_register},
|
||||
{"unregister", &lua_callback_obj::_unregister},
|
||||
{"__call", &lua_callback_obj::_call},
|
||||
|
@ -82,7 +82,7 @@ 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, const std::string& fname)
|
||||
{
|
||||
if(!callback)
|
||||
throw std::runtime_error("callback.{,un}register.register not valid");
|
||||
|
@ -95,7 +95,7 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
int lua_callback_obj::_unregister(lua_state& L, const std::string& fname)
|
||||
int lua_callback_obj::_unregister(lua::state& L, const std::string& fname)
|
||||
{
|
||||
if(!callback)
|
||||
throw std::runtime_error("callback.{,un}register.unregister not valid");
|
||||
|
@ -108,7 +108,7 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
int lua_callback_obj::_call(lua_state& L, const std::string& fname)
|
||||
int lua_callback_obj::_call(lua::state& L, const std::string& fname)
|
||||
{
|
||||
if(!special)
|
||||
throw std::runtime_error("Need to specify operation to do to callback");
|
||||
|
@ -133,9 +133,9 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
function_ptr_luafun callback(lua_func_callback, "callback", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr callback(lua_func_callback, "callback", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
lua_class<lua_callbacks_list>::create(L);
|
||||
lua::_class<lua_callbacks_list>::create(L);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
std::string luavalue_to_string(lua_state& L, int index, std::set<const void*>& printed, bool quote)
|
||||
std::string luavalue_to_string(lua::state& L, int index, std::set<const void*>& printed, bool quote)
|
||||
{
|
||||
switch(L.type(index)) {
|
||||
case LUA_TNONE:
|
||||
|
@ -67,7 +67,7 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
function_ptr_luafun lua_tostringx(lua_func_misc, "tostringx", [](lua_state& L, const std::string& fname) ->
|
||||
lua::fnptr lua_tostringx(lua_func_misc, "tostringx", [](lua::state& L, const std::string& fname) ->
|
||||
int {
|
||||
std::set<const void*> tmp2;
|
||||
std::string y = luavalue_to_string(L, 1, tmp2, false);
|
||||
|
@ -75,7 +75,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_print(lua_func_misc, "print2", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr lua_print(lua_func_misc, "print2", [](lua::state& L, const std::string& fname) -> int {
|
||||
int stacksize = 0;
|
||||
while(!L.isnone(stacksize + 1))
|
||||
stacksize++;
|
||||
|
@ -94,38 +94,38 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_exec(lua_func_misc, "exec", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr lua_exec(lua_func_misc, "exec", [](lua::state& L, const std::string& fname) -> int {
|
||||
std::string text = L.get_string(1, fname.c_str());
|
||||
lsnes_cmd.invoke(text);
|
||||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_booted(lua_func_misc, "emulator_ready", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr lua_booted(lua_func_misc, "emulator_ready", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
L.pushboolean(lua_booted_flag ? 1 : 0);
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_utime(lua_func_misc, "utime", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr lua_utime(lua_func_misc, "utime", [](lua::state& L, const std::string& fname) -> int {
|
||||
uint64_t t = get_utime();
|
||||
L.pushnumber(t / 1000000);
|
||||
L.pushnumber(t % 1000000);
|
||||
return 2;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_idle_time(lua_func_misc, "set_idle_timeout", [](lua_state& L,
|
||||
lua::fnptr lua_idle_time(lua_func_misc, "set_idle_timeout", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
lua_idle_hook_time = get_utime() + L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_timer_time(lua_func_misc, "set_timer_timeout", [](lua_state& L,
|
||||
lua::fnptr lua_timer_time(lua_func_misc, "set_timer_timeout", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
lua_timer_hook_time = get_utime() + L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_busaddr(lua_func_misc, "bus_address", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr lua_busaddr(lua_func_misc, "bus_address", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint64_t addr = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
auto busrange = our_rom.rtype->get_bus_map();
|
||||
|
@ -135,13 +135,13 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun mgetlagflag(lua_func_misc, "memory.get_lag_flag", [](lua_state& L,
|
||||
lua::fnptr mgetlagflag(lua_func_misc, "memory.get_lag_flag", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
L.pushboolean(!(our_rom.rtype && our_rom.rtype->get_pflag()));
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun msetlagflag(lua_func_misc, "memory.set_lag_flag", [](lua_state& L,
|
||||
lua::fnptr msetlagflag(lua_func_misc, "memory.set_lag_flag", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
if(our_rom.rtype)
|
||||
our_rom.rtype->set_pflag(!L.get_bool(1, fname.c_str()));
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_luafun memdisass(lua_func_misc, "memory.disassemble", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr memdisass(lua_func_misc, "memory.disassemble", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint64_t count = 1;
|
||||
std::string kind = L.get_string(1, fname.c_str());
|
||||
|
@ -43,7 +43,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun getreg(lua_func_misc, "memory.getregister", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr getreg(lua_func_misc, "memory.getregister", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
std::string r = L.get_string(1, fname.c_str());
|
||||
const interface_device_reg* regs = our_rom.rtype->get_registers();
|
||||
|
@ -64,7 +64,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun setreg(lua_func_misc, "memory.setregister", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr setreg(lua_func_misc, "memory.setregister", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
std::string r = L.get_string(1, fname.c_str());
|
||||
const interface_device_reg* regs = our_rom.rtype->get_registers();
|
||||
|
|
|
@ -88,7 +88,7 @@ namespace
|
|||
framebuffer::color color;
|
||||
};
|
||||
|
||||
function_ptr_luafun gui_box(lua_func_misc, "gui.arrow", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr gui_box(lua_func_misc, "gui.arrow", [](lua::state& L, const std::string& fname) -> int {
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
int32_t x = L.get_numeric_argument<int32_t>(1, fname.c_str());
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
lua_bitmap::lua_bitmap(lua_state& L, uint32_t w, uint32_t h)
|
||||
lua_bitmap::lua_bitmap(lua::state& L, uint32_t w, uint32_t h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
|
@ -29,7 +29,7 @@ std::string lua_bitmap::print()
|
|||
return (stringfmt() << width << "*" << height).str();
|
||||
}
|
||||
|
||||
lua_dbitmap::lua_dbitmap(lua_state& L, uint32_t w, uint32_t h)
|
||||
lua_dbitmap::lua_dbitmap(lua::state& L, uint32_t w, uint32_t h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
|
@ -46,7 +46,7 @@ std::string lua_dbitmap::print()
|
|||
return (stringfmt() << width << "*" << height).str();
|
||||
}
|
||||
|
||||
lua_palette::lua_palette(lua_state& L)
|
||||
lua_palette::lua_palette(lua::state& L)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -110,8 +110,8 @@ namespace
|
|||
|
||||
struct render_object_bitmap : public framebuffer::object
|
||||
{
|
||||
render_object_bitmap(int32_t _x, int32_t _y, lua_obj_pin<lua_bitmap> _bitmap,
|
||||
lua_obj_pin<lua_palette> _palette) throw()
|
||||
render_object_bitmap(int32_t _x, int32_t _y, lua::objpin<lua_bitmap> _bitmap,
|
||||
lua::objpin<lua_palette> _palette) throw()
|
||||
{
|
||||
x = _x;
|
||||
y = _y;
|
||||
|
@ -119,7 +119,7 @@ namespace
|
|||
p = _palette;
|
||||
}
|
||||
|
||||
render_object_bitmap(int32_t _x, int32_t _y, lua_obj_pin<lua_dbitmap> _bitmap) throw()
|
||||
render_object_bitmap(int32_t _x, int32_t _y, lua::objpin<lua_dbitmap> _bitmap) throw()
|
||||
{
|
||||
x = _x;
|
||||
y = _y;
|
||||
|
@ -188,39 +188,39 @@ namespace
|
|||
private:
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
lua_obj_pin<lua_bitmap> b;
|
||||
lua_obj_pin<lua_dbitmap> b2;
|
||||
lua_obj_pin<lua_palette> p;
|
||||
lua::objpin<lua_bitmap> b;
|
||||
lua::objpin<lua_dbitmap> b2;
|
||||
lua::objpin<lua_palette> p;
|
||||
};
|
||||
|
||||
function_ptr_luafun gui_bitmap(lua_func_misc, "gui.bitmap_draw", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_bitmap(lua_func_misc, "gui.bitmap_draw", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
int32_t x = L.get_numeric_argument<int32_t>(1, fname.c_str());
|
||||
int32_t y = L.get_numeric_argument<int32_t>(2, fname.c_str());
|
||||
if(lua_class<lua_bitmap>::is(L, 3)) {
|
||||
lua_class<lua_bitmap>::get(L, 3, fname.c_str());
|
||||
lua_class<lua_palette>::get(L, 4, fname.c_str());
|
||||
auto b = lua_class<lua_bitmap>::pin(L, 3, fname.c_str());
|
||||
auto p = lua_class<lua_palette>::pin(L, 4, fname.c_str());
|
||||
if(lua::_class<lua_bitmap>::is(L, 3)) {
|
||||
lua::_class<lua_bitmap>::get(L, 3, fname.c_str());
|
||||
lua::_class<lua_palette>::get(L, 4, fname.c_str());
|
||||
auto b = lua::_class<lua_bitmap>::pin(L, 3, fname.c_str());
|
||||
auto p = lua::_class<lua_palette>::pin(L, 4, fname.c_str());
|
||||
lua_render_ctx->queue->create_add<render_object_bitmap>(x, y, b, p);
|
||||
} else if(lua_class<lua_dbitmap>::is(L, 3)) {
|
||||
lua_class<lua_dbitmap>::get(L, 3, fname.c_str());
|
||||
auto b = lua_class<lua_dbitmap>::pin(L, 3, fname.c_str());
|
||||
} else if(lua::_class<lua_dbitmap>::is(L, 3)) {
|
||||
lua::_class<lua_dbitmap>::get(L, 3, fname.c_str());
|
||||
auto b = lua::_class<lua_dbitmap>::pin(L, 3, fname.c_str());
|
||||
lua_render_ctx->queue->create_add<render_object_bitmap>(x, y, b);
|
||||
} else
|
||||
throw std::runtime_error("Expected BITMAP or DBITMAP as argument 3 for gui.bitmap_draw.");
|
||||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_cpalette(lua_func_misc, "gui.palette_new", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_cpalette(lua_func_misc, "gui.palette_new", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
lua_class<lua_palette>::create(L);
|
||||
lua::_class<lua_palette>::create(L);
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_cbitmap(lua_func_misc, "gui.bitmap_new", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_cbitmap(lua_func_misc, "gui.bitmap_new", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint32_t w = L.get_numeric_argument<uint32_t>(1, fname.c_str());
|
||||
uint32_t h = L.get_numeric_argument<uint32_t>(2, fname.c_str());
|
||||
|
@ -228,22 +228,22 @@ namespace
|
|||
if(d) {
|
||||
int64_t c = -1;
|
||||
L.get_numeric_argument<int64_t>(4, c, fname.c_str());
|
||||
lua_dbitmap* b = lua_class<lua_dbitmap>::create(L, w, h);
|
||||
lua_dbitmap* b = lua::_class<lua_dbitmap>::create(L, w, h);
|
||||
for(size_t i = 0; i < b->width * b->height; i++)
|
||||
b->pixels[i] = framebuffer::color(c);
|
||||
} else {
|
||||
uint16_t c = 0;
|
||||
L.get_numeric_argument<uint16_t>(4, c, fname.c_str());
|
||||
lua_bitmap* b = lua_class<lua_bitmap>::create(L, w, h);
|
||||
lua_bitmap* b = lua::_class<lua_bitmap>::create(L, w, h);
|
||||
for(size_t i = 0; i < b->width * b->height; i++)
|
||||
b->pixels[i] = c;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_epalette(lua_func_misc, "gui.palette_set", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_epalette(lua_func_misc, "gui.palette_set", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
lua_palette* p = lua_class<lua_palette>::get(L, 1, fname.c_str());
|
||||
lua_palette* p = lua::_class<lua_palette>::get(L, 1, fname.c_str());
|
||||
uint16_t c = L.get_numeric_argument<uint16_t>(2, fname.c_str());
|
||||
int64_t nval = L.get_numeric_argument<int64_t>(3, fname.c_str());
|
||||
framebuffer::color nc(nval);
|
||||
|
@ -257,18 +257,18 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun pset_bitmap(lua_func_misc, "gui.bitmap_pset", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr pset_bitmap(lua_func_misc, "gui.bitmap_pset", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint32_t x = L.get_numeric_argument<uint32_t>(2, fname.c_str());
|
||||
uint32_t y = L.get_numeric_argument<uint32_t>(3, fname.c_str());
|
||||
if(lua_class<lua_bitmap>::is(L, 1)) {
|
||||
lua_bitmap* b = lua_class<lua_bitmap>::get(L, 1, fname.c_str());
|
||||
if(lua::_class<lua_bitmap>::is(L, 1)) {
|
||||
lua_bitmap* b = lua::_class<lua_bitmap>::get(L, 1, fname.c_str());
|
||||
uint16_t c = L.get_numeric_argument<uint16_t>(4, fname.c_str());
|
||||
if(x >= b->width || y >= b->height)
|
||||
return 0;
|
||||
b->pixels[y * b->width + x] = c;
|
||||
} else if(lua_class<lua_dbitmap>::is(L, 1)) {
|
||||
lua_dbitmap* b = lua_class<lua_dbitmap>::get(L, 1, fname.c_str());
|
||||
} else if(lua::_class<lua_dbitmap>::is(L, 1)) {
|
||||
lua_dbitmap* b = lua::_class<lua_dbitmap>::get(L, 1, fname.c_str());
|
||||
int64_t c = L.get_numeric_argument<int64_t>(4, fname.c_str());
|
||||
if(x >= b->width || y >= b->height)
|
||||
return 0;
|
||||
|
@ -286,17 +286,17 @@ namespace
|
|||
return c.orig | ((uint32_t)(256 - c.origa) << 24);
|
||||
}
|
||||
|
||||
function_ptr_luafun pget_bitmap(lua_func_misc, "gui.bitmap_pget", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr pget_bitmap(lua_func_misc, "gui.bitmap_pget", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint32_t x = L.get_numeric_argument<uint32_t>(2, fname.c_str());
|
||||
uint32_t y = L.get_numeric_argument<uint32_t>(3, fname.c_str());
|
||||
if(lua_class<lua_bitmap>::is(L, 1)) {
|
||||
lua_bitmap* b = lua_class<lua_bitmap>::get(L, 1, fname.c_str());
|
||||
if(lua::_class<lua_bitmap>::is(L, 1)) {
|
||||
lua_bitmap* b = lua::_class<lua_bitmap>::get(L, 1, fname.c_str());
|
||||
if(x >= b->width || y >= b->height)
|
||||
return 0;
|
||||
L.pushnumber(b->pixels[y * b->width + x]);
|
||||
} else if(lua_class<lua_dbitmap>::is(L, 1)) {
|
||||
lua_dbitmap* b = lua_class<lua_dbitmap>::get(L, 1, fname.c_str());
|
||||
} else if(lua::_class<lua_dbitmap>::is(L, 1)) {
|
||||
lua_dbitmap* b = lua::_class<lua_dbitmap>::get(L, 1, fname.c_str());
|
||||
if(x >= b->width || y >= b->height)
|
||||
return 0;
|
||||
L.pushnumber(demultiply_color(b->pixels[y * b->width + x]));
|
||||
|
@ -305,14 +305,14 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun size_bitmap(lua_func_misc, "gui.bitmap_size", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr size_bitmap(lua_func_misc, "gui.bitmap_size", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
if(lua_class<lua_bitmap>::is(L, 1)) {
|
||||
lua_bitmap* b = lua_class<lua_bitmap>::get(L, 1, fname.c_str());
|
||||
if(lua::_class<lua_bitmap>::is(L, 1)) {
|
||||
lua_bitmap* b = lua::_class<lua_bitmap>::get(L, 1, fname.c_str());
|
||||
L.pushnumber(b->width);
|
||||
L.pushnumber(b->height);
|
||||
} else if(lua_class<lua_dbitmap>::is(L, 1)) {
|
||||
lua_dbitmap* b = lua_class<lua_dbitmap>::get(L, 1, fname.c_str());
|
||||
} else if(lua::_class<lua_dbitmap>::is(L, 1)) {
|
||||
lua_dbitmap* b = lua::_class<lua_dbitmap>::get(L, 1, fname.c_str());
|
||||
L.pushnumber(b->width);
|
||||
L.pushnumber(b->height);
|
||||
} else
|
||||
|
@ -320,15 +320,15 @@ namespace
|
|||
return 2;
|
||||
});
|
||||
|
||||
function_ptr_luafun hash_bitmap(lua_func_misc, "gui.bitmap_hash", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr hash_bitmap(lua_func_misc, "gui.bitmap_hash", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
sha256 h;
|
||||
const int buffersize = 256;
|
||||
int bufferuse = 0;
|
||||
char buf[buffersize];
|
||||
memset(buf, 0, buffersize);
|
||||
if(lua_class<lua_bitmap>::is(L, 1)) {
|
||||
lua_bitmap* b = lua_class<lua_bitmap>::get(L, 1, fname.c_str());
|
||||
if(lua::_class<lua_bitmap>::is(L, 1)) {
|
||||
lua_bitmap* b = lua::_class<lua_bitmap>::get(L, 1, fname.c_str());
|
||||
serialization::u64b(buf + 0, b->width);
|
||||
serialization::u64b(buf + 8, b->height);
|
||||
bufferuse = 16;
|
||||
|
@ -343,8 +343,8 @@ namespace
|
|||
if(bufferuse > 0) h.write(buf, bufferuse);
|
||||
L.pushlstring(h.read());
|
||||
return 1;
|
||||
} else if(lua_class<lua_dbitmap>::is(L, 1)) {
|
||||
lua_dbitmap* b = lua_class<lua_dbitmap>::get(L, 1, fname.c_str());
|
||||
} else if(lua::_class<lua_dbitmap>::is(L, 1)) {
|
||||
lua_dbitmap* b = lua::_class<lua_dbitmap>::get(L, 1, fname.c_str());
|
||||
serialization::u64b(buf + 0, b->width);
|
||||
serialization::u64b(buf + 4, b->height);
|
||||
bufferuse = 16;
|
||||
|
@ -364,9 +364,9 @@ namespace
|
|||
throw std::runtime_error("Expected BITMAP or DBITMAP as argument 1 for gui.bitmap_hash.");
|
||||
});
|
||||
|
||||
function_ptr_luafun hash_palette(lua_func_misc, "gui.palette_hash", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr hash_palette(lua_func_misc, "gui.palette_hash", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
lua_palette* p = lua_class<lua_palette>::get(L, 1, fname.c_str());
|
||||
lua_palette* p = lua::_class<lua_palette>::get(L, 1, fname.c_str());
|
||||
sha256 h;
|
||||
const int buffersize = 256;
|
||||
int bufferuse = 0;
|
||||
|
@ -517,19 +517,19 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
function_ptr_luafun blit_bitmap(lua_func_misc, "gui.bitmap_blit", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr blit_bitmap(lua_func_misc, "gui.bitmap_blit", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
int slot = 1;
|
||||
int dsts = 0;
|
||||
int srcs = 0;
|
||||
bool dst_d = lua_class<lua_dbitmap>::is(L, dsts = slot);
|
||||
bool dst_p = lua_class<lua_bitmap>::is(L, slot++);
|
||||
bool dst_d = lua::_class<lua_dbitmap>::is(L, dsts = slot);
|
||||
bool dst_p = lua::_class<lua_bitmap>::is(L, slot++);
|
||||
if(!dst_d && !dst_p)
|
||||
throw std::runtime_error("Expected BITMAP or DBITMAP as argument 1 for gui.bitmap_blit");
|
||||
uint32_t dx = L.get_numeric_argument<uint32_t>(slot++, fname.c_str());
|
||||
uint32_t dy = L.get_numeric_argument<uint32_t>(slot++, fname.c_str());
|
||||
bool src_d = lua_class<lua_dbitmap>::is(L, srcs = slot);
|
||||
bool src_p = lua_class<lua_bitmap>::is(L, slot++);
|
||||
bool src_d = lua::_class<lua_dbitmap>::is(L, srcs = slot);
|
||||
bool src_p = lua::_class<lua_bitmap>::is(L, slot++);
|
||||
if(!src_d && !src_p)
|
||||
throw std::runtime_error("Expected BITMAP or DBITMAP as argument 4 for gui.bitmap_blit");
|
||||
if(dst_d && src_p)
|
||||
|
@ -542,25 +542,25 @@ namespace
|
|||
L.get_numeric_argument<int64_t>(slot++, ck, fname.c_str());
|
||||
|
||||
if(dst_d && src_d) {
|
||||
lua_dbitmap* db = lua_class<lua_dbitmap>::get(L, dsts, fname.c_str());
|
||||
lua_dbitmap* sb = lua_class<lua_dbitmap>::get(L, srcs, fname.c_str());
|
||||
lua_dbitmap* db = lua::_class<lua_dbitmap>::get(L, dsts, fname.c_str());
|
||||
lua_dbitmap* sb = lua::_class<lua_dbitmap>::get(L, srcs, fname.c_str());
|
||||
if(ck == 0x100000000ULL)
|
||||
blit(srcdest_direct<colorkey_none>(*db, *sb, colorkey_none()), dx, dy, sx, sy, w, h);
|
||||
else
|
||||
blit(srcdest_direct<colorkey_direct>(*db, *sb, colorkey_direct(ck)), dx, dy, sx, sy, w,
|
||||
h);
|
||||
blit(srcdest_direct<colorkey_direct>(*db, *sb, colorkey_direct(ck)), dx, dy, sx, sy,
|
||||
w, h);
|
||||
} else if(dst_p && src_p) {
|
||||
lua_bitmap* db = lua_class<lua_bitmap>::get(L, dsts, fname.c_str());
|
||||
lua_bitmap* sb = lua_class<lua_bitmap>::get(L, srcs, fname.c_str());
|
||||
lua_bitmap* db = lua::_class<lua_bitmap>::get(L, dsts, fname.c_str());
|
||||
lua_bitmap* sb = lua::_class<lua_bitmap>::get(L, srcs, fname.c_str());
|
||||
if(ck > 65535)
|
||||
blit(srcdest_palette<colorkey_none>(*db, *sb, colorkey_none()), dx, dy, sx, sy, w, h);
|
||||
else
|
||||
blit(srcdest_palette<colorkey_palette>(*db, *sb, colorkey_palette(ck)), dx, dy, sx, sy,
|
||||
w, h);
|
||||
blit(srcdest_palette<colorkey_palette>(*db, *sb, colorkey_palette(ck)), dx, dy, sx,
|
||||
sy, w, h);
|
||||
} else if(dst_d && src_p) {
|
||||
lua_dbitmap* db = lua_class<lua_dbitmap>::get(L, dsts, fname.c_str());
|
||||
lua_bitmap* sb = lua_class<lua_bitmap>::get(L, srcs, fname.c_str());
|
||||
lua_palette* pal = lua_class<lua_palette>::get(L, srcs + 1, fname.c_str());
|
||||
lua_dbitmap* db = lua::_class<lua_dbitmap>::get(L, dsts, fname.c_str());
|
||||
lua_bitmap* sb = lua::_class<lua_bitmap>::get(L, srcs, fname.c_str());
|
||||
lua_palette* pal = lua::_class<lua_palette>::get(L, srcs + 1, fname.c_str());
|
||||
if(ck > 65535)
|
||||
blit(srcdest_paletted<colorkey_none>(*db, *sb, *pal, colorkey_none()), dx, dy, sx, sy,
|
||||
w, h);
|
||||
|
@ -573,18 +573,18 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
int bitmap_load_fn(lua_state& L, std::function<lua_loaded_bitmap()> src)
|
||||
int bitmap_load_fn(lua::state& L, std::function<lua_loaded_bitmap()> src)
|
||||
{
|
||||
uint32_t w, h;
|
||||
auto bitmap = src();
|
||||
if(bitmap.d) {
|
||||
lua_dbitmap* b = lua_class<lua_dbitmap>::create(L, bitmap.w, bitmap.h);
|
||||
lua_dbitmap* b = lua::_class<lua_dbitmap>::create(L, bitmap.w, bitmap.h);
|
||||
for(size_t i = 0; i < bitmap.w * bitmap.h; i++)
|
||||
b->pixels[i] = framebuffer::color(bitmap.bitmap[i]);
|
||||
return 1;
|
||||
} else {
|
||||
lua_bitmap* b = lua_class<lua_bitmap>::create(L, bitmap.w, bitmap.h);
|
||||
lua_palette* p = lua_class<lua_palette>::create(L);
|
||||
lua_bitmap* b = lua::_class<lua_bitmap>::create(L, bitmap.w, bitmap.h);
|
||||
lua_palette* p = lua::_class<lua_palette>::create(L);
|
||||
for(size_t i = 0; i < bitmap.w * bitmap.h; i++)
|
||||
b->pixels[i] = bitmap.bitmap[i];
|
||||
p->colors.resize(bitmap.palette.size());
|
||||
|
@ -594,7 +594,7 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
function_ptr_luafun gui_loadbitmap(lua_func_misc, "gui.bitmap_load", [](lua_state& L,
|
||||
lua::fnptr gui_loadbitmap(lua_func_misc, "gui.bitmap_load", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
std::string name2;
|
||||
std::string name = L.get_string(1, fname.c_str());
|
||||
|
@ -606,7 +606,7 @@ namespace
|
|||
});
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_loadbitmap2(lua_func_misc, "gui.bitmap_load_str", [](lua_state& L,
|
||||
lua::fnptr gui_loadbitmap2(lua_func_misc, "gui.bitmap_load_str", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
std::string contents = L.get_string(1, fname.c_str());
|
||||
return bitmap_load_fn(L, [&contents]() -> lua_loaded_bitmap {
|
||||
|
@ -713,12 +713,12 @@ namespace
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
int bitmap_load_png_fn(lua_state& L, T& src)
|
||||
int bitmap_load_png_fn(lua::state& L, T& src)
|
||||
{
|
||||
png_decoded_image img(src);
|
||||
if(img.has_palette) {
|
||||
lua_bitmap* b = lua_class<lua_bitmap>::create(L, img.width, img.height);
|
||||
lua_palette* p = lua_class<lua_palette>::create(L);
|
||||
lua_bitmap* b = lua::_class<lua_bitmap>::create(L, img.width, img.height);
|
||||
lua_palette* p = lua::_class<lua_palette>::create(L);
|
||||
for(size_t i = 0; i < img.width * img.height; i++)
|
||||
b->pixels[i] = img.data[i];
|
||||
p->colors.resize(img.palette.size());
|
||||
|
@ -726,23 +726,23 @@ namespace
|
|||
p->colors[i] = framebuffer::color(mangle_color(img.palette[i]));
|
||||
return 2;
|
||||
} else {
|
||||
lua_dbitmap* b = lua_class<lua_dbitmap>::create(L, img.width, img.height);
|
||||
lua_dbitmap* b = lua::_class<lua_dbitmap>::create(L, img.width, img.height);
|
||||
for(size_t i = 0; i < img.width * img.height; i++)
|
||||
b->pixels[i] = framebuffer::color(mangle_color(img.data[i]));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void bitmap_save_png_fn(lua_state& L, std::function<void(const std::vector<char>& buf)> fn, int index,
|
||||
void bitmap_save_png_fn(lua::state& L, std::function<void(const std::vector<char>& buf)> fn, int index,
|
||||
const std::string& fname)
|
||||
{
|
||||
std::vector<char> buf;
|
||||
if(lua_class<lua_bitmap>::is(L, index)) {
|
||||
lua_bitmap* b = lua_class<lua_bitmap>::get(L, index, fname.c_str());
|
||||
lua_palette* p = lua_class<lua_palette>::get(L, index + 1, fname.c_str());
|
||||
if(lua::_class<lua_bitmap>::is(L, index)) {
|
||||
lua_bitmap* b = lua::_class<lua_bitmap>::get(L, index, fname.c_str());
|
||||
lua_palette* p = lua::_class<lua_palette>::get(L, index + 1, fname.c_str());
|
||||
buf = b->save_png(*p);
|
||||
} else if(lua_class<lua_dbitmap>::is(L, index)) {
|
||||
lua_dbitmap* b = lua_class<lua_dbitmap>::get(L, index, fname.c_str());
|
||||
} else if(lua::_class<lua_dbitmap>::is(L, index)) {
|
||||
lua_dbitmap* b = lua::_class<lua_dbitmap>::get(L, index, fname.c_str());
|
||||
buf = b->save_png();
|
||||
} else
|
||||
(stringfmt() << "Expected BITMAP or DBITMAP as argument " << index
|
||||
|
@ -751,7 +751,7 @@ namespace
|
|||
}
|
||||
|
||||
|
||||
function_ptr_luafun gui_loadbitmappng(lua_func_misc, "gui.bitmap_load_png", [](lua_state& L,
|
||||
lua::fnptr gui_loadbitmappng(lua_func_misc, "gui.bitmap_load_png", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
std::string name2;
|
||||
std::string name = L.get_string(1, fname.c_str());
|
||||
|
@ -761,14 +761,14 @@ namespace
|
|||
return bitmap_load_png_fn(L, filename);
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_loadbitmappng2(lua_func_misc, "gui.bitmap_load_png_str", [](lua_state& L,
|
||||
lua::fnptr gui_loadbitmappng2(lua_func_misc, "gui.bitmap_load_png_str", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
std::string contents = base64_decode(L.get_string(1, fname.c_str()));
|
||||
std::istringstream strm(contents);
|
||||
return bitmap_load_png_fn(L, strm);
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_savebitmappng(lua_func_misc, "gui.bitmap_save_png", [](lua_state& L,
|
||||
lua::fnptr gui_savebitmappng(lua_func_misc, "gui.bitmap_save_png", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
int index = 1;
|
||||
std::string name, name2;
|
||||
|
@ -799,9 +799,9 @@ namespace
|
|||
}
|
||||
});
|
||||
|
||||
int bitmap_palette_fn(lua_state& L, std::istream& s)
|
||||
int bitmap_palette_fn(lua::state& L, std::istream& s)
|
||||
{
|
||||
lua_palette* p = lua_class<lua_palette>::create(L);
|
||||
lua_palette* p = lua::_class<lua_palette>::create(L);
|
||||
while(s) {
|
||||
std::string line;
|
||||
std::getline(s, line);
|
||||
|
@ -833,7 +833,7 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
function_ptr_luafun gui_loadpalette(lua_func_misc, "gui.bitmap_load_pal", [](lua_state& L,
|
||||
lua::fnptr gui_loadpalette(lua_func_misc, "gui.bitmap_load_pal", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
std::string name2;
|
||||
std::string name = L.get_string(1, fname.c_str());
|
||||
|
@ -850,16 +850,16 @@ namespace
|
|||
}
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_loadpalette2(lua_func_misc, "gui.bitmap_load_pal_str", [](lua_state& L,
|
||||
lua::fnptr gui_loadpalette2(lua_func_misc, "gui.bitmap_load_pal_str", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
std::string content = L.get_string(1, fname.c_str());
|
||||
std::istringstream s(content);
|
||||
return bitmap_palette_fn(L, s);
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_dpalette(lua_func_misc, "gui.palette_debug", [](lua_state& L,
|
||||
lua::fnptr gui_dpalette(lua_func_misc, "gui.palette_debug", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
lua_palette* p = lua_class<lua_palette>::get(L, 1, fname.c_str());
|
||||
lua_palette* p = lua::_class<lua_palette>::get(L, 1, fname.c_str());
|
||||
size_t i = 0;
|
||||
for(auto c : p->colors)
|
||||
messages << "Color #" << (i++) << ": " << c.orig << ":" << c.origa << std::endl;
|
||||
|
@ -879,15 +879,15 @@ namespace
|
|||
return framebuffer::color(rgb | ((uint32_t)(256 - a) << 24));
|
||||
}
|
||||
|
||||
function_ptr_luafun adjust_trans(lua_func_misc, "gui.adjust_transparency", [](lua_state& L,
|
||||
lua::fnptr adjust_trans(lua_func_misc, "gui.adjust_transparency", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
uint16_t tadj = L.get_numeric_argument<uint16_t>(2, fname.c_str());
|
||||
if(lua_class<lua_dbitmap>::is(L, 1)) {
|
||||
lua_dbitmap* b = lua_class<lua_dbitmap>::get(L, 1, fname.c_str());
|
||||
if(lua::_class<lua_dbitmap>::is(L, 1)) {
|
||||
lua_dbitmap* b = lua::_class<lua_dbitmap>::get(L, 1, fname.c_str());
|
||||
for(auto& c : b->pixels)
|
||||
c = tadjust(c, tadj);
|
||||
} else if(lua_class<lua_palette>::is(L, 1)) {
|
||||
lua_palette* p = lua_class<lua_palette>::get(L, 1, fname.c_str());
|
||||
} else if(lua::_class<lua_palette>::is(L, 1)) {
|
||||
lua_palette* p = lua::_class<lua_palette>::get(L, 1, fname.c_str());
|
||||
for(auto& c : p->colors)
|
||||
c = tadjust(c, tadj);
|
||||
} else {
|
||||
|
@ -897,7 +897,7 @@ namespace
|
|||
return 2;
|
||||
});
|
||||
|
||||
lua_class<lua_palette> class_palette("PALETTE");
|
||||
lua_class<lua_bitmap> class_bitmap("BITMAP");
|
||||
lua_class<lua_dbitmap> class_dbitmap("DBITMAP");
|
||||
lua::_class<lua_palette> class_palette("PALETTE");
|
||||
lua::_class<lua_bitmap> class_bitmap("BITMAP");
|
||||
lua::_class<lua_dbitmap> class_dbitmap("DBITMAP");
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace
|
|||
int32_t thickness;
|
||||
};
|
||||
|
||||
function_ptr_luafun gui_box(lua_func_misc, "gui.box", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr gui_box(lua_func_misc, "gui.box", [](lua::state& L, const std::string& fname) -> int {
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
int64_t outline1 = 0xFFFFFFU;
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace
|
|||
framebuffer::color fill;
|
||||
};
|
||||
|
||||
function_ptr_luafun gui_rectangle(lua_func_misc, "gui.circle", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_rectangle(lua_func_misc, "gui.circle", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
class lua_gui_resolution : public lua_function
|
||||
class lua_gui_resolution : public lua::function
|
||||
{
|
||||
public:
|
||||
lua_gui_resolution() : lua_function(lua_func_misc, "gui.resolution") {}
|
||||
int invoke(lua_state& L)
|
||||
lua_gui_resolution() : lua::function(lua_func_misc, "gui.resolution") {}
|
||||
int invoke(lua::state& L)
|
||||
{
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
|
@ -19,11 +19,11 @@ namespace
|
|||
} gui_resolution;
|
||||
|
||||
template<uint32_t lua_render_context::*gap, bool delta>
|
||||
class lua_gui_set_gap : public lua_function
|
||||
class lua_gui_set_gap : public lua::function
|
||||
{
|
||||
public:
|
||||
lua_gui_set_gap(const std::string& name) : lua_function(lua_func_misc, name) {}
|
||||
int invoke(lua_state& L)
|
||||
lua_gui_set_gap(const std::string& name) : lua::function(lua_func_misc, name) {}
|
||||
int invoke(lua::state& L)
|
||||
{
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
|
@ -47,19 +47,19 @@ namespace
|
|||
lua_gui_set_gap<&lua_render_context::top_gap, true> dtg("gui.delta_top_gap");
|
||||
lua_gui_set_gap<&lua_render_context::bottom_gap, true> dbg("gui.delta_bottom_gap");
|
||||
|
||||
function_ptr_luafun gui_repaint(lua_func_misc, "gui.repaint", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_repaint(lua_func_misc, "gui.repaint", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
lua_requests_repaint = true;
|
||||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_sfupd(lua_func_misc, "gui.subframe_update", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_sfupd(lua_func_misc, "gui.subframe_update", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
lua_requests_subframe_paint = L.get_bool(1, fname.c_str());
|
||||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_color(lua_func_misc, "gui.color", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_color(lua_func_misc, "gui.color", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
int64_t a = 256;
|
||||
int64_t r = L.get_numeric_argument<uint32_t>(1, fname.c_str());
|
||||
|
@ -73,7 +73,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_status(lua_func_misc, "gui.status", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_status(lua_func_misc, "gui.status", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
std::string name = L.get_string(1, fname.c_str());
|
||||
std::string value = L.get_string(2, fname.c_str());
|
||||
|
@ -119,7 +119,7 @@ namespace
|
|||
return (V[(flag >> 4) & 3] << 16) | (V[(flag >> 2) & 3] << 8) | (V[flag & 3]);
|
||||
}
|
||||
|
||||
function_ptr_luafun gui_rainbow(lua_func_misc, "gui.rainbow", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_rainbow(lua_func_misc, "gui.rainbow", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
int64_t basecolor = 0x00FF0000;
|
||||
uint64_t step = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
|
@ -141,7 +141,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_killframe(lua_func_misc, "gui.kill_frame", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_killframe(lua_func_misc, "gui.kill_frame", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
if(lua_kill_frame)
|
||||
*lua_kill_frame = true;
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace
|
|||
uint32_t length;
|
||||
};
|
||||
|
||||
function_ptr_luafun gui_crosshair(lua_func_misc, "gui.crosshair", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_crosshair(lua_func_misc, "gui.crosshair", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
|
|
|
@ -89,7 +89,7 @@ nodraw2:
|
|||
framebuffer::color color;
|
||||
};
|
||||
|
||||
function_ptr_luafun gui_pixel(lua_func_misc, "gui.line", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr gui_pixel(lua_func_misc, "gui.line", [](lua::state& L, const std::string& fname) -> int {
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
int64_t color = 0xFFFFFFU;
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace
|
|||
framebuffer::color color;
|
||||
};
|
||||
|
||||
function_ptr_luafun gui_pixel(lua_func_misc, "gui.pixel", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr gui_pixel(lua_func_misc, "gui.pixel", [](lua::state& L, const std::string& fname) -> int {
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
int64_t color = 0xFFFFFFU;
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace
|
|||
int32_t thickness;
|
||||
};
|
||||
|
||||
function_ptr_luafun gui_rectangle(lua_func_misc, "gui.rectangle", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_rectangle(lua_func_misc, "gui.rectangle", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace
|
|||
|
||||
struct render_queue_obj
|
||||
{
|
||||
render_queue_obj(lua_state& L, 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.right_gap = std::numeric_limits<uint32_t>::max();
|
||||
|
@ -32,13 +32,13 @@ namespace
|
|||
lua_render_context lctx;
|
||||
};
|
||||
|
||||
function_ptr_luafun gui_rq_run(lua_func_misc, "gui.renderq_run", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_rq_run(lua_func_misc, "gui.renderq_run", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
if(lua_class<render_queue_obj>::is(L, 1)) {
|
||||
lua_class<render_queue_obj>::get(L, 1, fname.c_str());
|
||||
auto q = lua_class<render_queue_obj>::pin(L, 1, fname.c_str());
|
||||
if(lua::_class<render_queue_obj>::is(L, 1)) {
|
||||
lua::_class<render_queue_obj>::get(L, 1, fname.c_str());
|
||||
auto q = lua::_class<render_queue_obj>::pin(L, 1, fname.c_str());
|
||||
lua_render_context* ptr = q->get();
|
||||
if(ptr->top_gap != std::numeric_limits<uint32_t>::max())
|
||||
lua_render_ctx->top_gap = ptr->top_gap;
|
||||
|
@ -54,11 +54,11 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_srepaint(lua_func_misc, "gui.synchronous_repaint", [](lua_state& L,
|
||||
lua::fnptr gui_srepaint(lua_func_misc, "gui.synchronous_repaint", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
if(lua_class<render_queue_obj>::is(L, 1)) {
|
||||
lua_class<render_queue_obj>::get(L, 1, fname.c_str());
|
||||
auto q = lua_class<render_queue_obj>::pin(L, 1, fname.c_str());
|
||||
if(lua::_class<render_queue_obj>::is(L, 1)) {
|
||||
lua::_class<render_queue_obj>::get(L, 1, fname.c_str());
|
||||
auto q = lua::_class<render_queue_obj>::pin(L, 1, fname.c_str());
|
||||
synchronous_paint_ctx = &*q;
|
||||
redraw_framebuffer();
|
||||
} else
|
||||
|
@ -66,11 +66,11 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_rq_clear(lua_func_misc, "gui.renderq_clear", [](lua_state& L,
|
||||
lua::fnptr gui_rq_clear(lua_func_misc, "gui.renderq_clear", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
if(lua_class<render_queue_obj>::is(L, 1)) {
|
||||
lua_class<render_queue_obj>::get(L, 1, fname.c_str());
|
||||
auto q = lua_class<render_queue_obj>::pin(L, 1, fname.c_str());
|
||||
if(lua::_class<render_queue_obj>::is(L, 1)) {
|
||||
lua::_class<render_queue_obj>::get(L, 1, fname.c_str());
|
||||
auto q = lua::_class<render_queue_obj>::pin(L, 1, fname.c_str());
|
||||
lua_render_context* ptr = q->get();
|
||||
ptr->top_gap = std::numeric_limits<uint32_t>::max();
|
||||
ptr->right_gap = std::numeric_limits<uint32_t>::max();
|
||||
|
@ -82,19 +82,19 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_rq_new(lua_func_misc, "gui.renderq_new", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_rq_new(lua_func_misc, "gui.renderq_new", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
int32_t x = L.get_numeric_argument<int32_t>(1, fname.c_str());
|
||||
int32_t y = L.get_numeric_argument<int32_t>(2, fname.c_str());
|
||||
lua_class<render_queue_obj>::create(L, x, y);
|
||||
lua::_class<render_queue_obj>::create(L, x, y);
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_rq_set(lua_func_misc, "gui.renderq_set", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_rq_set(lua_func_misc, "gui.renderq_set", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
if(lua_class<render_queue_obj>::is(L, 1)) {
|
||||
lua_class<render_queue_obj>::get(L, 1, fname.c_str());
|
||||
auto q = lua_class<render_queue_obj>::pin(L, 1, fname.c_str());
|
||||
if(lua::_class<render_queue_obj>::is(L, 1)) {
|
||||
lua::_class<render_queue_obj>::get(L, 1, fname.c_str());
|
||||
auto q = lua::_class<render_queue_obj>::pin(L, 1, fname.c_str());
|
||||
lua_render_context* ptr = q->get();
|
||||
if(!redirect || last != lua_render_ctx)
|
||||
saved = lua_render_ctx;
|
||||
|
@ -112,7 +112,7 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
lua_class<render_queue_obj> class_render_queue_obj("RENDERCTX");
|
||||
lua::_class<render_queue_obj> class_render_queue_obj("RENDERCTX");
|
||||
}
|
||||
|
||||
void lua_renderq_run(lua_render_context* ctx, void* _sctx)
|
||||
|
|
|
@ -12,27 +12,27 @@ namespace
|
|||
struct lua_customfont
|
||||
{
|
||||
public:
|
||||
lua_customfont(lua_state& L, const std::string& filename);
|
||||
lua_customfont(lua_state& L);
|
||||
lua_customfont(lua::state& L, const std::string& filename);
|
||||
lua_customfont(lua::state& L);
|
||||
~lua_customfont() throw();
|
||||
int draw(lua_state& L, const std::string& fname);
|
||||
int draw(lua::state& L, const std::string& fname);
|
||||
const framebuffer::font2& get_font() { return font; }
|
||||
std::string print()
|
||||
{
|
||||
return orig_filename;
|
||||
}
|
||||
private:
|
||||
void init(lua_state& L);
|
||||
void init(lua::state& L);
|
||||
std::string orig_filename;
|
||||
framebuffer::font2 font;
|
||||
};
|
||||
|
||||
lua_class<lua_customfont> class_customfont("CUSTOMFONT");
|
||||
lua::_class<lua_customfont> class_customfont("CUSTOMFONT");
|
||||
|
||||
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,
|
||||
framebuffer::color _bg, framebuffer::color _hl, lua_obj_pin<lua_customfont> _font) throw()
|
||||
framebuffer::color _bg, framebuffer::color _hl, lua::objpin<lua_customfont> _font) throw()
|
||||
: x(_x), y(_y), text(_text), fg(_fg), bg(_bg), hl(_hl), font(_font) {}
|
||||
~render_object_text_cf() throw()
|
||||
{
|
||||
|
@ -86,24 +86,24 @@ namespace
|
|||
framebuffer::color fg;
|
||||
framebuffer::color bg;
|
||||
framebuffer::color hl;
|
||||
lua_obj_pin<lua_customfont> font;
|
||||
lua::objpin<lua_customfont> font;
|
||||
};
|
||||
|
||||
void lua_customfont::init(lua_state& L)
|
||||
void lua_customfont::init(lua::state& L)
|
||||
{
|
||||
objclass<lua_customfont>().bind_multi(L, {
|
||||
lua::objclass<lua_customfont>().bind_multi(L, {
|
||||
{"__call", &lua_customfont::draw},
|
||||
});
|
||||
}
|
||||
|
||||
lua_customfont::lua_customfont(lua_state& L, const std::string& filename)
|
||||
lua_customfont::lua_customfont(lua::state& L, const std::string& filename)
|
||||
: font(filename)
|
||||
{
|
||||
orig_filename = filename;
|
||||
init(L);
|
||||
}
|
||||
|
||||
lua_customfont::lua_customfont(lua_state& L)
|
||||
lua_customfont::lua_customfont(lua::state& L)
|
||||
: font(main_font)
|
||||
{
|
||||
orig_filename = "<builtin>";
|
||||
|
@ -115,7 +115,7 @@ namespace
|
|||
render_kill_request(this);
|
||||
}
|
||||
|
||||
int lua_customfont::draw(lua_state& L, const std::string& fname)
|
||||
int lua_customfont::draw(lua::state& L, const std::string& fname)
|
||||
{
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
|
@ -128,7 +128,7 @@ namespace
|
|||
L.get_numeric_argument<int64_t>(6, bgc, fname.c_str());
|
||||
L.get_numeric_argument<int64_t>(7, hlc, fname.c_str());
|
||||
std::string text = L.get_string(4, fname.c_str());
|
||||
auto f = lua_class<lua_customfont>::pin(L, 1, fname.c_str());
|
||||
auto f = lua::_class<lua_customfont>::pin(L, 1, fname.c_str());
|
||||
framebuffer::color fg(fgc);
|
||||
framebuffer::color bg(bgc);
|
||||
framebuffer::color hl(hlc);
|
||||
|
@ -136,14 +136,14 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
function_ptr_luafun gui_text_cf(lua_func_misc, "gui.loadfont", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_text_cf(lua_func_misc, "gui.loadfont", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
if(L.type(1) == LUA_TNONE || L.type(1) == LUA_TNIL) {
|
||||
lua_class<lua_customfont>::create(L);
|
||||
lua::_class<lua_customfont>::create(L);
|
||||
return 1;
|
||||
}
|
||||
std::string filename = L.get_string(1, fname.c_str());
|
||||
lua_class<lua_customfont>::create(L, filename);
|
||||
lua::_class<lua_customfont>::create(L, filename);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace
|
|||
bool vdbl;
|
||||
};
|
||||
|
||||
int internal_gui_text(lua_state& L, const std::string& fname, bool hdbl, bool vdbl)
|
||||
int internal_gui_text(lua::state& L, const std::string& fname, bool hdbl, bool vdbl)
|
||||
{
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
|
@ -46,19 +46,19 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
function_ptr_luafun gui_text(lua_func_misc, "gui.text", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr gui_text(lua_func_misc, "gui.text", [](lua::state& L, const std::string& fname) -> int {
|
||||
return internal_gui_text(L, fname, false, false);
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_textH(lua_func_misc, "gui.textH", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr gui_textH(lua_func_misc, "gui.textH", [](lua::state& L, const std::string& fname) -> int {
|
||||
return internal_gui_text(L, fname, true, false);
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_textV(lua_func_misc, "gui.textV", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr gui_textV(lua_func_misc, "gui.textV", [](lua::state& L, const std::string& fname) -> int {
|
||||
return internal_gui_text(L, fname, false, true);
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_textHV(lua_func_misc, "gui.textHV", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr gui_textHV(lua_func_misc, "gui.textHV", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
return internal_gui_text(L, fname, true, true);
|
||||
});
|
||||
|
|
|
@ -22,21 +22,21 @@ namespace
|
|||
d.clear();
|
||||
p.clear();
|
||||
}
|
||||
lua_obj_pin<lua_bitmap> b;
|
||||
lua_obj_pin<lua_dbitmap> d;
|
||||
lua_obj_pin<lua_palette> p;
|
||||
lua::objpin<lua_bitmap> b;
|
||||
lua::objpin<lua_dbitmap> d;
|
||||
lua::objpin<lua_palette> p;
|
||||
};
|
||||
|
||||
struct tilemap
|
||||
{
|
||||
tilemap(lua_state& L, size_t _width, size_t _height, size_t _cwidth, size_t _cheight);
|
||||
tilemap(lua::state& L, size_t _width, size_t _height, size_t _cwidth, size_t _cheight);
|
||||
~tilemap()
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
render_kill_request(this);
|
||||
}
|
||||
int draw(lua_state& L, const std::string& fname);
|
||||
int get(lua_state& L, const std::string& fname)
|
||||
int draw(lua::state& L, const std::string& fname);
|
||||
int get(lua::state& L, const std::string& fname)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
uint32_t x = L.get_numeric_argument<uint32_t>(2, fname.c_str());
|
||||
|
@ -54,7 +54,7 @@ namespace
|
|||
} else
|
||||
return 0;
|
||||
}
|
||||
int set(lua_state& L, const std::string& fname)
|
||||
int set(lua::state& L, const std::string& fname)
|
||||
{
|
||||
umutex_class h(mutex);
|
||||
uint32_t x = L.get_numeric_argument<uint32_t>(2, fname.c_str());
|
||||
|
@ -62,13 +62,13 @@ namespace
|
|||
if(x >= width || y >= height)
|
||||
return 0;
|
||||
tilemap_entry& e = map[y * width + x];
|
||||
if(lua_class<lua_dbitmap>::is(L, 4)) {
|
||||
auto d = lua_class<lua_dbitmap>::pin(L, 4, fname.c_str());
|
||||
if(lua::_class<lua_dbitmap>::is(L, 4)) {
|
||||
auto d = lua::_class<lua_dbitmap>::pin(L, 4, fname.c_str());
|
||||
e.erase();
|
||||
e.d = d;
|
||||
} else if(lua_class<lua_bitmap>::is(L, 4)) {
|
||||
auto b = lua_class<lua_bitmap>::pin(L, 4, fname.c_str());
|
||||
auto p = lua_class<lua_palette>::pin(L, 5, fname.c_str());
|
||||
} else if(lua::_class<lua_bitmap>::is(L, 4)) {
|
||||
auto b = lua::_class<lua_bitmap>::pin(L, 4, fname.c_str());
|
||||
auto p = lua::_class<lua_palette>::pin(L, 5, fname.c_str());
|
||||
e.erase();
|
||||
e.b = b;
|
||||
e.p = p;
|
||||
|
@ -79,13 +79,13 @@ namespace
|
|||
+ fname);
|
||||
return 0;
|
||||
}
|
||||
int getsize(lua_state& L, const std::string& fname)
|
||||
int getsize(lua::state& L, const std::string& fname)
|
||||
{
|
||||
L.pushnumber(width);
|
||||
L.pushnumber(height);
|
||||
return 2;
|
||||
}
|
||||
int getcsize(lua_state& L, const std::string& fname)
|
||||
int getcsize(lua::state& L, const std::string& fname)
|
||||
{
|
||||
L.pushnumber(cwidth);
|
||||
L.pushnumber(cheight);
|
||||
|
@ -110,7 +110,7 @@ namespace
|
|||
} else
|
||||
return orig + shift;
|
||||
}
|
||||
int scroll(lua_state& L, const std::string& fname)
|
||||
int scroll(lua::state& L, const std::string& fname)
|
||||
{
|
||||
umutex_class mh(mutex);
|
||||
int32_t ox = -L.get_numeric_argument<int32_t>(2, fname.c_str());
|
||||
|
@ -163,7 +163,7 @@ namespace
|
|||
struct render_object_tilemap : public framebuffer::object
|
||||
{
|
||||
render_object_tilemap(int32_t _x, int32_t _y, int32_t _x0, int32_t _y0, uint32_t _w,
|
||||
uint32_t _h, lua_obj_pin<tilemap> _map)
|
||||
uint32_t _h, lua::objpin<tilemap> _map)
|
||||
: x(_x), y(_y), x0(_x0), y0(_y0), w(_w), h(_h), map(_map) {}
|
||||
~render_object_tilemap() throw()
|
||||
{
|
||||
|
@ -272,10 +272,10 @@ namespace
|
|||
int32_t y0;
|
||||
uint32_t w;
|
||||
uint32_t h;
|
||||
lua_obj_pin<tilemap> map;
|
||||
lua::objpin<tilemap> map;
|
||||
};
|
||||
|
||||
int tilemap::draw(lua_state& L, const std::string& fname)
|
||||
int tilemap::draw(lua::state& L, const std::string& fname)
|
||||
{
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
|
@ -287,27 +287,27 @@ namespace
|
|||
L.get_numeric_argument<int32_t>(5, y0, fname.c_str());
|
||||
L.get_numeric_argument<uint32_t>(6, w, fname.c_str());
|
||||
L.get_numeric_argument<uint32_t>(7, h, fname.c_str());
|
||||
auto t = lua_class<tilemap>::pin(L, 1, fname.c_str());
|
||||
auto t = lua::_class<tilemap>::pin(L, 1, fname.c_str());
|
||||
lua_render_ctx->queue->create_add<render_object_tilemap>(x, y, x0, y0, w, h, t);
|
||||
return 0;
|
||||
}
|
||||
|
||||
function_ptr_luafun gui_ctilemap(lua_func_misc, "gui.tilemap", [](lua_state& LS, const std::string& fname) ->
|
||||
lua::fnptr gui_ctilemap(lua_func_misc, "gui.tilemap", [](lua::state& LS, const std::string& fname) ->
|
||||
int {
|
||||
uint32_t w = LS.get_numeric_argument<uint32_t>(1, fname.c_str());
|
||||
uint32_t h = LS.get_numeric_argument<uint32_t>(2, fname.c_str());
|
||||
uint32_t px = LS.get_numeric_argument<uint32_t>(3, fname.c_str());
|
||||
uint32_t py = LS.get_numeric_argument<uint32_t>(4, fname.c_str());
|
||||
tilemap* t = lua_class<tilemap>::create(LS, w, h, px, py);
|
||||
tilemap* t = lua::_class<tilemap>::create(LS, w, h, px, py);
|
||||
return 1;
|
||||
});
|
||||
|
||||
lua_class<tilemap> class_tilemap("TILEMAP");
|
||||
lua::_class<tilemap> class_tilemap("TILEMAP");
|
||||
|
||||
tilemap::tilemap(lua_state& L, size_t _width, size_t _height, size_t _cwidth, size_t _cheight)
|
||||
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)
|
||||
{
|
||||
objclass<tilemap>().bind_multi(L, {
|
||||
lua::objclass<tilemap>().bind_multi(L, {
|
||||
{"draw", &tilemap::draw},
|
||||
{"set", &tilemap::set},
|
||||
{"get", &tilemap::get},
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
namespace
|
||||
{
|
||||
template<typename S>
|
||||
int do_read(lua_state& L, const std::string& fname)
|
||||
int do_read(lua::state& L, const std::string& fname)
|
||||
{
|
||||
size_t address = L.get_numeric_argument<size_t>(1, fname.c_str());
|
||||
auto& h = get_host_memory();
|
||||
|
@ -19,7 +19,7 @@ namespace
|
|||
}
|
||||
|
||||
template<typename S>
|
||||
int do_write(lua_state& L, const std::string& fname)
|
||||
int do_write(lua::state& L, const std::string& fname)
|
||||
{
|
||||
size_t address = L.get_numeric_argument<size_t>(1, fname.c_str());
|
||||
S value = static_cast<S>(L.get_numeric_argument<S>(2, fname.c_str()));
|
||||
|
@ -30,132 +30,132 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
function_ptr_luafun hm_read(lua_func_misc, "hostmemory.read", [](lua_state& L,
|
||||
lua::fnptr hm_read(lua_func_misc, "hostmemory.read", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<uint8_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_write(lua_func_misc, "hostmemory.write", [](lua_state& L,
|
||||
lua::fnptr hm_write(lua_func_misc, "hostmemory.write", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<uint8_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_readb(lua_func_misc, "hostmemory.readbyte", [](lua_state& L,
|
||||
lua::fnptr hm_readb(lua_func_misc, "hostmemory.readbyte", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<uint8_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_writeb(lua_func_misc, "hostmemory.writebyte", [](lua_state& L,
|
||||
lua::fnptr hm_writeb(lua_func_misc, "hostmemory.writebyte", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<uint8_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_readsb(lua_func_misc, "hostmemory.readsbyte", [](lua_state& L,
|
||||
lua::fnptr hm_readsb(lua_func_misc, "hostmemory.readsbyte", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<int8_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_writesb(lua_func_misc, "hostmemory.writesbyte", [](lua_state& L,
|
||||
lua::fnptr hm_writesb(lua_func_misc, "hostmemory.writesbyte", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<int8_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_readw(lua_func_misc, "hostmemory.readword", [](lua_state& L,
|
||||
lua::fnptr hm_readw(lua_func_misc, "hostmemory.readword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<uint16_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_writew(lua_func_misc, "hostmemory.writeword", [](lua_state& L,
|
||||
lua::fnptr hm_writew(lua_func_misc, "hostmemory.writeword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<uint16_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_readsw(lua_func_misc, "hostmemory.readsword", [](lua_state& L,
|
||||
lua::fnptr hm_readsw(lua_func_misc, "hostmemory.readsword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<int16_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_writesw(lua_func_misc, "hostmemory.writesword", [](lua_state& L,
|
||||
lua::fnptr hm_writesw(lua_func_misc, "hostmemory.writesword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<int16_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_readh(lua_func_misc, "hostmemory.readhword", [](lua_state& L,
|
||||
lua::fnptr hm_readh(lua_func_misc, "hostmemory.readhword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<ss_uint24_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_writeh(lua_func_misc, "hostmemory.writehword", [](lua_state& L,
|
||||
lua::fnptr hm_writeh(lua_func_misc, "hostmemory.writehword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<ss_uint24_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_readsh(lua_func_misc, "hostmemory.readshword", [](lua_state& L,
|
||||
lua::fnptr hm_readsh(lua_func_misc, "hostmemory.readshword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<ss_int24_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_writesh(lua_func_misc, "hostmemory.writeshword", [](lua_state& L,
|
||||
lua::fnptr hm_writesh(lua_func_misc, "hostmemory.writeshword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<ss_int24_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_readd(lua_func_misc, "hostmemory.readdword", [](lua_state& L,
|
||||
lua::fnptr hm_readd(lua_func_misc, "hostmemory.readdword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<uint32_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_writed(lua_func_misc, "hostmemory.writedword", [](lua_state& L,
|
||||
lua::fnptr hm_writed(lua_func_misc, "hostmemory.writedword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<uint32_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_readsd(lua_func_misc, "hostmemory.readsdword", [](lua_state& L,
|
||||
lua::fnptr hm_readsd(lua_func_misc, "hostmemory.readsdword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<int32_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_writesd(lua_func_misc, "hostmemory.writesdword", [](lua_state& L,
|
||||
lua::fnptr hm_writesd(lua_func_misc, "hostmemory.writesdword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<int32_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_readq(lua_func_misc, "hostmemory.readqword", [](lua_state& L,
|
||||
lua::fnptr hm_readq(lua_func_misc, "hostmemory.readqword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<uint64_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_writeq(lua_func_misc, "hostmemory.writeqword", [](lua_state& L,
|
||||
lua::fnptr hm_writeq(lua_func_misc, "hostmemory.writeqword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<uint64_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_readsq(lua_func_misc, "hostmemory.readsqword", [](lua_state& L,
|
||||
lua::fnptr hm_readsq(lua_func_misc, "hostmemory.readsqword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<int64_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_writesq(lua_func_misc, "hostmemory.writesqword", [](lua_state& L,
|
||||
lua::fnptr hm_writesq(lua_func_misc, "hostmemory.writesqword", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<int64_t>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_readf4(lua_func_misc, "hostmemory.readfloat", [](lua_state& L,
|
||||
lua::fnptr hm_readf4(lua_func_misc, "hostmemory.readfloat", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<float>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_writef4(lua_func_misc, "hostmemory.writefloat", [](lua_state& L,
|
||||
lua::fnptr hm_writef4(lua_func_misc, "hostmemory.writefloat", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<float>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_readf8(lua_func_misc, "hostmemory.readdouble", [](lua_state& L,
|
||||
lua::fnptr hm_readf8(lua_func_misc, "hostmemory.readdouble", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_read<double>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun hm_writef8(lua_func_misc, "hostmemory.writedouble", [](lua_state& L,
|
||||
lua::fnptr hm_writef8(lua_func_misc, "hostmemory.writedouble", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return do_write<double>(L, fname);
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
class lua_inverse_bind
|
||||
{
|
||||
public:
|
||||
lua_inverse_bind(lua_state& L, const std::string& name, const std::string& cmd);
|
||||
lua_inverse_bind(lua::state& L, const std::string& name, const std::string& cmd);
|
||||
std::string print()
|
||||
{
|
||||
return ikey.getname();
|
||||
|
@ -18,7 +18,7 @@ private:
|
|||
class lua_command_binding : public command::base
|
||||
{
|
||||
public:
|
||||
lua_command_binding(lua_state& _L, const std::string& cmd, int idx)
|
||||
lua_command_binding(lua::state& _L, const std::string& cmd, int idx)
|
||||
: command::base(lsnes_cmd, cmd), L(_L)
|
||||
{
|
||||
L.pushlightuserdata(this);
|
||||
|
@ -45,13 +45,13 @@ public:
|
|||
}
|
||||
}
|
||||
private:
|
||||
lua_state& L;
|
||||
lua::state& L;
|
||||
};
|
||||
|
||||
class lua_command_bind
|
||||
{
|
||||
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();
|
||||
std::string print()
|
||||
{
|
||||
|
@ -65,12 +65,12 @@ private:
|
|||
lua_command_binding* b;
|
||||
};
|
||||
|
||||
lua_inverse_bind::lua_inverse_bind(lua_state& L, 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)
|
||||
{
|
||||
}
|
||||
|
||||
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) {
|
||||
a = new lua_command_binding(L, "+" + cmd, idx1);
|
||||
|
@ -89,7 +89,7 @@ lua_command_bind::~lua_command_bind()
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_luafun input_bindings(lua_func_misc, "list_bindings", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr input_bindings(lua_func_misc, "list_bindings", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
std::string target;
|
||||
if(!L.isnoneornil(1))
|
||||
|
@ -121,7 +121,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun get_alias(lua_func_misc, "get_alias", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr get_alias(lua_func_misc, "get_alias", [](lua::state& L, const std::string& fname) -> int {
|
||||
std::string name = L.get_string(1, fname.c_str());
|
||||
std::string a = lsnes_cmd.get_alias_for(name);
|
||||
if(a != "")
|
||||
|
@ -131,7 +131,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun set_alias(lua_func_misc, "set_alias", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr set_alias(lua_func_misc, "set_alias", [](lua::state& L, const std::string& fname) -> int {
|
||||
std::string name = L.get_string(1, fname.c_str());
|
||||
std::string value;
|
||||
if(L.type(2) != LUA_TNIL)
|
||||
|
@ -141,25 +141,25 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun create_ibind(lua_func_misc, "create_ibind", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr create_ibind(lua_func_misc, "create_ibind", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
std::string name = L.get_string(1, fname.c_str());
|
||||
std::string command = L.get_string(2, fname.c_str());
|
||||
lua_inverse_bind* b = lua_class<lua_inverse_bind>::create(L, name, command);
|
||||
lua_inverse_bind* b = lua::_class<lua_inverse_bind>::create(L, name, command);
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun create_cmd(lua_func_misc, "create_command", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr create_cmd(lua_func_misc, "create_command", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
if(L.type(2) != LUA_TFUNCTION)
|
||||
throw std::runtime_error("Argument 2 of create_command must be function");
|
||||
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");
|
||||
std::string name = L.get_string(1, fname.c_str());
|
||||
lua_command_bind* b = lua_class<lua_command_bind>::create(L, name, 2, 3);
|
||||
lua_command_bind* b = lua::_class<lua_command_bind>::create(L, name, 2, 3);
|
||||
return 1;
|
||||
});
|
||||
|
||||
lua_class<lua_inverse_bind> class_inverse_bind("INVERSEBIND");
|
||||
lua_class<lua_command_bind> class_command_bind("COMMANDBIND");
|
||||
lua::_class<lua_inverse_bind> class_inverse_bind("INVERSEBIND");
|
||||
lua::_class<lua_command_bind> class_command_bind("COMMANDBIND");
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ extern bool* lua_veto_flag;
|
|||
|
||||
namespace
|
||||
{
|
||||
int input_set(lua_state& L, unsigned port, unsigned controller, unsigned index, short value)
|
||||
int input_set(lua::state& L, unsigned port, unsigned controller, unsigned index, short value)
|
||||
{
|
||||
if(!lua_input_controllerdata)
|
||||
return 0;
|
||||
|
@ -18,7 +18,7 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
int input_get(lua_state& L, unsigned port, unsigned controller, unsigned index)
|
||||
int input_get(lua::state& L, unsigned port, unsigned controller, unsigned index)
|
||||
{
|
||||
if(!lua_input_controllerdata)
|
||||
return 0;
|
||||
|
@ -26,7 +26,7 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
int input_controllertype(lua_state& L, unsigned port, unsigned controller)
|
||||
int input_controllertype(lua::state& L, unsigned port, unsigned controller)
|
||||
{
|
||||
auto& m = get_movie();
|
||||
controller_frame f = m.read_subframe(m.get_current_frame(), 0);
|
||||
|
@ -42,7 +42,7 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
int input_seta(lua_state& L, unsigned port, unsigned controller, uint64_t base, const char* fname)
|
||||
int input_seta(lua::state& L, unsigned port, unsigned controller, uint64_t base, const char* fname)
|
||||
{
|
||||
if(!lua_input_controllerdata)
|
||||
return 0;
|
||||
|
@ -60,7 +60,7 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
int input_geta(lua_state& L, unsigned port, unsigned controller)
|
||||
int input_geta(lua::state& L, unsigned port, unsigned controller)
|
||||
{
|
||||
if(!lua_input_controllerdata)
|
||||
return 0;
|
||||
|
@ -79,7 +79,7 @@ namespace
|
|||
return pt.controller_info->controllers[controller].buttons.size() + 1;
|
||||
}
|
||||
|
||||
function_ptr_luafun iset(lua_func_misc, "input.set", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr iset(lua_func_misc, "input.set", [](lua::state& L, const std::string& fname) -> int {
|
||||
if(!lua_input_controllerdata)
|
||||
return 0;
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
|
@ -89,7 +89,7 @@ namespace
|
|||
return input_set(L, _controller.first, _controller.second, index, value);
|
||||
});
|
||||
|
||||
function_ptr_luafun iset2(lua_func_misc, "input.set2", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr iset2(lua_func_misc, "input.set2", [](lua::state& L, const std::string& fname) -> int {
|
||||
unsigned port = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(2, fname.c_str());
|
||||
unsigned index = L.get_numeric_argument<unsigned>(3, fname.c_str());
|
||||
|
@ -97,7 +97,7 @@ namespace
|
|||
return input_set(L, port, controller, index, value);
|
||||
});
|
||||
|
||||
function_ptr_luafun iget(lua_func_misc, "input.get", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr iget(lua_func_misc, "input.get", [](lua::state& L, const std::string& fname) -> int {
|
||||
if(!lua_input_controllerdata)
|
||||
return 0;
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
|
@ -106,14 +106,14 @@ namespace
|
|||
return input_get(L, _controller.first, _controller.second, index);
|
||||
});
|
||||
|
||||
function_ptr_luafun iget2(lua_func_misc, "input.get2", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr iget2(lua_func_misc, "input.get2", [](lua::state& L, const std::string& fname) -> int {
|
||||
unsigned port = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(2, fname.c_str());
|
||||
unsigned index = L.get_numeric_argument<unsigned>(3, fname.c_str());
|
||||
return input_get(L, port, controller, index);
|
||||
});
|
||||
|
||||
function_ptr_luafun iseta(lua_func_misc, "input.seta", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr iseta(lua_func_misc, "input.seta", [](lua::state& L, const std::string& fname) -> int {
|
||||
if(!lua_input_controllerdata)
|
||||
return 0;
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
|
@ -122,14 +122,14 @@ namespace
|
|||
return input_seta(L, _controller.first, _controller.second, base, fname.c_str());
|
||||
});
|
||||
|
||||
function_ptr_luafun iseta2(lua_func_misc, "input.seta2", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr iseta2(lua_func_misc, "input.seta2", [](lua::state& L, const std::string& fname) -> int {
|
||||
unsigned port = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(2, fname.c_str());
|
||||
uint64_t base = L.get_numeric_argument<uint64_t>(3, fname.c_str());
|
||||
return input_seta(L, port, controller, base, fname.c_str());
|
||||
});
|
||||
|
||||
function_ptr_luafun igeta(lua_func_misc, "input.geta", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr igeta(lua_func_misc, "input.geta", [](lua::state& L, const std::string& fname) -> int {
|
||||
if(!lua_input_controllerdata)
|
||||
return 0;
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
|
@ -137,13 +137,13 @@ namespace
|
|||
return input_geta(L, _controller.first, _controller.second);
|
||||
});
|
||||
|
||||
function_ptr_luafun igeta2(lua_func_misc, "input.geta2", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr igeta2(lua_func_misc, "input.geta2", [](lua::state& L, const std::string& fname) -> int {
|
||||
unsigned port = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(2, fname.c_str());
|
||||
return input_geta(L, port, controller);
|
||||
});
|
||||
|
||||
function_ptr_luafun igett(lua_func_misc, "input.controllertype", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr igett(lua_func_misc, "input.controllertype", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
auto& m = get_movie();
|
||||
|
@ -152,14 +152,14 @@ namespace
|
|||
return input_controllertype(L, _controller.first, _controller.second);
|
||||
});
|
||||
|
||||
function_ptr_luafun igett2(lua_func_misc, "input.controllertype2", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr igett2(lua_func_misc, "input.controllertype2", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
unsigned port = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(2, fname.c_str());
|
||||
return input_controllertype(L, port, controller);
|
||||
});
|
||||
|
||||
function_ptr_luafun ireset(lua_func_misc, "input.reset", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr ireset(lua_func_misc, "input.reset", [](lua::state& L, const std::string& fname) -> int {
|
||||
if(!lua_input_controllerdata)
|
||||
return 0;
|
||||
long cycles = 0;
|
||||
|
@ -174,7 +174,7 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun iraw(lua_func_misc, "input.raw", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr iraw(lua_func_misc, "input.raw", [](lua::state& L, const std::string& fname) -> int {
|
||||
L.newtable();
|
||||
for(auto i : lsnes_kbd.all_keys()) {
|
||||
L.pushlstring(i->get_name());
|
||||
|
@ -193,7 +193,7 @@ namespace
|
|||
} keyhook_listener;
|
||||
std::set<std::string> hooked;
|
||||
|
||||
function_ptr_luafun ireq(lua_func_misc, "input.keyhook", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr ireq(lua_func_misc, "input.keyhook", [](lua::state& L, const std::string& fname) -> int {
|
||||
bool state;
|
||||
std::string x = L.get_string(1, fname.c_str());
|
||||
state = L.get_bool(2, fname.c_str());
|
||||
|
@ -213,7 +213,7 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun ijget(lua_func_misc, "input.joyget", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr ijget(lua_func_misc, "input.joyget", [](lua::state& L, const std::string& fname) -> int {
|
||||
unsigned lcid = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
if(!lua_input_controllerdata)
|
||||
return 0;
|
||||
|
@ -237,7 +237,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun ijset(lua_func_misc, "input.joyset", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr ijset(lua_func_misc, "input.joyset", [](lua::state& L, const std::string& fname) -> int {
|
||||
unsigned lcid = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
if(L.type(2) != LUA_TTABLE)
|
||||
throw std::runtime_error("Invalid type for input.joyset");
|
||||
|
@ -274,7 +274,7 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun ijlcid_to_pcid(lua_func_misc, "input.lcid_to_pcid", [](lua_state& L,
|
||||
lua::fnptr ijlcid_to_pcid(lua_func_misc, "input.lcid_to_pcid", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
unsigned lcid = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
auto pcid = controls.lcid_to_pcid(lcid - 1);
|
||||
|
@ -302,7 +302,7 @@ namespace
|
|||
|
||||
//THE NEW API.
|
||||
|
||||
function_ptr_luafun ijlcid_to_pcid2(lua_func_misc, "input.lcid_to_pcid2", [](lua_state& L,
|
||||
lua::fnptr ijlcid_to_pcid2(lua_func_misc, "input.lcid_to_pcid2", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
unsigned lcid = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
auto pcid = controls.lcid_to_pcid(lcid - 1);
|
||||
|
@ -313,7 +313,7 @@ namespace
|
|||
return 2;
|
||||
});
|
||||
|
||||
function_ptr_luafun iporttype(lua_func_misc, "input.port_type", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr iporttype(lua_func_misc, "input.port_type", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
unsigned port = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
auto& m = get_movie();
|
||||
|
@ -335,13 +335,13 @@ namespace
|
|||
return p.controller_info;
|
||||
}
|
||||
|
||||
function_ptr_luafun iveto(lua_func_misc, "input.veto_button", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr iveto(lua_func_misc, "input.veto_button", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
if(lua_veto_flag) *lua_veto_flag = true;
|
||||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun ictrlinfo(lua_func_misc, "input.controller_info", [](lua_state& L,
|
||||
lua::fnptr ictrlinfo(lua_func_misc, "input.controller_info", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
unsigned port = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(2, fname.c_str());
|
||||
|
|
|
@ -16,8 +16,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)
|
||||
lua_inputframe(lua::state& L, controller_frame _f);
|
||||
int get_button(lua::state& L, const std::string& fname)
|
||||
{
|
||||
unsigned port = L.get_numeric_argument<unsigned>(2, fname.c_str());
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(3, fname.c_str());
|
||||
|
@ -26,7 +26,7 @@ namespace
|
|||
L.pushboolean(value ? 1 : 0);
|
||||
return 1;
|
||||
}
|
||||
int get_axis(lua_state& L, const std::string& fname)
|
||||
int get_axis(lua::state& L, const std::string& fname)
|
||||
{
|
||||
unsigned port = L.get_numeric_argument<unsigned>(2, fname.c_str());
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(3, fname.c_str());
|
||||
|
@ -35,7 +35,7 @@ namespace
|
|||
L.pushnumber(value);
|
||||
return 1;
|
||||
}
|
||||
int set_axis(lua_state& L, const std::string& fname)
|
||||
int set_axis(lua::state& L, const std::string& fname)
|
||||
{
|
||||
unsigned port = L.get_numeric_argument<unsigned>(2, fname.c_str());
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(3, fname.c_str());
|
||||
|
@ -51,20 +51,20 @@ namespace
|
|||
setbutton(port, controller, button, value);
|
||||
return 0;
|
||||
}
|
||||
int serialize(lua_state& L, const std::string& fname)
|
||||
int serialize(lua::state& L, const std::string& fname)
|
||||
{
|
||||
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, const std::string& fname)
|
||||
{
|
||||
std::string buf = L.get_string(2, fname.c_str());
|
||||
f.deserialize(buf.c_str());
|
||||
return 0;
|
||||
}
|
||||
int get_stride(lua_state& L, const std::string& fname)
|
||||
int get_stride(lua::state& L, const std::string& fname)
|
||||
{
|
||||
L.pushnumber(f.size());
|
||||
return 1;
|
||||
|
@ -125,14 +125,14 @@ namespace
|
|||
throw std::runtime_error("Can not edit past");
|
||||
}
|
||||
|
||||
function_ptr_luafun movie_cfs(lua_func_misc, "movie.current_first_subframe", [](lua_state& L,
|
||||
lua::fnptr movie_cfs(lua_func_misc, "movie.current_first_subframe", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
movie& m = movb.get_movie();
|
||||
L.pushnumber(m.get_current_frame_first_subframe());
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_pc(lua_func_misc, "movie.pollcounter", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr movie_pc(lua_func_misc, "movie.pollcounter", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
unsigned port = L.get_numeric_argument<unsigned>(1, fname.c_str());
|
||||
unsigned controller = L.get_numeric_argument<unsigned>(2, fname.c_str());
|
||||
|
@ -143,18 +143,18 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
controller_frame_vector& framevector(lua_state& L, int& ptr, const std::string& fname);
|
||||
controller_frame_vector& framevector(lua::state& L, int& ptr, const std::string& fname);
|
||||
|
||||
int _copy_movie(lua_state& L, const std::string& fname)
|
||||
int _copy_movie(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||
|
||||
lua_inputmovie* m = lua_class<lua_inputmovie>::create(L, v);
|
||||
lua_inputmovie* m = lua::_class<lua_inputmovie>::create(L, v);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _get_frame(lua_state& L, const std::string& fname)
|
||||
int _get_frame(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||
|
@ -163,11 +163,11 @@ namespace
|
|||
if(n >= v.size())
|
||||
throw std::runtime_error("Requested frame outside movie");
|
||||
controller_frame _f = v[n];
|
||||
lua_inputframe* f = lua_class<lua_inputframe>::create(L, _f);
|
||||
lua_inputframe* f = lua::_class<lua_inputframe>::create(L, _f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _set_frame(lua_state& L, const std::string& fname)
|
||||
int _set_frame(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||
|
@ -179,7 +179,7 @@ namespace
|
|||
if(&v == &movb.get_movie().get_frame_vector())
|
||||
check_can_edit(0, 0, 0, n);
|
||||
|
||||
lua_inputframe* f = lua_class<lua_inputframe>::get(L, ptr++, fname.c_str());
|
||||
lua_inputframe* f = lua::_class<lua_inputframe>::get(L, ptr++, fname.c_str());
|
||||
int64_t adjust = 0;
|
||||
if(v[n].sync()) adjust--;
|
||||
v[n] = f->get_frame();
|
||||
|
@ -193,7 +193,7 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
int _get_size(lua_state& L, const std::string& fname)
|
||||
int _get_size(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||
|
@ -202,7 +202,7 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
int _count_frames(lua_state& L, const std::string& fname)
|
||||
int _count_frames(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||
|
@ -216,7 +216,7 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
int _find_frame(lua_state& L, const std::string& fname)
|
||||
int _find_frame(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||
|
@ -237,17 +237,17 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
int _blank_frame(lua_state& L, const std::string& fname)
|
||||
int _blank_frame(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||
|
||||
controller_frame _f = v.blank_frame(true);
|
||||
lua_inputframe* f = lua_class<lua_inputframe>::create(L, _f);
|
||||
lua_inputframe* f = lua::_class<lua_inputframe>::create(L, _f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _append_frames(lua_state& L, const std::string& fname)
|
||||
int _append_frames(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||
|
@ -263,12 +263,12 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
int _append_frame(lua_state& L, const std::string& fname)
|
||||
int _append_frame(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||
|
||||
lua_inputframe* f = lua_class<lua_inputframe>::get(L, ptr++, fname.c_str());
|
||||
lua_inputframe* f = lua::_class<lua_inputframe>::get(L, ptr++, fname.c_str());
|
||||
|
||||
v.append(v.blank_frame(true));
|
||||
if(&v == &movb.get_movie().get_frame_vector()) {
|
||||
|
@ -288,7 +288,7 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
int _truncate(lua_state& L, const std::string& fname)
|
||||
int _truncate(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||
|
@ -307,7 +307,7 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
int _edit(lua_state& L, const std::string& fname)
|
||||
int _edit(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||
|
@ -345,7 +345,7 @@ namespace
|
|||
}
|
||||
|
||||
template<bool same>
|
||||
int _copy_frames(lua_state& L, const std::string& fname)
|
||||
int _copy_frames(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& dstv = framevector(L, ptr, fname);
|
||||
|
@ -384,7 +384,7 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
int _serialize(lua_state& L, const std::string& fname)
|
||||
int _serialize(lua::state& L, const std::string& fname)
|
||||
{
|
||||
int ptr = 1;
|
||||
controller_frame_vector& v = framevector(L, ptr, fname);
|
||||
|
@ -419,61 +419,61 @@ namespace
|
|||
class lua_inputmovie
|
||||
{
|
||||
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)
|
||||
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)
|
||||
{
|
||||
return _copy_movie(L, fname.c_str());
|
||||
}
|
||||
int get_frame(lua_state& L, const std::string& fname)
|
||||
int get_frame(lua::state& L, const std::string& fname)
|
||||
{
|
||||
return _get_frame(L, fname.c_str());
|
||||
}
|
||||
int set_frame(lua_state& L, const std::string& fname)
|
||||
int set_frame(lua::state& L, const std::string& fname)
|
||||
{
|
||||
return _set_frame(L, fname.c_str());
|
||||
}
|
||||
int get_size(lua_state& L, const std::string& fname)
|
||||
int get_size(lua::state& L, const std::string& fname)
|
||||
{
|
||||
return _get_size(L, fname.c_str());
|
||||
}
|
||||
int count_frames(lua_state& L, const std::string& fname)
|
||||
int count_frames(lua::state& L, const std::string& fname)
|
||||
{
|
||||
return _count_frames(L, fname.c_str());
|
||||
}
|
||||
int find_frame(lua_state& L, const std::string& fname)
|
||||
int find_frame(lua::state& L, const std::string& fname)
|
||||
{
|
||||
return _find_frame(L, fname.c_str());
|
||||
}
|
||||
int blank_frame(lua_state& L, const std::string& fname)
|
||||
int blank_frame(lua::state& L, const std::string& fname)
|
||||
{
|
||||
return _blank_frame(L, fname.c_str());
|
||||
}
|
||||
int append_frames(lua_state& L, const std::string& fname)
|
||||
int append_frames(lua::state& L, const std::string& fname)
|
||||
{
|
||||
return _append_frames(L, fname.c_str());
|
||||
}
|
||||
int append_frame(lua_state& L, const std::string& fname)
|
||||
int append_frame(lua::state& L, const std::string& fname)
|
||||
{
|
||||
return _append_frame(L, fname.c_str());
|
||||
}
|
||||
int truncate(lua_state& L, const std::string& fname)
|
||||
int truncate(lua::state& L, const std::string& fname)
|
||||
{
|
||||
return _truncate(L, fname.c_str());
|
||||
}
|
||||
int edit(lua_state& L, const std::string& fname)
|
||||
int edit(lua::state& L, const std::string& fname)
|
||||
{
|
||||
return _edit(L, fname.c_str());
|
||||
}
|
||||
int copy_frames(lua_state& L, const std::string& fname)
|
||||
int copy_frames(lua::state& L, const std::string& fname)
|
||||
{
|
||||
return _copy_frames<true>(L, fname.c_str());
|
||||
}
|
||||
int serialize(lua_state& L, const std::string& fname)
|
||||
int serialize(lua::state& L, const std::string& fname)
|
||||
{
|
||||
return _serialize(L, fname.c_str());
|
||||
}
|
||||
int debugdump(lua_state& L, const std::string& fname)
|
||||
int debugdump(lua::state& L, const std::string& fname)
|
||||
{
|
||||
char buf[MAX_SERIALIZED_SIZE];
|
||||
for(uint64_t i = 0; i < v.size(); i++) {
|
||||
|
@ -492,89 +492,89 @@ namespace
|
|||
return (stringfmt() << s << " " << ((s != 1) ? "frames" : "frame")).str();
|
||||
}
|
||||
private:
|
||||
void common_init(lua_state& L);
|
||||
void common_init(lua::state& L);
|
||||
controller_frame_vector v;
|
||||
};
|
||||
|
||||
function_ptr_luafun movie_getdata(lua_func_misc, "movie.copy_movie", [](lua_state& L,
|
||||
lua::fnptr movie_getdata(lua_func_misc, "movie.copy_movie", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return _copy_movie(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_getframe(lua_func_misc, "movie.get_frame", [](lua_state& L,
|
||||
lua::fnptr movie_getframe(lua_func_misc, "movie.get_frame", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return _get_frame(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_setframe(lua_func_misc, "movie.set_frame", [](lua_state& L,
|
||||
lua::fnptr movie_setframe(lua_func_misc, "movie.set_frame", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return _set_frame(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_get_size(lua_func_misc, "movie.get_size", [](lua_state& L,
|
||||
lua::fnptr movie_get_size(lua_func_misc, "movie.get_size", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return _get_size(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_count_frames(lua_func_misc, "movie.count_frames", [](lua_state& L,
|
||||
lua::fnptr movie_count_frames(lua_func_misc, "movie.count_frames", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return _count_frames(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_find_frame(lua_func_misc, "movie.find_frame", [](lua_state& L,
|
||||
lua::fnptr movie_find_frame(lua_func_misc, "movie.find_frame", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return _find_frame(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_blank_frame(lua_func_misc, "movie.blank_frame", [](lua_state& L,
|
||||
lua::fnptr movie_blank_frame(lua_func_misc, "movie.blank_frame", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return _blank_frame(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_append_frames(lua_func_misc, "movie.append_frames", [](lua_state& L,
|
||||
lua::fnptr movie_append_frames(lua_func_misc, "movie.append_frames", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return _append_frames(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_append_frame(lua_func_misc, "movie.append_frame", [](lua_state& L,
|
||||
lua::fnptr movie_append_frame(lua_func_misc, "movie.append_frame", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return _append_frame(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_truncate(lua_func_misc, "movie.truncate", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr movie_truncate(lua_func_misc, "movie.truncate", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
return _truncate(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_edit(lua_func_misc, "movie.edit", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr movie_edit(lua_func_misc, "movie.edit", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
return _edit(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_copyframe2(lua_func_misc, "movie.copy_frames2", [](lua_state& L,
|
||||
lua::fnptr movie_copyframe2(lua_func_misc, "movie.copy_frames2", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return _copy_frames<false>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_copyframe(lua_func_misc, "movie.copy_frames", [](lua_state& L,
|
||||
lua::fnptr movie_copyframe(lua_func_misc, "movie.copy_frames", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return _copy_frames<true>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_serialize(lua_func_misc, "movie.serialize", [](lua_state& L,
|
||||
lua::fnptr movie_serialize(lua_func_misc, "movie.serialize", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return _serialize(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_unserialize(lua_func_misc, "movie.unserialize", [](lua_state& L,
|
||||
lua::fnptr movie_unserialize(lua_func_misc, "movie.unserialize", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
lua_inputframe* f = lua_class<lua_inputframe>::get(L, 1, fname.c_str());
|
||||
lua_inputframe* f = lua::_class<lua_inputframe>::get(L, 1, fname.c_str());
|
||||
std::string filename = L.get_string(2, fname.c_str());
|
||||
bool binary = L.get_bool(3, fname.c_str());
|
||||
std::ifstream file(filename, binary ? std::ios_base::binary : std::ios_base::in);
|
||||
if(!file)
|
||||
throw std::runtime_error("Can't open file to read input from");
|
||||
lua_inputmovie* m = lua_class<lua_inputmovie>::create(L, f->get_frame());
|
||||
lua_inputmovie* m = lua::_class<lua_inputmovie>::create(L, f->get_frame());
|
||||
controller_frame_vector& v = *m->get_frame_vector();
|
||||
if(binary) {
|
||||
uint64_t stride = v.get_stride();
|
||||
|
@ -605,24 +605,24 @@ namespace
|
|||
});
|
||||
|
||||
|
||||
controller_frame_vector& framevector(lua_state& L, int& ptr, const std::string& fname)
|
||||
controller_frame_vector& framevector(lua::state& L, int& ptr, const std::string& fname)
|
||||
{
|
||||
if(L.type(ptr) == LUA_TNIL) { //NONE can be handled as else case.
|
||||
ptr++;
|
||||
return movb.get_movie().get_frame_vector();
|
||||
} else if(lua_class<lua_inputmovie>::is(L, ptr))
|
||||
return *lua_class<lua_inputmovie>::get(L, ptr++, fname.c_str())->get_frame_vector();
|
||||
} else if(lua::_class<lua_inputmovie>::is(L, ptr))
|
||||
return *lua::_class<lua_inputmovie>::get(L, ptr++, fname.c_str())->get_frame_vector();
|
||||
else
|
||||
return movb.get_movie().get_frame_vector();
|
||||
}
|
||||
|
||||
lua_class<lua_inputmovie> class_inputmovie("INPUTMOVIE");
|
||||
lua_class<lua_inputframe> class_inputframe("INPUTFRAME");
|
||||
lua::_class<lua_inputmovie> class_inputmovie("INPUTMOVIE");
|
||||
lua::_class<lua_inputframe> class_inputframe("INPUTFRAME");
|
||||
|
||||
lua_inputframe::lua_inputframe(lua_state& L, controller_frame _f)
|
||||
lua_inputframe::lua_inputframe(lua::state& L, controller_frame _f)
|
||||
{
|
||||
f = _f;
|
||||
objclass<lua_inputframe>().bind_multi(L, {
|
||||
lua::objclass<lua_inputframe>().bind_multi(L, {
|
||||
{"get_button", &lua_inputframe::get_button},
|
||||
{"get_axis", &lua_inputframe::get_axis},
|
||||
{"set_axis", &lua_inputframe::set_axis},
|
||||
|
@ -633,9 +633,9 @@ namespace
|
|||
});
|
||||
}
|
||||
|
||||
void lua_inputmovie::common_init(lua_state& L)
|
||||
void lua_inputmovie::common_init(lua::state& L)
|
||||
{
|
||||
objclass<lua_inputmovie>().bind_multi(L, {
|
||||
lua::objclass<lua_inputmovie>().bind_multi(L, {
|
||||
{"copy_movie", &lua_inputmovie::copy_movie},
|
||||
{"get_frame", &lua_inputmovie::get_frame},
|
||||
{"set_frame", &lua_inputmovie::set_frame},
|
||||
|
@ -653,13 +653,13 @@ 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;
|
||||
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());
|
||||
common_init(L);
|
||||
|
|
|
@ -149,12 +149,12 @@ namespace
|
|||
class lua_file_reader
|
||||
{
|
||||
public:
|
||||
lua_file_reader(lua_state& L, std::istream* strm);
|
||||
lua_file_reader(lua::state& L, std::istream* strm);
|
||||
~lua_file_reader()
|
||||
{
|
||||
delete &s;
|
||||
}
|
||||
int read(lua_state& L, const std::string& fname)
|
||||
int read(lua::state& L, const std::string& fname)
|
||||
{
|
||||
if(L.type(2) == LUA_TNUMBER) {
|
||||
//Read specified number of bytes.
|
||||
|
@ -182,7 +182,7 @@ namespace
|
|||
} else
|
||||
(stringfmt() << "Expected number or nil as the 2nd argument of " << fname).throwex();
|
||||
}
|
||||
int lines(lua_state& L, const std::string& fname)
|
||||
int lines(lua::state& L, const std::string& fname)
|
||||
{
|
||||
L.pushlightuserdata(this);
|
||||
L.pushcclosure(lua_file_reader::lines_helper2, 1);
|
||||
|
@ -240,7 +240,7 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
void load_chunk(lua_state& L, const std::string& fname)
|
||||
void load_chunk(lua::state& L, const std::string& fname)
|
||||
{
|
||||
std::string file2;
|
||||
std::string file1 = L.get_string(1, fname.c_str());
|
||||
|
@ -273,13 +273,13 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
function_ptr_luafun loadfile2(lua_func_load, "loadfile2", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr loadfile2(lua_func_load, "loadfile2", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
load_chunk(L, fname);
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun dofile2(lua_func_load, "dofile2", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr dofile2(lua_func_load, "dofile2", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
load_chunk(L, fname);
|
||||
int old_sp = lua_gettop(L.handle());
|
||||
|
@ -288,7 +288,7 @@ namespace
|
|||
return new_sp - (old_sp - 1);
|
||||
});
|
||||
|
||||
function_ptr_luafun resolvefile(lua_func_load, "resolve_filename", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr resolvefile(lua_func_load, "resolve_filename", [](lua::state& L, const std::string& fname)
|
||||
{
|
||||
std::string file2;
|
||||
std::string file1 = L.get_string(1, fname.c_str());
|
||||
|
@ -299,14 +299,14 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun openfile(lua_func_load, "open_file", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr openfile(lua_func_load, "open_file", [](lua::state& L, const std::string& fname) -> int {
|
||||
std::string file2;
|
||||
std::string file1 = L.get_string(1, fname.c_str());
|
||||
if(L.type(2) != LUA_TNIL && L.type(2) != LUA_TNONE)
|
||||
file2 = L.get_string(2, fname.c_str());
|
||||
std::istream& s = zip::openrel(file1, file2);
|
||||
try {
|
||||
lua_class<lua_file_reader>::create(L, &s);
|
||||
lua::_class<lua_file_reader>::create(L, &s);
|
||||
return 1;
|
||||
} catch(...) {
|
||||
delete &s;
|
||||
|
@ -314,12 +314,12 @@ namespace
|
|||
}
|
||||
});
|
||||
|
||||
lua_class<lua_file_reader> class_filreader("FILEREADER");
|
||||
lua::_class<lua_file_reader> class_filreader("FILEREADER");
|
||||
|
||||
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)
|
||||
{
|
||||
objclass<lua_file_reader>().bind_multi(L, {
|
||||
lua::objclass<lua_file_reader>().bind_multi(L, {
|
||||
{"__call", &lua_file_reader::read},
|
||||
{"lines", &lua_file_reader::lines}
|
||||
});
|
||||
|
|
|
@ -23,23 +23,23 @@ bool* lua_kill_frame = NULL;
|
|||
extern const char* lua_sysrc_script;
|
||||
void* synchronous_paint_ctx;
|
||||
|
||||
lua_state lsnes_lua_state;
|
||||
lua_function_group lua_func_bit;
|
||||
lua_function_group lua_func_misc;
|
||||
lua_function_group lua_func_callback;
|
||||
lua_function_group lua_func_load;
|
||||
lua_function_group lua_func_zip;
|
||||
lua::state lsnes_lua_state;
|
||||
lua::function_group lua_func_bit;
|
||||
lua::function_group lua_func_misc;
|
||||
lua::function_group lua_func_callback;
|
||||
lua::function_group lua_func_load;
|
||||
lua::function_group lua_func_zip;
|
||||
|
||||
namespace
|
||||
{
|
||||
void pushpair(lua_state& L, std::string key, double value)
|
||||
void pushpair(lua::state& L, std::string key, double value)
|
||||
{
|
||||
L.pushstring(key.c_str());
|
||||
L.pushnumber(value);
|
||||
L.settable(-3);
|
||||
}
|
||||
|
||||
void pushpair(lua_state& L, std::string key, std::string value)
|
||||
void pushpair(lua::state& L, std::string key, std::string value)
|
||||
{
|
||||
L.pushstring(key.c_str());
|
||||
L.pushstring(value.c_str());
|
||||
|
@ -56,7 +56,7 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
void push_keygroup_parameters(lua_state& L, keyboard::key& p)
|
||||
void push_keygroup_parameters(lua::state& L, keyboard::key& p)
|
||||
{
|
||||
keyboard::mouse_calibration p2;
|
||||
keyboard::axis_calibration p3;
|
||||
|
@ -90,7 +90,7 @@ bool lua_booted_flag = false;
|
|||
|
||||
namespace
|
||||
{
|
||||
int push_keygroup_parameters2(lua_state& L, keyboard::key* p)
|
||||
int push_keygroup_parameters2(lua::state& L, keyboard::key* p)
|
||||
{
|
||||
push_keygroup_parameters(L, *p);
|
||||
return 1;
|
||||
|
@ -118,7 +118,7 @@ namespace
|
|||
"\"Parse error in Lua statement\"); end;";
|
||||
const char* run_lua_lua = "dofile(" TEMPORARY ");";
|
||||
|
||||
void run_lua_fragment(lua_state& L) throw(std::bad_alloc)
|
||||
void run_lua_fragment(lua::state& L) throw(std::bad_alloc)
|
||||
{
|
||||
if(recursive_flag)
|
||||
return;
|
||||
|
@ -161,7 +161,7 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
void do_eval_lua(lua_state& L, const std::string& c) throw(std::bad_alloc)
|
||||
void do_eval_lua(lua::state& L, const std::string& c) throw(std::bad_alloc)
|
||||
{
|
||||
L.pushlstring(c.c_str(), c.length());
|
||||
L.setglobal(TEMPORARY);
|
||||
|
@ -169,7 +169,7 @@ namespace
|
|||
run_lua_fragment(L);
|
||||
}
|
||||
|
||||
void do_run_lua(lua_state& L, const std::string& c) throw(std::bad_alloc)
|
||||
void do_run_lua(lua::state& L, const std::string& c) throw(std::bad_alloc)
|
||||
{
|
||||
L.pushlstring(c.c_str(), c.length());
|
||||
L.setglobal(TEMPORARY);
|
||||
|
@ -177,7 +177,7 @@ namespace
|
|||
run_lua_fragment(L);
|
||||
}
|
||||
|
||||
template<typename... T> bool run_callback(lua_state::lua_callback_list& list, T... args)
|
||||
template<typename... T> bool run_callback(lua::state::callback_list& list, T... args)
|
||||
{
|
||||
if(recursive_flag)
|
||||
return true;
|
||||
|
@ -206,7 +206,7 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
void copy_system_tables(lua_state& L)
|
||||
void copy_system_tables(lua::state& L)
|
||||
{
|
||||
#if LUA_VERSION_NUM == 501
|
||||
L.pushvalue(LUA_GLOBALSINDEX);
|
||||
|
@ -233,7 +233,7 @@ namespace
|
|||
L.setglobal("_SYSTEM");
|
||||
}
|
||||
|
||||
void run_sysrc_lua(lua_state& L)
|
||||
void run_sysrc_lua(lua::state& L)
|
||||
{
|
||||
do_eval_lua(L, lua_sysrc_script);
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ namespace
|
|||
lua_renderq_run(ctx, synchronous_paint_ctx);
|
||||
}
|
||||
|
||||
#define DEFINE_CB(X) lua_state::lua_callback_list on_##X (lsnes_lua_state, #X , "on_" #X )
|
||||
#define DEFINE_CB(X) lua::state::callback_list on_##X (lsnes_lua_state, #X , "on_" #X )
|
||||
|
||||
DEFINE_CB(paint);
|
||||
DEFINE_CB(video);
|
||||
|
@ -279,12 +279,12 @@ namespace
|
|||
void lua_callback_do_paint(struct lua_render_context* ctx, bool non_synthetic) throw()
|
||||
{
|
||||
run_synchronous_paint(ctx);
|
||||
run_callback(on_paint, lua_state::store_tag(lua_render_ctx, ctx), lua_state::boolean_tag(non_synthetic));
|
||||
run_callback(on_paint, lua::state::store_tag(lua_render_ctx, ctx), lua::state::boolean_tag(non_synthetic));
|
||||
}
|
||||
|
||||
void lua_callback_do_video(struct lua_render_context* ctx, bool& kill_frame) throw()
|
||||
{
|
||||
run_callback(on_video, lua_state::store_tag(lua_render_ctx, ctx), lua_state::store_tag(lua_kill_frame,
|
||||
run_callback(on_video, lua::state::store_tag(lua_render_ctx, ctx), lua::state::store_tag(lua_kill_frame,
|
||||
&kill_frame));
|
||||
}
|
||||
|
||||
|
@ -333,54 +333,54 @@ void lua_callback_startup() throw()
|
|||
|
||||
void lua_callback_pre_load(const std::string& name) throw()
|
||||
{
|
||||
run_callback(on_pre_load, lua_state::string_tag(name));
|
||||
run_callback(on_pre_load, lua::state::string_tag(name));
|
||||
}
|
||||
|
||||
void lua_callback_err_load(const std::string& name) throw()
|
||||
{
|
||||
run_callback(on_err_load, lua_state::string_tag(name));
|
||||
run_callback(on_err_load, lua::state::string_tag(name));
|
||||
}
|
||||
|
||||
void lua_callback_post_load(const std::string& name, bool was_state) throw()
|
||||
{
|
||||
run_callback(on_post_load, lua_state::string_tag(name), lua_state::boolean_tag(was_state));
|
||||
run_callback(on_post_load, lua::state::string_tag(name), lua::state::boolean_tag(was_state));
|
||||
}
|
||||
|
||||
void lua_callback_pre_save(const std::string& name, bool is_state) throw()
|
||||
{
|
||||
run_callback(on_pre_save, lua_state::string_tag(name), lua_state::boolean_tag(is_state));
|
||||
run_callback(on_pre_save, lua::state::string_tag(name), lua::state::boolean_tag(is_state));
|
||||
}
|
||||
|
||||
void lua_callback_err_save(const std::string& name) throw()
|
||||
{
|
||||
run_callback(on_err_save, lua_state::string_tag(name));
|
||||
run_callback(on_err_save, lua::state::string_tag(name));
|
||||
}
|
||||
|
||||
void lua_callback_post_save(const std::string& name, bool is_state) throw()
|
||||
{
|
||||
run_callback(on_post_save, lua_state::string_tag(name), lua_state::boolean_tag(is_state));
|
||||
run_callback(on_post_save, lua::state::string_tag(name), lua::state::boolean_tag(is_state));
|
||||
}
|
||||
|
||||
void lua_callback_do_input(controller_frame& data, bool subframe) throw()
|
||||
{
|
||||
run_callback(on_input, lua_state::store_tag(lua_input_controllerdata, &data),
|
||||
lua_state::boolean_tag(subframe));
|
||||
run_callback(on_input, lua::state::store_tag(lua_input_controllerdata, &data),
|
||||
lua::state::boolean_tag(subframe));
|
||||
}
|
||||
|
||||
void lua_callback_snoop_input(uint32_t port, uint32_t controller, uint32_t index, short value) throw()
|
||||
{
|
||||
if(run_callback(on_snoop2, lua_state::numeric_tag(port), lua_state::numeric_tag(controller),
|
||||
lua_state::numeric_tag(index), lua_state::numeric_tag(value)))
|
||||
if(run_callback(on_snoop2, lua::state::numeric_tag(port), lua::state::numeric_tag(controller),
|
||||
lua::state::numeric_tag(index), lua::state::numeric_tag(value)))
|
||||
return;
|
||||
run_callback(on_snoop, lua_state::numeric_tag(port), lua_state::numeric_tag(controller),
|
||||
lua_state::numeric_tag(index), lua_state::numeric_tag(value));
|
||||
run_callback(on_snoop, lua::state::numeric_tag(port), lua::state::numeric_tag(controller),
|
||||
lua::state::numeric_tag(index), lua::state::numeric_tag(value));
|
||||
}
|
||||
|
||||
bool lua_callback_do_button(uint32_t port, uint32_t controller, uint32_t index, const char* type)
|
||||
{
|
||||
bool flag = false;
|
||||
run_callback(on_button, lua_state::store_tag(lua_veto_flag, &flag), lua_state::numeric_tag(port),
|
||||
lua_state::numeric_tag(controller), lua_state::numeric_tag(index), lua_state::string_tag(type));
|
||||
run_callback(on_button, lua::state::store_tag(lua_veto_flag, &flag), lua::state::numeric_tag(port),
|
||||
lua::state::numeric_tag(controller), lua::state::numeric_tag(index), lua::state::string_tag(type));
|
||||
return flag;
|
||||
}
|
||||
|
||||
|
@ -421,7 +421,7 @@ namespace
|
|||
messages << "Lua VM reset" << std::endl;
|
||||
});
|
||||
|
||||
lua_class<lua_unsaferewind> class_unsaferewind("UNSAFEREWIND");
|
||||
lua::_class<lua_unsaferewind> class_unsaferewind("UNSAFEREWIND");
|
||||
}
|
||||
|
||||
void lua_callback_quit() throw()
|
||||
|
@ -431,7 +431,7 @@ void lua_callback_quit() throw()
|
|||
|
||||
void lua_callback_keyhook(const std::string& key, keyboard::key& p) throw()
|
||||
{
|
||||
run_callback(on_keyhook, lua_state::string_tag(key), lua_state::fnptr_tag(push_keygroup_parameters2, &p));
|
||||
run_callback(on_keyhook, lua::state::string_tag(key), lua::state::fnptr_tag(push_keygroup_parameters2, &p));
|
||||
}
|
||||
|
||||
void init_lua() throw()
|
||||
|
@ -476,7 +476,7 @@ uint64_t lua_timed_hook(int timer) throw()
|
|||
void lua_callback_do_unsafe_rewind(const std::vector<char>& save, uint64_t secs, uint64_t ssecs, movie& mov, void* u)
|
||||
{
|
||||
if(u) {
|
||||
lua_unsaferewind* u2 = reinterpret_cast<lua_obj_pin<lua_unsaferewind>*>(u)->object();
|
||||
lua_unsaferewind* u2 = reinterpret_cast<lua::objpin<lua_unsaferewind>*>(u)->object();
|
||||
//Load.
|
||||
try {
|
||||
run_callback(on_pre_rewind);
|
||||
|
@ -485,14 +485,14 @@ void lua_callback_do_unsafe_rewind(const std::vector<char>& save, uint64_t secs,
|
|||
mov.fast_load(u2->frame, u2->ptr, u2->lag, u2->pollcounters);
|
||||
try { get_host_memory() = u2->hostmemory; } catch(...) {}
|
||||
run_callback(on_post_rewind);
|
||||
delete reinterpret_cast<lua_obj_pin<lua_unsaferewind>*>(u);
|
||||
delete reinterpret_cast<lua::objpin<lua_unsaferewind>*>(u);
|
||||
} catch(...) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
//Save
|
||||
run_callback(on_set_rewind, lua_state::fn_tag([save, secs, ssecs, &mov](lua_state& L) -> int {
|
||||
lua_unsaferewind* u2 = lua_class<lua_unsaferewind>::create(lsnes_lua_state);
|
||||
run_callback(on_set_rewind, lua::state::fn_tag([save, secs, ssecs, &mov](lua::state& L) -> int {
|
||||
lua_unsaferewind* u2 = lua::_class<lua_unsaferewind>::create(lsnes_lua_state);
|
||||
u2->state = save;
|
||||
u2->secs = secs,
|
||||
u2->ssecs = ssecs;
|
||||
|
@ -510,12 +510,12 @@ void lua_callback_movie_lost(const char* what)
|
|||
|
||||
void lua_callback_do_latch(std::list<std::string>& args)
|
||||
{
|
||||
run_callback(on_latch, lua_state::vararg_tag(args));
|
||||
run_callback(on_latch, lua::state::vararg_tag(args));
|
||||
}
|
||||
|
||||
bool lua_requests_repaint = false;
|
||||
bool lua_requests_subframe_paint = false;
|
||||
|
||||
lua_unsaferewind::lua_unsaferewind(lua_state& L)
|
||||
lua_unsaferewind::lua_unsaferewind(lua::state& L)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
uint64_t get_vmabase(lua_state& L, const std::string& vma)
|
||||
uint64_t get_vmabase(lua::state& L, const std::string& vma)
|
||||
{
|
||||
for(auto i : lsnes_memory.get_regions())
|
||||
if(i->name == vma)
|
||||
|
@ -21,7 +21,7 @@ namespace
|
|||
throw std::runtime_error("No such VMA");
|
||||
}
|
||||
|
||||
uint64_t get_read_address(lua_state& L, int& base, const char* fn)
|
||||
uint64_t get_read_address(lua::state& L, int& base, const char* fn)
|
||||
{
|
||||
uint64_t vmabase = 0;
|
||||
if(L.type(base) == LUA_TSTRING) {
|
||||
|
@ -33,11 +33,11 @@ namespace
|
|||
}
|
||||
|
||||
template<typename T, T (memory_space::*rfun)(uint64_t addr)>
|
||||
class lua_read_memory : public lua_function
|
||||
class lua_read_memory : public lua::function
|
||||
{
|
||||
public:
|
||||
lua_read_memory(const std::string& name) : lua_function(lua_func_misc, name) {}
|
||||
int invoke(lua_state& L)
|
||||
lua_read_memory(const std::string& name) : lua::function(lua_func_misc, name) {}
|
||||
int invoke(lua::state& L)
|
||||
{
|
||||
int base = 1;
|
||||
uint64_t addr = get_read_address(L, base, "lua_read_memory");
|
||||
|
@ -47,11 +47,11 @@ namespace
|
|||
};
|
||||
|
||||
template<typename T, bool (memory_space::*wfun)(uint64_t addr, T value)>
|
||||
class lua_write_memory : public lua_function
|
||||
class lua_write_memory : public lua::function
|
||||
{
|
||||
public:
|
||||
lua_write_memory(const std::string& name) : lua_function(lua_func_misc, name) {}
|
||||
int invoke(lua_state& L)
|
||||
lua_write_memory(const std::string& name) : lua::function(lua_func_misc, name) {}
|
||||
int invoke(lua::state& L)
|
||||
{
|
||||
int base = 1;
|
||||
uint64_t addr = get_read_address(L, base, "lua_write_memory");
|
||||
|
@ -65,8 +65,8 @@ namespace
|
|||
{
|
||||
public:
|
||||
~mmap_base() {}
|
||||
virtual void read(lua_state& L, uint64_t addr) = 0;
|
||||
virtual void write(lua_state& L, uint64_t addr) = 0;
|
||||
virtual void read(lua::state& L, uint64_t addr) = 0;
|
||||
virtual void write(lua::state& L, uint64_t addr) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -76,12 +76,12 @@ namespace
|
|||
{
|
||||
public:
|
||||
~lua_mmap_memory_helper() {}
|
||||
void read(lua_state& L, uint64_t addr)
|
||||
void read(lua::state& L, uint64_t addr)
|
||||
{
|
||||
L.pushnumber(static_cast<T>((lsnes_memory.*rfun)(addr)));
|
||||
}
|
||||
|
||||
void write(lua_state& L, uint64_t addr)
|
||||
void write(lua::state& L, uint64_t addr)
|
||||
{
|
||||
T value = L.get_numeric_argument<T>(3, "aperture(write)");
|
||||
(lsnes_memory.*wfun)(addr, value);
|
||||
|
@ -92,13 +92,13 @@ namespace
|
|||
class lua_mmap_struct
|
||||
{
|
||||
public:
|
||||
lua_mmap_struct(lua_state& L);
|
||||
lua_mmap_struct(lua::state& L);
|
||||
|
||||
~lua_mmap_struct()
|
||||
{
|
||||
}
|
||||
|
||||
int index(lua_state& L, const std::string& fname)
|
||||
int index(lua::state& L, const std::string& fname)
|
||||
{
|
||||
const char* c = L.tostring(2);
|
||||
if(!c) {
|
||||
|
@ -114,7 +114,7 @@ public:
|
|||
x.first->read(L, x.second);
|
||||
return 1;
|
||||
}
|
||||
int newindex(lua_state& L, const std::string& fname)
|
||||
int newindex(lua::state& L, const std::string& fname)
|
||||
{
|
||||
const char* c = L.tostring(2);
|
||||
if(!c)
|
||||
|
@ -126,7 +126,7 @@ public:
|
|||
x.first->write(L, x.second);
|
||||
return 0;
|
||||
}
|
||||
int map(lua_state& L, const std::string& fname);
|
||||
int map(lua::state& L, const std::string& fname);
|
||||
std::string print()
|
||||
{
|
||||
size_t s = mappings.size();
|
||||
|
@ -140,7 +140,7 @@ namespace
|
|||
{
|
||||
int aperture_read_fun(lua_State* _L)
|
||||
{
|
||||
lua_state& L = *reinterpret_cast<lua_state*>(lua_touserdata(_L, lua_upvalueindex(4)));
|
||||
lua::state& L = *reinterpret_cast<lua::state*>(lua_touserdata(_L, lua_upvalueindex(4)));
|
||||
uint64_t base = L.tonumber(lua_upvalueindex(1));
|
||||
uint64_t size = 0xFFFFFFFFFFFFFFFFULL;
|
||||
if(L.type(lua_upvalueindex(2)) == LUA_TNUMBER)
|
||||
|
@ -158,7 +158,7 @@ namespace
|
|||
|
||||
int aperture_write_fun(lua_State* _L)
|
||||
{
|
||||
lua_state& L = *reinterpret_cast<lua_state*>(lua_touserdata(_L, lua_upvalueindex(4)));
|
||||
lua::state& L = *reinterpret_cast<lua::state*>(lua_touserdata(_L, lua_upvalueindex(4)));
|
||||
uint64_t base = L.tonumber(lua_upvalueindex(1));
|
||||
uint64_t size = 0xFFFFFFFFFFFFFFFFULL;
|
||||
if(L.type(lua_upvalueindex(2)) == LUA_TNUMBER)
|
||||
|
@ -172,7 +172,7 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
void aperture_make_fun(lua_state& L, uint64_t base, uint64_t size, mmap_base& type)
|
||||
void aperture_make_fun(lua::state& L, uint64_t base, uint64_t size, mmap_base& type)
|
||||
{
|
||||
L.newtable();
|
||||
L.newtable();
|
||||
|
@ -233,7 +233,7 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
|
||||
void do_lua_error(lua_state& L, int ret)
|
||||
void do_lua_error(lua::state& L, int ret)
|
||||
{
|
||||
if(!ret) return;
|
||||
switch(ret) {
|
||||
|
@ -253,11 +253,11 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
template<debug_type type, bool reg> class lua_registerX : public lua_function
|
||||
template<debug_type type, bool reg> class lua_registerX : public lua::function
|
||||
{
|
||||
public:
|
||||
lua_registerX(const std::string& name) : lua_function(lua_func_misc, name) {}
|
||||
int invoke(lua_state& L)
|
||||
lua_registerX(const std::string& name) : lua::function(lua_func_misc, name) {}
|
||||
int invoke(lua::state& L)
|
||||
{
|
||||
uint64_t addr;
|
||||
int base = 1;
|
||||
|
@ -279,7 +279,7 @@ namespace
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
void handle_registerX(lua_state& L, uint64_t addr, int lfn)
|
||||
void handle_registerX(lua::state& L, uint64_t addr, int lfn)
|
||||
{
|
||||
auto& cbl = cbs[addr];
|
||||
|
||||
|
@ -301,7 +301,7 @@ namespace
|
|||
D->addr = addr;
|
||||
D->type = type;
|
||||
D->lua_fn = L.topointer(lfn);
|
||||
lua_state* LL = &L.get_master();
|
||||
lua::state* LL = &L.get_master();
|
||||
void* D2 = &D->type;
|
||||
if(type != DEBUG_TRACE)
|
||||
D->h = debug_add_callback(addr, type, [LL, D2](uint64_t addr, uint64_t value) {
|
||||
|
@ -333,7 +333,7 @@ namespace
|
|||
L.pushvalue(lfn);
|
||||
L.rawset(LUA_REGISTRYINDEX);
|
||||
}
|
||||
void handle_unregisterX(lua_state& L, uint64_t addr, int lfn)
|
||||
void handle_unregisterX(lua::state& L, uint64_t addr, int lfn)
|
||||
{
|
||||
if(!cbs.count(addr))
|
||||
return;
|
||||
|
@ -360,11 +360,11 @@ namespace
|
|||
<< j->lua_fn << std::endl;
|
||||
});
|
||||
|
||||
class lua_mmap_memory : public lua_function
|
||||
class lua_mmap_memory : public lua::function
|
||||
{
|
||||
public:
|
||||
lua_mmap_memory(const std::string& name, mmap_base& _h) : lua_function(lua_func_misc, name), h(_h) {}
|
||||
int invoke(lua_state& L)
|
||||
lua_mmap_memory(const std::string& name, mmap_base& _h) : lua::function(lua_func_misc, name), h(_h) {}
|
||||
int invoke(lua::state& L)
|
||||
{
|
||||
if(L.isnoneornil(1)) {
|
||||
aperture_make_fun(L, 0, 0xFFFFFFFFFFFFFFFFULL, h);
|
||||
|
@ -381,13 +381,13 @@ namespace
|
|||
mmap_base& h;
|
||||
};
|
||||
|
||||
function_ptr_luafun vmacount(lua_func_misc, "memory.vma_count", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr vmacount(lua_func_misc, "memory.vma_count", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
L.pushnumber(lsnes_memory.get_regions().size());
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun cheat(lua_func_misc, "memory.cheat", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr cheat(lua_func_misc, "memory.cheat", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
int base = 1;
|
||||
uint64_t addr = get_read_address(L, base, fname.c_str());
|
||||
|
@ -400,14 +400,14 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun xmask(lua_func_misc, "memory.setxmask", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr xmask(lua_func_misc, "memory.setxmask", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint64_t value = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
debug_setxmask(value);
|
||||
return 0;
|
||||
});
|
||||
|
||||
int handle_push_vma(lua_state& L, memory_region& r)
|
||||
int handle_push_vma(lua::state& L, memory_region& r)
|
||||
{
|
||||
L.newtable();
|
||||
L.pushstring("region_name");
|
||||
|
@ -437,7 +437,7 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
function_ptr_luafun readvma(lua_func_misc, "memory.read_vma", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr readvma(lua_func_misc, "memory.read_vma", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
std::list<memory_region*> regions = lsnes_memory.get_regions();
|
||||
uint32_t num = L.get_numeric_argument<uint32_t>(1, fname.c_str());
|
||||
|
@ -449,7 +449,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun findvma(lua_func_misc, "memory.find_vma", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr findvma(lua_func_misc, "memory.find_vma", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint64_t addr = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
auto r = lsnes_memory.lookup(addr);
|
||||
|
@ -461,7 +461,7 @@ namespace
|
|||
|
||||
const char* hexes = "0123456789ABCDEF";
|
||||
|
||||
function_ptr_luafun hashstate(lua_func_misc, "memory.hash_state", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr hashstate(lua_func_misc, "memory.hash_state", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
char hash[64];
|
||||
auto x = our_rom.save_core_state();
|
||||
|
@ -476,7 +476,7 @@ namespace
|
|||
|
||||
#define BLOCKSIZE 256
|
||||
|
||||
function_ptr_luafun hashmemory(lua_func_misc, "memory.hash_region", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr hashmemory(lua_func_misc, "memory.hash_region", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
std::string hash;
|
||||
int base = 1;
|
||||
|
@ -499,7 +499,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun readmemoryr(lua_func_misc, "memory.readregion", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr readmemoryr(lua_func_misc, "memory.readregion", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
std::string hash;
|
||||
int base = 1;
|
||||
|
@ -522,7 +522,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun writememoryr(lua_func_misc, "memory.writeregion", [](lua_state& L,
|
||||
lua::fnptr writememoryr(lua_func_misc, "memory.writeregion", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
std::string hash;
|
||||
int base = 1;
|
||||
|
@ -545,20 +545,20 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun gui_cbitmap(lua_func_misc, "memory.map_structure", [](lua_state& L,
|
||||
lua::fnptr gui_cbitmap(lua_func_misc, "memory.map_structure", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
lua_class<lua_mmap_struct>::create(L);
|
||||
lua::_class<lua_mmap_struct>::create(L);
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun memory_watchexpr(lua_func_misc, "memory.read_expr", [](lua_state& L,
|
||||
lua::fnptr memory_watchexpr(lua_func_misc, "memory.read_expr", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
std::string val = evaluate_watch(L.get_string(1, fname.c_str()));
|
||||
L.pushstring(val.c_str());
|
||||
return 1;
|
||||
});
|
||||
|
||||
template<bool write, bool sign> int memory_scattergather(lua_state& L, const std::string& fname)
|
||||
template<bool write, bool sign> int memory_scattergather(lua::state& L, const std::string& fname)
|
||||
{
|
||||
uint64_t val = 0;
|
||||
int ptr = 1;
|
||||
|
@ -592,17 +592,17 @@ namespace
|
|||
return write ? 0 : 1;
|
||||
}
|
||||
|
||||
function_ptr_luafun scattergather1(lua_func_misc, "memory.read_sg", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr scattergather1(lua_func_misc, "memory.read_sg", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
return memory_scattergather<false, false>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun scattergather2(lua_func_misc, "memory.sread_sg", [](lua_state& L,
|
||||
lua::fnptr scattergather2(lua_func_misc, "memory.sread_sg", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return memory_scattergather<false, true>(L, fname);
|
||||
});
|
||||
|
||||
function_ptr_luafun scattergather3(lua_func_misc, "memory.write_sg", [](lua_state& L,
|
||||
lua::fnptr scattergather3(lua_func_misc, "memory.write_sg", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
return memory_scattergather<true, false>(L, fname);
|
||||
});
|
||||
|
@ -659,10 +659,10 @@ namespace
|
|||
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");
|
||||
lua::_class<lua_mmap_struct> class_mmap_struct("MMAP_STRUCT");
|
||||
}
|
||||
|
||||
int lua_mmap_struct::map(lua_state& L, const std::string& fname)
|
||||
int lua_mmap_struct::map(lua::state& L, const std::string& fname)
|
||||
{
|
||||
const char* name = L.tostring(2);
|
||||
int base = 0;
|
||||
|
@ -708,9 +708,9 @@ int lua_mmap_struct::map(lua_state& L, const std::string& fname)
|
|||
return 0;
|
||||
}
|
||||
|
||||
lua_mmap_struct::lua_mmap_struct(lua_state& L)
|
||||
lua_mmap_struct::lua_mmap_struct(lua::state& L)
|
||||
{
|
||||
objclass<lua_mmap_struct>().bind_multi(L, {
|
||||
lua::objclass<lua_mmap_struct>().bind_multi(L, {
|
||||
{"__index", &lua_mmap_struct::index},
|
||||
{"__newindex", &lua_mmap_struct::newindex},
|
||||
{"__call", &lua_mmap_struct::map},
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
int handle_push_vma(lua_state& L, memory_region& r)
|
||||
int handle_push_vma(lua::state& L, memory_region& r)
|
||||
{
|
||||
L.newtable();
|
||||
L.pushstring("name");
|
||||
|
@ -49,10 +49,10 @@ namespace
|
|||
class lua_vma
|
||||
{
|
||||
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);
|
||||
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);
|
||||
std::string print()
|
||||
{
|
||||
return vma;
|
||||
|
@ -67,22 +67,22 @@ namespace
|
|||
class lua_vma_list
|
||||
{
|
||||
public:
|
||||
lua_vma_list(lua_state& L);
|
||||
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);
|
||||
lua_vma_list(lua::state& L);
|
||||
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);
|
||||
std::string print()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
lua_class<lua_vma> class_vma("VMA");
|
||||
lua_class<lua_vma_list> class_vmalist("VMALIST");
|
||||
lua::_class<lua_vma> class_vma("VMA");
|
||||
lua::_class<lua_vma_list> class_vmalist("VMALIST");
|
||||
|
||||
lua_vma::lua_vma(lua_state& L, memory_region* r)
|
||||
lua_vma::lua_vma(lua::state& L, memory_region* r)
|
||||
{
|
||||
objclass<lua_vma>().bind_multi(L, {
|
||||
lua::objclass<lua_vma>().bind_multi(L, {
|
||||
{"info", &lua_vma::info},
|
||||
{"read", &lua_vma::scattergather<false, false>},
|
||||
{"sread", &lua_vma::scattergather<false, true>},
|
||||
|
@ -118,7 +118,7 @@ namespace
|
|||
ro = r->readonly;
|
||||
}
|
||||
|
||||
int lua_vma::info(lua_state& L, const std::string& fname)
|
||||
int lua_vma::info(lua::state& L, const std::string& fname)
|
||||
{
|
||||
for(auto i : lsnes_memory.get_regions())
|
||||
if(i->name == vma)
|
||||
|
@ -126,7 +126,7 @@ namespace
|
|||
(stringfmt() << 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, const std::string& fname)
|
||||
{
|
||||
uint64_t addr = L.get_numeric_argument<uint64_t>(2, fname.c_str());
|
||||
if(addr > vmasize || addr > vmasize - sizeof(T))
|
||||
|
@ -149,7 +149,7 @@ namespace
|
|||
(stringfmt() << fname << ": Parameter #3 must be integer if present").throwex();
|
||||
}
|
||||
|
||||
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, const std::string& fname)
|
||||
{
|
||||
uint64_t val = 0;
|
||||
int ptr = 2;
|
||||
|
@ -179,16 +179,16 @@ namespace
|
|||
return write ? 0 : 1;
|
||||
}
|
||||
|
||||
lua_vma_list::lua_vma_list(lua_state& L)
|
||||
lua_vma_list::lua_vma_list(lua::state& L)
|
||||
{
|
||||
objclass<lua_vma_list>().bind_multi(L, {
|
||||
lua::objclass<lua_vma_list>().bind_multi(L, {
|
||||
{"__index", &lua_vma_list::index},
|
||||
{"__newindex", &lua_vma_list::newindex},
|
||||
{"__call", &lua_vma_list::call},
|
||||
});
|
||||
}
|
||||
|
||||
int lua_vma_list::call(lua_state& L, const std::string& fname)
|
||||
int lua_vma_list::call(lua::state& L, const std::string& fname)
|
||||
{
|
||||
L.newtable();
|
||||
size_t key = 1;
|
||||
|
@ -200,7 +200,7 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
int lua_vma_list::index(lua_state& L, const std::string& fname)
|
||||
int lua_vma_list::index(lua::state& L, const std::string& fname)
|
||||
{
|
||||
std::string vma = L.get_string(2, fname.c_str());
|
||||
auto l = lsnes_memory.get_regions();
|
||||
|
@ -208,20 +208,20 @@ namespace
|
|||
std::list<memory_region*>::iterator i;
|
||||
for(i = l.begin(), j = 0; i != l.end(); i++, j++)
|
||||
if((*i)->name == vma) {
|
||||
lua_class<lua_vma>::create(L, *i);
|
||||
lua::_class<lua_vma>::create(L, *i);
|
||||
return 1;
|
||||
}
|
||||
(stringfmt() << 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, const std::string& fname)
|
||||
{
|
||||
throw std::runtime_error("Writing is not allowed");
|
||||
}
|
||||
|
||||
function_ptr_luafun memory2(lua_func_misc, "memory2", [](lua_state& L, const std::string& fname) ->
|
||||
lua::fnptr memory2(lua_func_misc, "memory2", [](lua::state& L, const std::string& fname) ->
|
||||
int {
|
||||
lua_class<lua_vma_list>::create(L);
|
||||
lua::_class<lua_vma_list>::create(L);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -7,37 +7,37 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_luafun mcurframe(lua_func_misc, "movie.currentframe", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr mcurframe(lua_func_misc, "movie.currentframe", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
auto& m = get_movie();
|
||||
L.pushnumber(m.get_current_frame());
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun mfc(lua_func_misc, "movie.framecount", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr mfc(lua_func_misc, "movie.framecount", [](lua::state& L, const std::string& fname) -> int {
|
||||
auto& m = get_movie();
|
||||
L.pushnumber(m.get_frame_count());
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun mrrs(lua_func_misc, "movie.rerecords", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr mrrs(lua_func_misc, "movie.rerecords", [](lua::state& L, const std::string& fname) -> int {
|
||||
L.pushnumber(rrdata.count());
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun mro(lua_func_misc, "movie.readonly", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr mro(lua_func_misc, "movie.readonly", [](lua::state& L, const std::string& fname) -> int {
|
||||
auto& m = get_movie();
|
||||
L.pushboolean(m.readonly_mode() ? 1 : 0);
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun mrw(lua_func_misc, "movie.readwrite", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr mrw(lua_func_misc, "movie.readwrite", [](lua::state& L, const std::string& fname) -> int {
|
||||
auto& m = get_movie();
|
||||
m.readonly_mode(false);
|
||||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun mfs(lua_func_misc, "movie.frame_subframes", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr mfs(lua_func_misc, "movie.frame_subframes", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint64_t frame = L.get_numeric_argument<uint64_t>(1, "movie.frame_subframes");
|
||||
auto& m = get_movie();
|
||||
|
@ -45,7 +45,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun mrs(lua_func_misc, "movie.read_subframes", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr mrs(lua_func_misc, "movie.read_subframes", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint64_t frame = L.get_numeric_argument<uint64_t>(1, "movie.frame_subframes");
|
||||
uint64_t subframe = L.get_numeric_argument<uint64_t>(2, "movie.frame_subframes");
|
||||
|
@ -61,34 +61,34 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun rrc(lua_func_misc, "movie.read_rtc", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr rrc(lua_func_misc, "movie.read_rtc", [](lua::state& L, const std::string& fname) -> int {
|
||||
L.pushnumber(our_movie.rtc_second);
|
||||
L.pushnumber(our_movie.rtc_subsecond);
|
||||
return 2;
|
||||
});
|
||||
|
||||
function_ptr_luafun musv(lua_func_misc, "movie.unsafe_rewind", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr musv(lua_func_misc, "movie.unsafe_rewind", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
if(L.isnoneornil(1)) {
|
||||
//Start process to mark save.
|
||||
mainloop_signal_need_rewind(NULL);
|
||||
} else if(lua_class<lua_unsaferewind>::is(L, 1)) {
|
||||
} else if(lua::_class<lua_unsaferewind>::is(L, 1)) {
|
||||
//Load the save.
|
||||
lua_obj_pin<lua_unsaferewind>* u = new lua_obj_pin<lua_unsaferewind>(
|
||||
lua_class<lua_unsaferewind>::pin(L, 1, fname.c_str()));
|
||||
lua::objpin<lua_unsaferewind>* u = new lua::objpin<lua_unsaferewind>(
|
||||
lua::_class<lua_unsaferewind>::pin(L, 1, fname.c_str()));
|
||||
mainloop_signal_need_rewind(u);
|
||||
} else
|
||||
throw std::runtime_error("movie.unsafe_rewind: Expected nil or UNSAFEREWIND as 1st argument");
|
||||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun movie_to_rewind(lua_func_misc, "movie.to_rewind", [](lua_state& L,
|
||||
lua::fnptr movie_to_rewind(lua_func_misc, "movie.to_rewind", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
std::string filename = L.get_string(1, fname.c_str());
|
||||
moviefile mfile(filename, *our_rom.rtype);
|
||||
if(!mfile.is_savestate)
|
||||
throw std::runtime_error("movie.to_rewind only allows savestates");
|
||||
lua_unsaferewind* u2 = lua_class<lua_unsaferewind>::create(L);
|
||||
lua_unsaferewind* u2 = lua::_class<lua_unsaferewind>::create(L);
|
||||
u2->state = mfile.savestate;
|
||||
if(u2->state.size() >= 32)
|
||||
u2->state.resize(u2->state.size() - 32);
|
||||
|
|
|
@ -28,13 +28,13 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
function_ptr_luafun rboolean(lua_func_misc, "random.boolean", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr rboolean(lua_func_misc, "random.boolean", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
L.pushboolean(randnum() % 2);
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun rinteger(lua_func_misc, "random.integer", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr rinteger(lua_func_misc, "random.integer", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
int64_t low = 0;
|
||||
int64_t high = 0;
|
||||
|
@ -53,7 +53,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun rfloat(lua_func_misc, "random.float", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr rfloat(lua_func_misc, "random.float", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
double _bits = 0;
|
||||
uint64_t* bits = (uint64_t*)&_bits;
|
||||
|
@ -63,7 +63,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun ramong(lua_func_misc, "random.among", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr ramong(lua_func_misc, "random.among", [](lua::state& L, const std::string& fname)
|
||||
{
|
||||
unsigned args = 1;
|
||||
while(L.type(args) != LUA_TNONE)
|
||||
|
@ -78,7 +78,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun ramongt(lua_func_misc, "random.amongtable", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr ramongt(lua_func_misc, "random.amongtable", [](lua::state& L, const std::string& fname)
|
||||
{
|
||||
if(L.type(1) != LUA_TTABLE)
|
||||
throw std::runtime_error("random.amongtable: First argument must be table");
|
||||
|
|
|
@ -4,20 +4,20 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_luafun lua_gui_screenshot(lua_func_misc, "gui.screenshot", [](lua_state& L,
|
||||
lua::fnptr lua_gui_screenshot(lua_func_misc, "gui.screenshot", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
std::string fn = L.get_string(1, fname.c_str());
|
||||
take_screenshot(fn);
|
||||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_gui_screenshot_b(lua_func_misc, "gui.screenshot_bitmap", [](lua_state& L,
|
||||
lua::fnptr lua_gui_screenshot_b(lua_func_misc, "gui.screenshot_bitmap", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
framebuffer::raw& _fb = render_get_latest_screen();
|
||||
try {
|
||||
auto osize = std::make_pair(_fb.get_width(), _fb.get_height());
|
||||
std::vector<uint32_t> tmp(_fb.get_width());
|
||||
lua_dbitmap* b = lua_class<lua_dbitmap>::create(L, osize.first, osize.second);
|
||||
lua_dbitmap* b = lua::_class<lua_dbitmap>::create(L, osize.first, osize.second);
|
||||
for(size_t y = 0; y < osize.second; y++) {
|
||||
_fb.get_format()->decode(&tmp[0], _fb.get_start() + _fb.get_stride() * y,
|
||||
_fb.get_width());
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_luafun ss(lua_func_misc, "settings.set", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr ss(lua_func_misc, "settings.set", [](lua::state& L, const std::string& fname) -> int {
|
||||
std::string name = L.get_string(1, fname.c_str());
|
||||
std::string value = L.get_string(2, fname.c_str());
|
||||
try {
|
||||
|
@ -17,7 +17,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun sg(lua_func_misc, "settings.get", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr sg(lua_func_misc, "settings.get", [](lua::state& L, const std::string& fname) -> int {
|
||||
std::string name = L.get_string(1, fname.c_str());
|
||||
try {
|
||||
std::string value = lsnes_vsetc.get(name);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_luafun enumerate(lua_func_misc, "subtitle.byindex", [](lua_state& L, const std::string& fname)
|
||||
lua::fnptr enumerate(lua_func_misc, "subtitle.byindex", [](lua::state& L, const std::string& fname)
|
||||
-> int {
|
||||
uint64_t n = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
uint64_t j = 0;
|
||||
|
@ -18,7 +18,7 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun sget(lua_func_misc, "subtitle.get", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr sget(lua_func_misc, "subtitle.get", [](lua::state& L, const std::string& fname) -> int {
|
||||
uint64_t frame = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
uint64_t length = L.get_numeric_argument<uint64_t>(2, fname.c_str());
|
||||
std::string x = get_subtitle_for(frame, length);
|
||||
|
@ -26,7 +26,7 @@ namespace
|
|||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun sset(lua_func_misc, "subtitle.set", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr sset(lua_func_misc, "subtitle.set", [](lua::state& L, const std::string& fname) -> int {
|
||||
uint64_t frame = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
uint64_t length = L.get_numeric_argument<uint64_t>(2, fname.c_str());
|
||||
std::string text = L.get_string(3, fname.c_str());
|
||||
|
@ -34,7 +34,7 @@ namespace
|
|||
return 0;
|
||||
});
|
||||
|
||||
function_ptr_luafun sdel(lua_func_misc, "subtitle.delete", [](lua_state& L, const std::string& fname) -> int {
|
||||
lua::fnptr sdel(lua_func_misc, "subtitle.delete", [](lua::state& L, const std::string& fname) -> int {
|
||||
uint64_t frame = L.get_numeric_argument<uint64_t>(1, fname.c_str());
|
||||
uint64_t length = L.get_numeric_argument<uint64_t>(2, fname.c_str());
|
||||
set_subtitle_for(frame, length, "");
|
||||
|
|
|
@ -6,12 +6,12 @@ namespace
|
|||
class lua_zip_writer
|
||||
{
|
||||
public:
|
||||
lua_zip_writer(lua_state& L, const std::string& filename, unsigned compression);
|
||||
lua_zip_writer(lua::state& L, const std::string& filename, unsigned compression);
|
||||
~lua_zip_writer()
|
||||
{
|
||||
if(w) delete w;
|
||||
}
|
||||
int commit(lua_state& L, const std::string& fname)
|
||||
int commit(lua::state& L, const std::string& fname)
|
||||
{
|
||||
if(!w)
|
||||
throw std::runtime_error("Zip writer already finished");
|
||||
|
@ -22,14 +22,14 @@ namespace
|
|||
delete w;
|
||||
w = NULL;
|
||||
}
|
||||
int rollback(lua_state& L, const std::string& fname)
|
||||
int rollback(lua::state& L, const std::string& fname)
|
||||
{
|
||||
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, const std::string& fname)
|
||||
{
|
||||
if(!w)
|
||||
throw std::runtime_error("Zip writer already finished");
|
||||
|
@ -38,7 +38,7 @@ namespace
|
|||
w->close_file();
|
||||
file_open = NULL;
|
||||
}
|
||||
int create_file(lua_state& L, const std::string& fname)
|
||||
int create_file(lua::state& L, const std::string& fname)
|
||||
{
|
||||
if(!w)
|
||||
throw std::runtime_error("Zip writer already finished");
|
||||
|
@ -49,7 +49,7 @@ namespace
|
|||
}
|
||||
file_open = &w->create_file(filename);
|
||||
}
|
||||
int write(lua_state& L, const std::string& fname)
|
||||
int write(lua::state& L, const std::string& fname)
|
||||
{
|
||||
if(!w)
|
||||
throw std::runtime_error("Zip writer already finished");
|
||||
|
@ -70,14 +70,14 @@ namespace
|
|||
std::string file;
|
||||
};
|
||||
|
||||
lua_class<lua_zip_writer> class_zipwriter("ZIPWRITER");
|
||||
lua::_class<lua_zip_writer> class_zipwriter("ZIPWRITER");
|
||||
|
||||
lua_zip_writer::lua_zip_writer(lua_state& L, const std::string& filename, unsigned compression)
|
||||
lua_zip_writer::lua_zip_writer(lua::state& L, const std::string& filename, unsigned compression)
|
||||
{
|
||||
file = filename;
|
||||
w = new zip::writer(filename, compression);
|
||||
file_open = NULL;
|
||||
objclass<lua_zip_writer>().bind_multi(L, {
|
||||
lua::objclass<lua_zip_writer>().bind_multi(L, {
|
||||
{"commit", &lua_zip_writer::commit},
|
||||
{"rollback", &lua_zip_writer::rollback},
|
||||
{"close_file", &lua_zip_writer::close_file},
|
||||
|
@ -86,7 +86,7 @@ namespace
|
|||
});
|
||||
}
|
||||
|
||||
function_ptr_luafun lua_zip(lua_func_zip, "zip.create", [](lua_state& L,
|
||||
lua::fnptr lua_zip(lua_func_zip, "zip.create", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
unsigned compression = 9;
|
||||
std::string filename = L.get_string(1, fname.c_str());
|
||||
|
@ -95,11 +95,11 @@ namespace
|
|||
compression = 0;
|
||||
if(compression > 9)
|
||||
compression = 9;
|
||||
lua_class<lua_zip_writer>::create(L, filename, compression);
|
||||
lua::_class<lua_zip_writer>::create(L, filename, compression);
|
||||
return 1;
|
||||
});
|
||||
|
||||
function_ptr_luafun lua_enumerate_zip(lua_func_zip, "zip.enumerate", [](lua_state& L,
|
||||
lua::fnptr lua_enumerate_zip(lua_func_zip, "zip.enumerate", [](lua::state& L,
|
||||
const std::string& fname) -> int {
|
||||
std::string filename = L.get_string(1, fname.c_str());
|
||||
bool invert = false;
|
||||
|
|
Loading…
Add table
Reference in a new issue