13
0
livetrax/libs/lua/LuaBridge/detail
Robin Gareus 520dcf8cdf 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)
2016-07-18 23:52:40 +02:00
..
CFunctions.h add lua/C++ dynamic_cast<> 2016-06-01 13:59:31 +02:00
ClassInfo.h Change LuaBridge_API to be __declspec(dllexport) or __declspec(dllimport, as required 2016-04-12 17:55:16 +01:00
Constructor.h NO-OP whitespace 2016-02-22 22:06:47 +01:00
dump.h customize LuaBridge 2016-02-22 22:06:47 +01:00
FuncArgs.h LuaBridge: support argument references via table return 2016-02-22 22:06:47 +01:00
FuncTraits.h allow lua binding functions with up to 9 parameters 2016-05-31 23:51:22 +02:00
Iterator.h NO-OP whitespace 2016-02-22 22:06:47 +01:00
LuaException.h NO-OP whitespace 2016-02-22 22:06:47 +01:00
LuaHelpers.h NO-OP whitespace 2016-02-22 22:06:47 +01:00
LuaRef.h prepare sharing C++ class instances across lua-interpreters 2016-07-07 15:37:11 +02:00
Namespace.h Use correct type of std::map::count 2016-06-26 16:18:34 +02:00
Stack.h rework lua-bridge C++ variable references 2016-07-18 23:52:40 +02:00
TypeList.h NO-OP whitespace 2016-02-22 22:06:47 +01:00
TypeTraits.h customize LuaBridge 2016-02-22 22:06:47 +01:00
Userdata.h prepare sharing C++ class instances across lua-interpreters 2016-07-07 15:37:11 +02:00