lua-users home
lua-l archive

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


Thank you. I was not aware that my structure needed to be constructed because it was quite simple :-o
 
 soundFileSt *sndf = (soundFileSt *)lua_newuserdata(L, sizeof(soundFileSt));
 sndf = new(sndf) soundFileSt();
 luaL_getmetatable(L, "soundFileSt ");
 lua_setmetatable(L, -2);
 
is working the same as lua_pushobject
 
Thanks again for answering!!
----- Original Message -----
Sent: Sunday, February 23, 2014 4:07 PM
Subject: Re: lua_pushobject

Hi!

The lua_pushobject macro you mentioned uses the C++ placement new operator [1] to call constructor of the object.

Your code does not call constructor of the object.




On Sun, Feb 23, 2014 at 7:03 PM, Victor Bombi <sonoro@telefonica.net> wrote:
Hello,

May be someone could help me to understand.

I have used lua_pushobject described in http://lua-users.org/wiki/DoItYourselfCppBinding

I am not able to understand the difference between:

soundFileSt *sndf = (soundFileSt *)lua_newuserdata(L, sizeof(soundFileSt));
luaL_getmetatable(L, "soundFileSt ");
lua_setmetatable(L, -2);

and

soundFileSt *sndf = (soundFileSt *)lua_pushobject(L, soundFileSt)();

They must be different because the first makes my module to crash but not the second.

Thank you for your attention
victor bombi