lua-users home
lua-l archive

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


No, lua_pushvalue does not copy tables, or other objects. This will
work (tho it's untested):

// assuming the "parent" table is the only value on the stack
lua_pushstring(L, "child");
lua_gettable(L, 1);
lua_pushstring(L, "parent");
lua_pushvalue(L, 1); // copies a reference to the table, not the table itself
lua_settable(L, 2);
lua_pop(L, 1);

Ben

On 11/7/05, Mildred <mildred593@online.fr> wrote:
> On Mon, 07 Nov 2005 18:35:49 +0100
> "Ashwin Hirschi" <deery@operamail.com> wrote:
>
> >
> > > I found in the lua manual a function: lua_insert which put the
> > > element on the top of the stack at a given index.
> > > But is there a solution to put an element at a given index on the
> > > top of the stack (and not a copy of the element like lua_pushfield
> > > do) ?
> >
> > I don't know about lua_pushfield, but how about using lua_pushvalue
> > and lua_remove?
> >
> > Ashwin.
>
> Just a mistake. Replace lua_pushfield by lua_pushvalue ...
> The problem of that function is that a copy is made. And I want the
> same object
>
> For example, If I have a table obj and a subtable obj.child. I want
> obj.child.parent to be obj itseld.
> Then If I modify obj.child.parend, obj is also modified (because it is
> the same object)
>
> Am I clear ?
> Mildred
> --
> Mildred
> Website <http://louve.dyndns.org> ou <http://mildred632.free.fr>
> GnuPG   <http://mildred632.free.fr/gpg_key> ou hkp://pgp.mit.edu
> Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 <9A7D_2E2B> (ID)
> Ce courrier E-mail doit être considéré comme une correspondance privée.
>
>
>