From fbacb13d2d64666883ab7f2a662da92974837993 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 31 Jan 2020 12:28:34 +0100 Subject: [PATCH] Extend Lua binding for static methods This add support for Lua bindings for static member functions in weak/share ptr class bindings. --- libs/lua/LuaBridge/detail/Namespace.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 (); } + template + WSPtrClass & 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 ::f, 1); + rawsetfield (L, -2, name); + + set_weak_class (); + new (lua_newuserdata (L, sizeof (fp))) FP (fp); + lua_pushcclosure (L, &CFunc::Call ::f, 1); + rawsetfield (L, -2, name); + return *this; + } + WSPtrClass & addNilPtrConstructor () { FUNDOC ("Weak/Shared Pointer NIL Constructor", "", void (*) ())