Navigation Menu

Skip to content

Commit

Permalink
LuaBridge pushed all fields to lua as a copy. Fix this idiocy.
Browse files Browse the repository at this point in the history
  • Loading branch information
pisto committed Nov 15, 2014
1 parent 83edbbd commit 46db0d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 12 additions & 1 deletion include/LuaBridge/detail/CFunctions.h
Expand Up @@ -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);
Expand All @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions include/LuaBridge/detail/Userdata.h
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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 ());
}
};

Expand Down

0 comments on commit 46db0d9

Please sign in to comment.