diff options
author | Robin Gareus <robin@gareus.org> | 2020-01-31 12:28:34 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2020-02-06 17:30:21 +0100 |
commit | fbacb13d2d64666883ab7f2a662da92974837993 (patch) | |
tree | da58c38b2b80e4c5db425fa426d48d9a63852ffa /libs/lua/LuaBridge | |
parent | ee43db8b5410ce3a6b1215c7cf943186c35e76e0 (diff) |
Extend Lua binding for static methods
This add support for Lua bindings for static member
functions in weak/share ptr class bindings.
Diffstat (limited to 'libs/lua/LuaBridge')
-rw-r--r-- | libs/lua/LuaBridge/detail/Namespace.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libs/lua/LuaBridge/detail/Namespace.h b/libs/lua/LuaBridge/detail/Namespace.h index 46fdaa5252..fdb9e82012 100644 --- a/libs/lua/LuaBridge/detail/Namespace.h +++ b/libs/lua/LuaBridge/detail/Namespace.h @@ -1304,6 +1304,22 @@ private: return addConstructor <void (*) ()> (); } + template <class FP> + WSPtrClass <T>& addStaticFunction (char const* name, FP const fp) + { + FUNDOC ("Static Member Function", name, FP) + set_shared_class (); + new (lua_newuserdata (L, sizeof (fp))) FP (fp); + lua_pushcclosure (L, &CFunc::Call <FP>::f, 1); + rawsetfield (L, -2, name); + + set_weak_class (); + new (lua_newuserdata (L, sizeof (fp))) FP (fp); + lua_pushcclosure (L, &CFunc::Call <FP>::f, 1); + rawsetfield (L, -2, name); + return *this; + } + WSPtrClass <T>& addNilPtrConstructor () { FUNDOC ("Weak/Shared Pointer NIL Constructor", "", void (*) ()) |