summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/BLua.h30
-rw-r--r--lib/BLua.cc28
2 files changed, 30 insertions, 28 deletions
diff --git a/include/BLua.h b/include/BLua.h
index 8e4f549..a0d33c1 100644
--- a/include/BLua.h
+++ b/include/BLua.h
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: BLua.h,v 1.7 2003-12-07 04:44:38 pixel Exp $ */
+/* $Id: BLua.h,v 1.8 2003-12-08 15:12:56 pixel Exp $ */
#ifndef __BLUA_H__
#define __BLUA_H__
@@ -88,7 +88,7 @@ class LuaObject : public Base {
public:
LuaObject() : wantdestruct(false), pushed(false) {}
virtual void push(Lua *) throw (GeneralException);
- static void * getme(Lua *, int = 1) throw (GeneralException);
+ static void * getme(Lua *, int = 1);
void pushdestruct(Lua *) throw (GeneralException);
protected:
virtual void pushmembers(Lua *) = 0;
@@ -177,7 +177,8 @@ class LuaHelpers : public Base {
public:
static int method_multiplex(int caller, lua_State * _L, int (*proceed)(Lua * L, int n, T * obj, int caller), int (*proceed_static)(Lua * L, int n, int caller), lua_functypes_t * tab, bool method) {
Lua * L = Lua::find(_L);
- int n = L->gettop() - (method ? 1 : 0);
+ int add = method ? 1 : 0;
+ int n = L->gettop() - add;
T * obj = (T *) LuaObject::getme(L);
int i;
bool invalid = false;
@@ -191,28 +192,29 @@ class LuaHelpers : public Base {
case LUA_ANY:
break;
case LUA_OBJECT:
- invalid = !L->istable(i + 2);
- if (!invalid) {
+ if (L->istable(i + 1 + add)) {
L->push("__obj");
- L->gettable(i + 2);
- invalid = L->islightuserdata();
+ L->gettable(i + 1 + add);
+ invalid = !L->islightuserdata();
L->pop();
+ } else {
+ invalid = !L->isnil(i + 1 + add);
}
break;
case LUA_TABLE:
- invalid = !L->istable(i + 2);
+ invalid = !L->istable(i + 1 + add);
break;
case LUA_BOOLEAN:
- invalid = !L->isboolean(i + 2);
+ invalid = !L->isboolean(i + 1 + add);
break;
case LUA_NUMBER:
- invalid = !L->isnumber(i + 2);
+ invalid = !L->isnumber(i + 1 + add);
break;
case LUA_STRING:
- invalid = !L->isstring(i + 2);
+ invalid = !L->isstring(i + 1 + add);
break;
case LUA_FUNCTION:
- invalid = !L->isfunction(i + 2);
+ invalid = !L->isfunction(i + 1 + add);
break;
}
}
@@ -236,9 +238,9 @@ class LuaHelpers : public Base {
};
-/*********************************\
+ /*******************************\
|** Let's have a sample of use **|
-\*********************************/
+ \*******************************/
#ifdef THIS_IS_A_SAMPLE_WHICH_DOES_NOT_COMPILE
Luacdfile::Luacdfile(cdfile * h) : LuaHandle(h) { }
diff --git a/lib/BLua.cc b/lib/BLua.cc
index c3f7351..36cc566 100644
--- a/lib/BLua.cc
+++ b/lib/BLua.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: BLua.cc,v 1.9 2003-12-07 05:50:41 pixel Exp $ */
+/* $Id: BLua.cc,v 1.10 2003-12-08 15:12:56 pixel Exp $ */
#include <lualib.h>
@@ -321,12 +321,6 @@ bool Lua::isuserdata(int i) {
bool Lua::islightuserdata(int i) {
return lua_islightuserdata(L, i);
}
- 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);
bool Lua::toboolean(int i) {
return lua_toboolean(L, i);
@@ -484,15 +478,21 @@ void LuaObject::pushme(Lua * L, void * o) {
L->settable();
}
-void * LuaObject::getme(Lua * L, int i) throw (GeneralException) {
+void * LuaObject::getme(Lua * L, int i) {
void * r;
- L->push("__obj");
- L->gettable(i);
- if (!(r = L->touserdata())) {
- throw GeneralException("Lua object already destroyed");
+ if (L->istable(i)) {
+ L->push("__obj");
+ L->gettable(i);
+ if (!(r = L->touserdata())) {
+ L->error("Lua object already destroyed, or table is not an object.");
+ }
+ L->pop();
+ } else if (L->isnil(i)) {
+ r = 0;
+ } else {
+ L->error("Not an object");
}
- L->pop();
return r;
}
@@ -500,7 +500,7 @@ void * LuaObject::getme(Lua * L, int i) throw (GeneralException) {
void LuaObject::pushit(Lua * L, const String & s, lua_CFunction f) {
L->push(s);
L->push(f);
- L->settable();
+ L->settable(-3, true);
}
void LuaObject::pushmeta(Lua * L, const String & s, lua_CFunction f) {