summaryrefslogtreecommitdiff
path: root/libs/lua/LuaBridge/LuaBridge.h
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-07-18 23:30:20 +0200
committerRobin Gareus <robin@gareus.org>2016-07-18 23:52:40 +0200
commit520dcf8cdf0e6cf36210fa7826b63fe2c64ec218 (patch)
treedb61180e4c0b65a98ccb502b907ffe56a3ceac11 /libs/lua/LuaBridge/LuaBridge.h
parentbb29478aa2739f985cc7d41ae48340a85f0b89cb (diff)
rework lua-bridge C++ variable references
Since lua functions are closures, C++ methods that pass arguments by reference cannot be used directly. The previous approach (boost::ref) failed with clang. Assume the following: void foo (float&) { } static inline float& bar () { boost::reference_wrapper<float> r (42); return r.get (); } foo ( bar () ); With gcc, "r" goes out of scope after foo's arguments are processed and all is well. But with clang, "r" already leave scope when *inlined* bar() returns. Solution: allocate some user-data on the lua-stack to hold the reference. There is no reference to this user-data so lua will eventually garbage collect it. (theoretically, creating the table which holds the return-values could trigger an emergency garbage collection when memory is low and free the reference just while they're being pushed to the table, then gain FuncArgs<Params> already dereferenced them all as variable on the C stack -- probably again compiler specific)
Diffstat (limited to 'libs/lua/LuaBridge/LuaBridge.h')
-rw-r--r--libs/lua/LuaBridge/LuaBridge.h1
1 files changed, 0 insertions, 1 deletions
diff --git a/libs/lua/LuaBridge/LuaBridge.h b/libs/lua/LuaBridge/LuaBridge.h
index 706e77cbfd..01f9e90b7d 100644
--- a/libs/lua/LuaBridge/LuaBridge.h
+++ b/libs/lua/LuaBridge/LuaBridge.h
@@ -47,7 +47,6 @@
#include <vector>
#include <inttypes.h>
-#include <boost/ref.hpp>
#include <boost/type_traits.hpp>
#include <boost/shared_ptr.hpp>