lua-users home
lua-l archive

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


Hi,

it depends on what you want to change.
If you want to change the value itself (e.g. referenz to another table
or
to change the value of the reference to any other kind of object) then
you have to unref the current table an reref the new table.
Because of the way references are implemented right now you can do a
little
hack instead, i.e. just use the reference as index into the registry and
replace the value at that position - but I won't recommend that because
the way references are implemented may change in future.

To change the contents of the table (e.g. add/change a new key/value
pair
you simply modify the table on the stack after you getrefed it.

Kind regards,
 
--
Claw Design Software http://www.clawdesign.com
Ludwigstr. 8 D-72474 Winterlingen / Germany
Tel: +49 7434 3931 Fax: --- ICQ: 48525570


> -----Ursprüngliche Nachricht-----
> Von: owner-lua-l@tecgraf.puc-rio.br 
> [mailto:owner-lua-l@tecgraf.puc-rio.br] Im Auftrag von Alexey Scryabin
> Gesendet: Freitag, 31. Januar 2003 13:56
> An: Multiple recipients of list
> Betreff: Modifying referenced data
> 
> 
> 
> Good day!
> 
> How can I modify a referenced data? For instance:
> 
> // create a table
> lua_newtable( L );
> // set table[0] = number
> lua_pushnumber( L, number );
> lua_rawseti( L, -2, 0 );
> // reference the table
> int ref = lua_ref( L, lock );
> 
> // ... somewhere later in the code
> // get referenced table
> lua_getref( L, ref );
> 
> now I can read table[0], but how could I change the value of 
> table[0] such as next time I do lua_getref( L, ref ) I will 
> get modified table?
> 
> -- 
> Best regards,
>  Alexey                          mailto:alex@targem.ru
>