[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: linked variable
- From: "wang xu" <xu4wang@...>
- Date: Sat, 2 Dec 2006 01:27:53 +0800
Jim,
Thanks! It works.
I also tried to change the value:
> =loadstring("return "..path_to_n2)()
hello
> =loadstring(path_to_n2.."='world'")()
> =n1.n2
world
>
However, I'm not feeling comfortable with it..
To make it looks a little bit nicer..Maybe I need to wrap lua_getglobal/lua_setglobal in C, and then I can use:
getglobal(path_to_n2)
setglobal(path_to_n2, "a new value for
n1.n2")
Or, is it meaningful for Lua to add a dynamic resolving operator?
2006/12/2, Jim Whitehead II <jnwhiteh@gmail.com>:
You can use loadstring, i.e.
Lua 5.1.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio
> t = {a = true}
> =loadstring("return t.a")()
true
>
In your case something like this should work:
loadstring("return " .. path_to_n2)()
On 12/1/06, wang xu <xu4wang@gmail.com> wrote:
Hello,
If I have a string containing the path to a varialble, for example:
> n1={n2="hello"}
> =n1.n2
hello
> path_to_n2="n1.n2"
> print(path_to_n2)
n1.n2
>
Given variable path_to_n2, how can I get the value of n1.n2 ?