[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: tables
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Fri, 22 Sep 2000 16:43:59 -0300 (EST)
>Suppose I have a table:
>
>Config = {
> Dir = "somestring/",
> File = "somefile"
>};
>
>Is there a way to access the value of "Dir" while
>initializing "File".
Sorry, no.
>This problem comes up often in my use of Lua. Other examples:
>
>Config = {
> Pos = { 0, 1 },
> Window = mainwindow{ Offset = would_like_to_use_pos }
>};
You can try something like
do
local pos= {0,1}
Config = {
Pos = pos,
Window = mainwindow{ Offset = f(pos) }
end
Or you could use constructors that fill some fields based on the values of
other fields. Your first example would be
function config(t)
if t.dir then t.File=t.dir..t.File end
return t
end
Config = config{
Dir = "somestring/",
File = "somefile"
}
The syntax f{} was created exactly for this use.
--lhf