lua-users home
lua-l archive

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


On Wed, Jun 9, 2010 at 09:09, Warlich, Christof
<christof.warlich@thermofisher.com> wrote:
>> Do you have a different variable 'interface' defined somewhere else? What
>> is
>
>> the error you are seeing?
>
>>
>
>> Because I'd have thought this would work:
>
>>
>
>> C:\>lua
>
>> Lua 5.1.2  Copyright (C) 1994-2007 Lua.org, PUC-Rio
>
>> > T = { v = 1, f = function() print("Here is T.v: " .. T["v"]) end }
>
>> > T.f()
>
>> Here is T.v: 1
>
>> > T = { v = 42, f = function() print("Here is T.v: " .. T.v) end }  -- or
>
>> using dot notation
>
>> > T.f()
>
>> Here is T.v: 42
>
>> >
>
>>
>
>> Robby
>
>
>
> Oh, mea culpa! I tried this:
>
>
>
> xxx = {
>
>     a = 10,
>
>     b = xxx["a"]
>
> }
>
> print(xxx["a"], xxx["b"])
>
>
>
> As this (presumably simpler) case did not work, I did not even try with a
> function!
>
>
>
> Thanks a lot for your help,
>
>
>
> Christof

Yes, this has come up many times: a table does not exist until its
closing brace and thus can't be referenced by things inside the
constructor.

-- 
Sent from my toaster.