summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2009-12-01 00:31:09 +0100
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2009-12-01 00:31:09 +0100
commit935d1dbc7dd8357619b2a6892d017c511a7ef57a (patch)
tree28fef50e82466038d361ecfcd8e5f24f68fdda95 /include
parent3699ebd1770218368902469a32daf13ce6057408 (diff)
Protecting the pushes in order to make sure we have enough stack space every time.
Diffstat (limited to 'include')
-rw-r--r--include/BLua.h23
1 files changed, 12 insertions, 11 deletions
diff --git a/include/BLua.h b/include/BLua.h
index c12a8b7..1cc74f4 100644
--- a/include/BLua.h
+++ b/include/BLua.h
@@ -82,21 +82,22 @@ class Lua : public Base {
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() { 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() { checkstack(); lua_pushnil(L); }
+ void push(lua_Number n) { checkstack(); lua_pushnumber(L, n); }
+ void push(const String & s) { checkstack(); lua_pushlstring(L, s.to_charp(), s.strlen()); }
+ void push(bool b) { checkstack(); lua_pushboolean(L, b); }
void push(const char *, int size = -1);
- void push(void * p) { lua_pushlightuserdata(L, p); }
- void push(lua_CFunction f, int n = 0) { lua_pushcclosure(L, f, n); }
+ void push(void * p) { checkstack(); lua_pushlightuserdata(L, p); }
+ void push(lua_CFunction f, int n = 0) { checkstack(); 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); }
+ int checkstack(int extra = 1) { return lua_checkstack(L, extra); }
+ void copy(int n = -1) { checkstack(); lua_pushvalue(L, n); }
void remove(int n = 1) { lua_remove(L, n); }
- void insert(int n = 1) { lua_insert(L, n); }
+ void insert(int n = 1) { checkstack(); lua_insert(L, n); }
void replace(int n = 1) { lua_replace(L, n); }
- void newtable() { lua_newtable(L); }
- void * newuser(size_t s) { return lua_newuserdata(L, s); }
+ void newtable() { checkstack(); lua_newtable(L); }
+ void * newuser(size_t s) { checkstack(); return lua_newuserdata(L, s); }
void settable(int = -3, bool raw = false);
void gettable(int = -2, bool raw = false);
void setvar() { lua_settable(L, LUA_GLOBALSINDEX); }
@@ -138,7 +139,7 @@ class Lua : public Base {
static Lua * find(lua_State *) throw (GeneralException);
void showstack(int level = M_INFO);
void showerror();
- int getmetatable(int i = -1) { return lua_getmetatable(L, i); }
+ int getmetatable(int i = -1) { checkstack(); 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); }