lua-users home
lua-l archive

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


Hi Lua gurus,

Is there a way to implement a linked variable?

For example

$ lua
Lua 5.1.1  Copyright (C) 1994-2006 Lua.org, PUC-Rio
> var1="hello"
> var2=var1
> var2="world"
> =var1
hello
>

I want var1 changed to "world" too, when I change var2.

I tried to store the string "var1" in some place, and when I want to change var1, I use:

> _G["var1"]="world"
> =var1
world
>

It works, but It doesn't work for variable inside tables, for example:

> var1={var3="hello"}
> _G["var1.var3 "]="world"
> =var1.var3
hello
>

Is there a generic way to automatically update one variable when the value of another variable is changed?

Regards,
Austin