diff options
Diffstat (limited to 'include/BLua.h')
-rw-r--r-- | include/BLua.h | 102 |
1 files changed, 52 insertions, 50 deletions
diff --git a/include/BLua.h b/include/BLua.h index 49573e3..0dcb524 100644 --- a/include/BLua.h +++ b/include/BLua.h @@ -61,6 +61,8 @@ typedef int (*openlualib_t)(lua_State * L); //!Basic LUA engine. /*! This will create an LUA context, and provide mechanisms to interact with it. + This is somehow not threadsafe, and is intended to be so. Don't use this + class directly if you're not in the main Lua thread. */ class Lua : public Base { public: @@ -76,50 +78,50 @@ class Lua : public Base { void open_dir(); void open_bit(); void open_jit(); - int wrap_open(openlualib_t); + int wrap_open(openlualib_t open) { return open(L); } void declarefunc(const String &, lua_CFunction, int = LUA_GLOBALSINDEX); void call(const String &, int = LUA_GLOBALSINDEX, int = 0, int = 0); void call(int = 0, int = 0) throw (GeneralException); - void push(); - void push(lua_Number); - void push(const String &); - void push(bool); + void push() { lua_pushnil(L); } + void push(lua_Number n) { lua_pushnumber(L, n); } + void push(const String & s) { lua_pushlstring(L, s.to_charp(), s.strlen()); } + void push(bool b) { lua_pushboolean(L, b); } void push(const char *, int size = -1); - void push(void *); - void push(lua_CFunction, int = 0); - void pop(int = 1); - int next(int = -2); - void copy(int = -1); - void remove(int = 1); - void insert(int = 1); - void replace(int = 1); - void newtable(); - void * newuser(size_t); + void push(void * p) { lua_pushlightuserdata(L, p); } + void push(lua_CFunction f, int n = 0) { lua_pushcclosure(L, f, n); } + void pop(int n = 1) { lua_pop(L, n); } + int next(int t = -2) { lua_next(L, t); } + void copy(int n = -1) { lua_pushvalue(L, n); } + void remove(int n = 1) { lua_remove(L, n); } + void insert(int n = 1) { lua_insert(L, n); } + void replace(int = 1) { lua_replace(L, n); } + void newtable() { lua_newtable(L); } + void * newuser(size_t s) { return lua_newuserdata(L, s); } void settable(int = -3, bool raw = false); void gettable(int = -2, bool raw = false); - void setvar(); - int gettop(); + void setvar() { lua_settable(L, LUA_GLOBALSINDEX); } + int gettop() { return lua_gettop(L); } void getglobal(const String &) throw (GeneralException); void push_lua_context(); void error(const String &); - int status(); - int type(int = -1); - bool isnil(int = -1); - bool isboolean(int = -1); - bool isnumber(int = -1); - bool isstring(int = -1); - bool istable(int = -1); - bool isfunction(int = -1); - bool iscfunction(int = -1); - bool isuserdata(int = -1); - bool islightuserdata(int = -1); - bool isobject(int = -1); - bool toboolean(int = -1); - lua_Number tonumber(int = -1); - String tostring(int = -1); - lua_CFunction tocfunction(int = -1); - void * touserdata(int = -1); - Lua * tothread(int = -1); + int status() { return 0; } + int type(int i = -1) { return lua_type(L, i); } + bool isnil(int i = -1) { return lua_isnil(L, i); } + bool isboolean(int i = -1) { return lua_isboolean(L, i); } + bool isnumber(int i = -1) { return lua_isnumber(L, i); } + bool isstring(int i = -1) { return lua_isstring(L, i); } + bool istable(int i = -1) { return lua_isttable(L, i); } + bool isfunction(int i = -1) { return lua_isfunction(L, i); } + bool iscfunction(int i = -1) { return lua_iscfunction(L, i); } + bool isuserdata(int i = -1) { return lua_isuserdata(L, i); } + bool islightuserdata(int i = -1) { return lua_islightuserdata(L, i); } + bool isobject(int i = -1); + bool toboolean(int i = -1) { return lua_toboolean(L, i); } + lua_Number tonumber(int i = -1) { return lua_tonumber(L, i); } + String tostring(int i = -1); + lua_CFunction tocfunction(int i = -1) { return lua_tocfunction(L, i); } + void * touserdata(int i = -1) { return lua_touserdata(L, i); } + Lua * tothread(int i = -1) { return find(lua_tothread(L, i)); } String escape_string(const String &); void load(Handle *, bool docall = true) throw (GeneralException); void load(const String &, bool docall = true) throw (GeneralException); @@ -129,30 +131,30 @@ class Lua : public Base { Lua * thread(const String &, int nargs = 0, bool saveit = true); Lua * thread(Handle *, int nargs = 0, bool saveit = true); void weaken(); - int yield(int nresults = 0); + int yield(int nresults = 0) { return lua_yield(L, nresults); } bool resume(int nargs = 0) throw (GeneralException); bool resume(const String &, int nargs = 0); bool resume(Handle *, int nargs = 0); static Lua * find(lua_State *) throw (GeneralException); void showstack(int level = M_INFO); void showerror(); - int getmetatable(int = -1); - int setmetatable(int = -2); - int sethook(lua_Hook func, int mask, int count); + int getmetatable(int i = -1) { return lua_getmetatable(L, i); } + int setmetatable(int i = -2) { return lua_setmetatable(L, i); } + int sethook(lua_Hook func, int mask, int count) { return lua_sethook(L, func, mask, count); } - void do_break(); + void do_break() {/* need to be done within LuaJIT with a hook */} - bool is_protected(); - void openlib(const String & libname, const struct luaL_reg *l, int nup); + bool is_protected() { return _protected; } + void openlib(const String & libname, const struct luaL_reg *l, int nup) { luaL_openlib(L, libname.to_charp(), l, nup); } - void setgcthreshold(int = 0); - int getgcthreshold(); - int getgccount(); + void setgcthreshold(int = 0) { /***TODO***/ } + int getgcthreshold() { return 0; /***TODO***/ } + int getgccount() { return lua_getgccount(L); } - Lua * Father(); + Lua * Father() { return father ? father : this; } - void SetPrinter(LuaPrinter *); - void puts(const char * msg); + void SetPrinter(LuaPrinter * lp) { lprinter = lp; } + void puts(const char * msg) { lprinter->puts(msg); } template<class T> T * recast(int n = 1) { @@ -190,9 +192,9 @@ class Lua : public Base { class LuaException : public GeneralException { public: - LuaException(String); + LuaException(String fn) : GeneralException(fn) { } protected: - LuaException(); + LuaException() { } }; enum Lua_types_t { |