summaryrefslogtreecommitdiff
path: root/libs/lua
diff options
context:
space:
mode:
Diffstat (limited to 'libs/lua')
-rw-r--r--libs/lua/LuaBridge/detail/Namespace.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/libs/lua/LuaBridge/detail/Namespace.h b/libs/lua/LuaBridge/detail/Namespace.h
index 7f8d44859c..9a9b3c44cb 100644
--- a/libs/lua/LuaBridge/detail/Namespace.h
+++ b/libs/lua/LuaBridge/detail/Namespace.h
@@ -482,6 +482,14 @@ private:
return 1;
}
+ template <class T>
+ static int ctorNilPtrPlacementProxy (lua_State* L)
+ {
+ const T* newobject = new T ();
+ Stack<T>::push (L, *newobject);
+ return 1;
+ }
+
//--------------------------------------------------------------------------
/**
Pop the Lua stack.
@@ -1279,6 +1287,24 @@ private:
return addConstructor <void (*) ()> ();
}
+ WSPtrClass <T>& addNilPtrConstructor ()
+ {
+ FUNDOC ("Weak/Shared Pointer Constructor", "", MemFn)
+ set_shared_class ();
+ lua_pushcclosure (L,
+ &shared. template ctorNilPtrPlacementProxy <boost::shared_ptr<T> >, 0);
+ rawsetfield(L, -2, "__call");
+
+ set_weak_class ();
+ // NOTE: this constructs an empty weak-ptr,
+ // ideally we'd construct a weak-ptr from a referenced shared-ptr
+ lua_pushcclosure (L,
+ &weak. template ctorNilPtrPlacementProxy <boost::weak_ptr<T> >, 0);
+ rawsetfield(L, -2, "__call");
+
+ return *this;
+ }
+
WSPtrClass <T>& addExtCFunction (char const* name, int (*const fp)(lua_State*))
{
DATADOC ("Weak/Shared Ext C Function", name, fp)