Skip to content
Permalink
Browse files
LuaBridge pushed all fields to lua as a copy. Fix this idiocy.
  • Loading branch information
pisto committed Nov 15, 2014
1 parent 83edbbd commit 46db0d96c200f6e273feafd329eef766ab9a4ed4
Showing with 17 additions and 4 deletions.
  1. +12 −1 include/LuaBridge/detail/CFunctions.h
  2. +5 −3 include/LuaBridge/detail/Userdata.h
@@ -446,7 +446,7 @@ struct CFunc
The pointer-to-member is in the first upvalue.
The class userdata object is at the top of the Lua stack.
*/
template <class C, typename T>
template <class C, typename T, typename std::enable_if<!std::is_class<T>::value, int>::type = 0>
static int getProperty (lua_State* L)
{
C const* const c = Userdata::get <C> (L, 1, true);
@@ -455,6 +455,17 @@ struct CFunc
return 1;
}

template <class C, typename T, typename std::enable_if<std::is_class<T>::value, int>::type = 0>
static int getProperty (lua_State* L)
{
bool constResult;
C* c = Userdata::get <C> (L, 1, true, &constResult);
T C::** mp = static_cast <T C::**> (lua_touserdata (L, lua_upvalueindex (1)));
if(constResult) Stack <const T*>::push (L, &(c->**mp));
else Stack <T*>::push (L, &(c->**mp));
return 1;
}

//--------------------------------------------------------------------------
/**
lua_CFunction to set a class data member.
@@ -177,7 +177,8 @@ class Userdata
static Userdata* getClass (lua_State* L,
int index,
void const* baseClassKey,
bool canBeConst)
bool canBeConst,
bool* constResult = 0)
{
assert (index > 0);
Userdata* ud = 0;
@@ -203,6 +204,7 @@ class Userdata
assert (lua_istable (L, -1) || lua_isnil (L, -1));
bool const isConst = lua_isnil (L, -1);
lua_pop (L, 1);
if (constResult) *constResult = isConst;

// Replace the class table with the const table if needed.
if (isConst)
@@ -311,13 +313,13 @@ ud __parent (nil)
const-ness, a Lua error is raised.
*/
template <class T>
static inline T* get (lua_State* L, int index, bool canBeConst)
static inline T* get (lua_State* L, int index, bool canBeConst, bool* constResult = 0)
{
if (lua_isnil (L, index))
return 0;
else
return static_cast <T*> (getClass (L, index,
ClassInfo <T>::getClassKey (), canBeConst)->getPointer ());
ClassInfo <T>::getClassKey (), canBeConst, constResult)->getPointer ());
}
};

0 comments on commit 46db0d9

Please sign in to comment.