lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I changed the method as you suggested 
CLObject :GetListofNumbers(lua_State *L)//
{
 
              CLNumList*o = new CLNumList(L);
CLNL*ud = static_cast< CLNL*>(lua_newuserdata(L, sizeof(CLNumList)));  // create new userdata
real_object->GetListofNumbers(*o->real_object); //CLObject
ud->pT = o;
// lua_pushlightuserdata(L, ud);
// luaL_getmetatable(L, NUMLIST );
// lua_setmetatable(L, -2);

CLNumList::push(L, o);
return 1;
}

i am receiving this

error C2039: 'push' : is not a member of 'CLNumList'



On Fri, Oct 30, 2009 at 6:26 PM, Sivan Thiruvengadam <rajskm@gmail.com> wrote:
Thanks.  

Let me change this by pushing the object as you suggest and see if things work as expected. 

BTW, I always hit the else part of the CLNumList constructor, since i am not passing any CLNumList instance from LUA.

I will update you as soon as i test this.

Thanks once again


2009/10/30 Ignacio Burgueño <ignaciob@inconcertcc.com>
Sivan Thiruvengadam wrote:

Ignacio,
*
*
Yes, you are absolutely right.
CLNumList:: CLNumList(lua_State *L)
{
       if (lua_isuserdata(L,1))
 {

CLNL*t = static_cast< CLNL*>(lua_touserdata(L, 1));
real_object = new CNumList(*t->pT->real_object);

 }
 else
 real_object = new CNumList();
}


I think that is the problem. See, the constructor of CLNumList is assuming that at stackpos 1 there is a CLNumList.
In the case of your call to GetListofNumbers, at that position there is an instance of CLObject. I fail to see how that ends up messing the Lua side of things, but I think it is definitely wrong.

Could you just use push(L, new CLNumList) in GetListofNumbers ?


Something like:

CLObject :GetListofNumbers(lua_State *L)//
{
 CLNumList*o = new CLNumList();
// initialize it properly with the corresponding CNumList pointer
 CLNumList::push(L, o);
return 1;
}