[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re: lua_pushobject
From:       "Victor Bombi" <sonoro () telefonica ! net>
Date:       2014-02-23 15:26:19
Message-ID: 9C02A30B3DEC45FC977D8293AE063F61 () victorPortatil
[Download RAW message or body]

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 ----- 
  From: Nikolay Zapolnov 
  To: Lua mailing list 
  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.





  [1] http://www.parashift.com/c++-faq/placement-new.html



  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


[Attachment #3 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6002.18494" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Thank you.&nbsp;I was not aware that my structure 
needed to be constructed because it was quite simple :-o</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;soundFileSt *sndf = (soundFileSt 
*)lua_newuserdata(L, sizeof(soundFileSt));<BR>&nbsp;sndf = new(sndf) 
soundFileSt();<BR>&nbsp;luaL_getmetatable(L, <FONT face="Times New Roman" 
size=3>"soundFileSt "</FONT>);<BR>&nbsp;lua_setmetatable(L, -2);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>is working the same as lua_pushobject</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Thanks again for answering!!</FONT></DIV>
<BLOCKQUOTE dir=ltr 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 \
2px solid; MARGIN-RIGHT: 0px">  <DIV style="FONT: 10pt arial">----- Original Message \
----- </DIV>  <DIV 
  style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
  <A title=zapolnov@gmail.com href="mailto:zapolnov@gmail.com">Nikolay 
  Zapolnov</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>To:</B> <A title=lua-l@lists.lua.org 
  href="mailto:lua-l@lists.lua.org">Lua mailing list</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>Sent:</B> Sunday, February 23, 2014 4:07 
  PM</DIV>
  <DIV style="FONT: 10pt arial"><B>Subject:</B> Re: lua_pushobject</DIV>
  <DIV><BR></DIV>
  <DIV dir=ltr>Hi!
  <DIV><BR></DIV>
  <DIV>The lua_pushobject macro you mentioned uses the C++ placement new 
  operator [1] to call constructor of the object.</DIV>
  <DIV><BR></DIV>
  <DIV>Your code does not call constructor of the object.<BR></DIV>
  <DIV><BR></DIV>
  <DIV><BR></DIV>
  <DIV class=gmail_extra>[1]&nbsp;<A 
  href="http://www.parashift.com/c++-faq/placement-new.html">http://www.parashift.com/c++-faq/placement-new.html</A></DIV>
  <DIV class=gmail_extra><BR><BR>
  <DIV class=gmail_quote>On Sun, Feb 23, 2014 at 7:03 PM, Victor Bombi <SPAN 
  dir=ltr>&lt;<A href="mailto:sonoro@telefonica.net" 
  target=_blank>sonoro@telefonica.net</A>&gt;</SPAN> wrote:<BR>
  <BLOCKQUOTE class=gmail_quote 
  style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: rgb(204,204,204) \
1px solid">Hello,<BR><BR>May   be someone could help me to understand.<BR><BR>I have \
used lua_pushobject   described in <A \
href="http://lua-users.org/wiki/DoItYourselfCppBinding"   \
target=_blank>http://lua-users.org/wiki/<U></U>DoItYourselfCppBinding</A><BR><BR>I   \
am not able to understand the difference between:<BR><BR>soundFileSt *sndf =   \
(soundFileSt *)lua_newuserdata(L,   sizeof(soundFileSt));<BR>luaL_getmetatable(L, \
"soundFileSt   ");<BR>lua_setmetatable(L, -2);<BR><BR>and<BR><BR>soundFileSt *sndf = 
    (soundFileSt *)lua_pushobject(L, soundFileSt)();<BR><BR>They must be 
    different because the first makes my module to crash but not the 
    second.<BR><BR>Thank you for your attention<SPAN class=""><FONT 
    color=#888888><BR>victor 
  bombi<BR><BR><BR><BR></FONT></SPAN></BLOCKQUOTE></DIV><BR>
  <DIV dir=ltr><BR>
  <DIV><BR></DIV></DIV></DIV></DIV></BLOCKQUOTE></BODY></HTML>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic