summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-11-13 17:56:08 -0800
committerPixel <pixel@nobis-crew.org>2009-11-13 17:56:08 -0800
commit882715383682541b79642fc0e731ad533e04162e (patch)
tree3ce8c1beca210e7ed65e36223759a2bb7d5288e8
parent9d155a9f9464cfb85bf864c8e0075743dc15a52a (diff)
Speeding up a little bit the Lua class.
-rw-r--r--include/BLua.h102
-rw-r--r--lib/BLua.cc191
2 files changed, 52 insertions, 241 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 {
diff --git a/lib/BLua.cc b/lib/BLua.cc
index 57b9eb8..0a763aa 100644
--- a/lib/BLua.cc
+++ b/lib/BLua.cc
@@ -510,18 +510,6 @@ Lua::Lua(lua_State * __L) : L(__L), _protected(false), _is_thread(true) {
}
-void Lua::SetPrinter(LuaPrinter * lp) {
- lprinter = lp;
-}
-
-void Lua::puts(const char * msg) {
- lprinter->puts(msg);
-}
-
-Lua * Lua::Father() {
- return father ? father : this;
-}
-
Lua * Lua::spawn_from_thread(lua_State * __L) {
Lua * L = new Lua(__L);
L->father = Father();
@@ -552,10 +540,6 @@ Lua::~Lua() {
L = 0;
}
-bool Lua::is_protected() {
- return _protected;
-}
-
Lua::Lua(const Lua & l) throw (GeneralException) {
throw GeneralException("Error: can't duplicate a Lua object.");
}
@@ -636,10 +620,6 @@ void Lua::open_bit() {
lua_pop(L, 1);
}
-int Lua::wrap_open(openlualib_t open) {
- return open(L);
-}
-
void Lua::declarefunc(const String & name, lua_CFunction f, int i) {
lua_pushstring(L, name.to_charp());
lua_pushcfunction(L, f);
@@ -679,22 +659,6 @@ void Lua::call(int nargs, int nresults) throw(GeneralException) {
}
}
-void Lua::push() {
- lua_pushnil(L);
-}
-
-void Lua::push(lua_Number n) {
- lua_pushnumber(L, n);
-}
-
-void Lua::push(const String & s) {
- lua_pushlstring(L, s.to_charp(), s.strlen());
-}
-
-void Lua::push(bool b) {
- lua_pushboolean(L, b);
-}
-
void Lua::push(const char * s, int size) {
if (size < 0) {
lua_pushstring(L, s);
@@ -703,46 +667,6 @@ void Lua::push(const char * s, int size) {
}
}
-void Lua::push(void * p) {
- lua_pushlightuserdata(L, p);
-}
-
-void Lua::push(lua_CFunction f, int n) {
- lua_pushcclosure(L, f, n);
-}
-
-void Lua::pop(int n) {
- lua_pop(L, n);
-}
-
-int Lua::next(int t) {
- return lua_next(L, t);
-}
-
-void Lua::copy(int n) {
- lua_pushvalue(L, n);
-}
-
-void Lua::remove(int n) {
- lua_remove(L, n);
-}
-
-void Lua::insert(int n) {
- lua_insert(L, n);
-}
-
-void Lua::replace(int n) {
- lua_replace(L, n);
-}
-
-void Lua::newtable() {
- lua_newtable(L);
-}
-
-void * Lua::newuser(size_t s) {
- return lua_newuserdata(L, s);
-}
-
void Lua::settable(int i, bool raw) {
if (raw) {
lua_rawset(L, i);
@@ -759,14 +683,6 @@ void Lua::gettable(int i, bool raw) {
}
}
-void Lua::setvar() {
- lua_settable(L, LUA_GLOBALSINDEX);
-}
-
-int Lua::gettop() {
- return lua_gettop(L);
-}
-
void Lua::getglobal(const String & name) throw (GeneralException) {
Buffer b;
b << "return " + name;
@@ -806,50 +722,6 @@ void Lua::error(const String & msg) {
lua_error(L);
}
-int Lua::status() {
- return 0;
-}
-
-int Lua::type(int i) {
- return lua_type(L, i);
-}
-
-bool Lua::isnil(int i) {
- return lua_isnil(L, i);
-}
-
-bool Lua::isboolean(int i) {
- return lua_isboolean(L, i);
-}
-
-bool Lua::isnumber(int i) {
- return lua_isnumber(L, i);
-}
-
-bool Lua::isstring(int i) {
- return lua_isstring(L, i);
-}
-
-bool Lua::istable(int i) {
- return lua_istable(L, i);
-}
-
-bool Lua::isfunction(int i) {
- return lua_isfunction(L, i);
-}
-
-bool Lua::iscfunction(int i) {
- return lua_iscfunction(L, i);
-}
-
-bool Lua::isuserdata(int i) {
- return lua_isuserdata(L, i);
-}
-
-bool Lua::islightuserdata(int i) {
- return lua_islightuserdata(L, i);
-}
-
bool Lua::isobject(int i) {
bool r = false;
if (istable(i)) {
@@ -863,14 +735,6 @@ bool Lua::isobject(int i) {
return r;
}
-bool Lua::toboolean(int i) {
- return lua_toboolean(L, i);
-}
-
-lua_Number Lua::tonumber(int i) {
- return lua_tonumber(L, i);
-}
-
String Lua::tostring(int i) {
const char * r = 0;
size_t l = -1;
@@ -890,18 +754,6 @@ String Lua::tostring(int i) {
return String(r ? r : "<lua-NULL>", l);
}
-lua_CFunction Lua::tocfunction(int i) {
- return lua_tocfunction(L, i);
-}
-
-void * Lua::touserdata(int i) {
- return lua_touserdata(L, i);
-}
-
-Lua * Lua::tothread(int i) {
- return find(lua_tothread(L, i));
-}
-
struct LoadF {
Handle * f;
char buff[BUFFERSIZE];
@@ -1154,10 +1006,6 @@ Lua * Lua::thread(Handle * h, int nargs, bool saveit) {
return L1;
}
-int Lua::yield(int nresults) {
- return lua_yield(L, nresults);
-}
-
bool Lua::resume(int nargs) throw (GeneralException) {
int r;
@@ -1263,41 +1111,6 @@ void Lua::showerror() {
showstack(M_ERROR);
}
-int Lua::getmetatable(int i) {
- return lua_getmetatable(L, i);
-}
-
-int Lua::setmetatable(int i) {
- return lua_setmetatable(L, i);
-}
-
-int Lua::sethook(lua_Hook func, int mask, int count) {
- return lua_sethook(L, func, mask, count);
-}
-
-void Lua::do_break() {
-// lua_break(L);
-}
-
-void Lua::openlib(const String & libname, const luaL_reg *l, int nup) {
- luaL_openlib(L, libname.to_charp(), l, nup);
-}
-
-/* ***TODO*** handle the new garbage collection system. */
-
-void Lua::setgcthreshold(int newthreshold) {
-// lua_setgcthreshold(L, newthreshold);
-}
-
-int Lua::getgcthreshold() {
-// return lua_getgcthreshold(L);
- return 0;
-}
-
-int Lua::getgccount() {
- return lua_getgccount(L);
-}
-
void LuaObject::push(Lua * L) throw (GeneralException) {
if (pushed && wantdestruct) {
throw GeneralException("Error: object is owned by the LUA script and can not be pushed.");
@@ -1372,7 +1185,3 @@ void LuaObject::pushdestruct(Lua * L) throw (GeneralException) {
wantdestruct = true;
}
-
-LuaException::LuaException(String fn) : GeneralException(fn) { }
-
-LuaException::LuaException() { }