summaryrefslogtreecommitdiff
path: root/libs/lua
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-04-14 03:08:02 +0200
committerRobin Gareus <robin@gareus.org>2016-04-14 03:08:02 +0200
commit204c8016c70ea0e91534e30bc5b879da5540e1de (patch)
tree25221bf2379c195cc421a44f530ff3c34725717f /libs/lua
parentafca178e45316b187c92dc17cc0fc5d3e9692790 (diff)
allow to compare C class instances from lua
Diffstat (limited to 'libs/lua')
-rw-r--r--libs/lua/LuaBridge/detail/CFunctions.h13
-rw-r--r--libs/lua/LuaBridge/detail/Namespace.h15
2 files changed, 28 insertions, 0 deletions
diff --git a/libs/lua/LuaBridge/detail/CFunctions.h b/libs/lua/LuaBridge/detail/CFunctions.h
index 29b361b690..6f43919216 100644
--- a/libs/lua/LuaBridge/detail/CFunctions.h
+++ b/libs/lua/LuaBridge/detail/CFunctions.h
@@ -367,6 +367,19 @@ struct CFunc
};
template <class T>
+ struct ClassEqualCheck
+ {
+ static int f (lua_State* L)
+ {
+ T const* const t0 = Userdata::get <T> (L, 1, true);
+ T const* const t1 = Userdata::get <T> (L, 2, true);
+ Stack <bool>::push (L, t0 == t1);
+ return 1;
+ }
+ };
+
+
+ template <class T>
struct PtrNullCheck
{
static int f (lua_State* L)
diff --git a/libs/lua/LuaBridge/detail/Namespace.h b/libs/lua/LuaBridge/detail/Namespace.h
index 722d02e4a7..c859d8d151 100644
--- a/libs/lua/LuaBridge/detail/Namespace.h
+++ b/libs/lua/LuaBridge/detail/Namespace.h
@@ -1039,6 +1039,15 @@ private:
return addConstructor <void (*) ()> ();
}
+ Class <T>& addEqualCheck ()
+ {
+ PRINTDOC("Member Function", _name << "sameinstance", std::string("bool"), std::string("void (*)(" + type_name <T>() + ")"))
+ assert (lua_istable (L, -1));
+ lua_pushcclosure (L, &CFunc::ClassEqualCheck <T>::f, 0);
+ rawsetfield (L, -3, "sameinstance");
+ return *this;
+ }
+
};
/** C Array to/from table */
@@ -1060,6 +1069,8 @@ private:
std::string(""), "int (*)(lua_State*)")
PRINTDOC ("Ext C Function", _name << "set_table",
std::string(""), "int (*)(lua_State*)")
+ PRINTDOC("Member Function", _name << "sameinstance",
+ std::string("bool"), std::string("void (*)(" + type_name <T>() + "*)"))
m_stackSize = parent->m_stackSize + 3;
parent->m_stackSize = 0;
@@ -1117,6 +1128,10 @@ private:
lua_pushcclosure (L, &CFunc::setTable <T>, 0);
rawsetfield (L, -3, "set_table"); // class table
+
+ lua_pushcclosure (L, &CFunc::ClassEqualCheck <T>::f, 0);
+ rawsetfield (L, -3, "sameinstance");
+
}
else
{