lua-users home
lua-l archive

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


2010/5/8 spir ☣ <denis.spir@gmail.com>:
> On Sat, 8 May 2010 11:20:03 +0200
> steve donovan <steve.j.donovan@gmail.com> wrote:
>
>> > * That table definitions be executable blocks! (Inside its own scope.) So that one can refer to previously defined slots in further ones, or even to the table itself.
>>
>> This definitely makes some things easier, but it's a big change. It
>> complicates the lookup rules, which are fairly simple in Lua.  Try
>> some big-scale C++ and see your brain using extra cycles trying to
>> keep track of symbol lookup!
>
> Hello Steve,
>
> What I mean (already exchanged on the topic) is simply that the table be defined at start of its definition:
>
> Pt = {                  -- here t already exists and is equal to {}
>    x = 1,
>    y = 2,
>    d = x+y,            -- so, this is legal
>    __index = t         -- and this, too ;-)
>    -- .......
> }
>
> Denis
> ________________________________
>
> vit esse estrany ☣
>
> spir.wikidot.com
>

Probably it would be ideal to just make 'self' equal to the table
that's being created, so you could use self.x + self.y. However, it
would require some drastic changes to the table code, and any such
change would break compatibility. Consider:
function foo(x,y) return {x=y, y=x} end
the "y=x" would no longer work, or if you used my suggestion, existing
code that uses 'self' in table creation would no longer work.

-- 
Sent from my toaster.