summaryrefslogtreecommitdiff
path: root/src/cat/LuaLuna.h
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-08-31 21:02:02 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-31 21:02:02 (GMT)
commit355c43723fd7aa5c412649924c1aa9238657b8ca (patch)
tree6860645c9f9dc5e224471af5170c578a2d13435e /src/cat/LuaLuna.h
parente8628274ada57b6a526e7cdb261875ac95f05db5 (diff)
downloadpowder-355c43723fd7aa5c412649924c1aa9238657b8ca.zip
powder-355c43723fd7aa5c412649924c1aa9238657b8ca.tar.gz
More interface API
Diffstat (limited to 'src/cat/LuaLuna.h')
-rw-r--r--src/cat/LuaLuna.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/cat/LuaLuna.h b/src/cat/LuaLuna.h
index d15a7c6..591dad2 100644
--- a/src/cat/LuaLuna.h
+++ b/src/cat/LuaLuna.h
@@ -75,6 +75,33 @@ public:
return ud->pT; // pointer to T object
}
+ static void * tryGet(lua_State * L, int narg)
+ {
+ if(checkType(L, narg, T::className))
+ {
+ userdataType *ud = static_cast<userdataType*>(luaL_checkudata(L, narg, T::className));
+ if(!ud)
+ luaL_typerror(L, narg, T::className);
+ return ud; // pointer to T object
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+
+ static bool checkType (lua_State * L, int idx, const char *name)
+ {
+ // returns true if a userdata is of a certain type
+ int res;
+ if (lua_type(L, idx) != LUA_TUSERDATA) return false;
+ lua_getmetatable(L, idx);
+ luaL_newmetatable (L, name);
+ res = lua_equal(L, -2, -1);
+ lua_pop(L, 2); // pop both tables (metatables) off
+ return res;
+ }
+
static inline T * get(void * userData)
{
return ((userdataType*)userData)->pT;