[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Small improvement of Automagic Tables behavior
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 4 Nov 2016 17:27:55 +0200
2016-11-04 16:53 GMT+02:00 Egor Skriptunoff <egor.skriptunoff@gmail.com>:
> Hi!
>
> There is a well-known implementation of automagic tables at
> http://lua-users.org/wiki/AutomagicTables
>
> Unfortunately, that implementation behaves weirdly in some situations:
>
> local a = AutomagicTable()
> local x = a.b.c
> local y = a.b.c
> assert(x == y) -- assertion fails !
>
> local a = AutomagicTable()
> a.pointer = a.array.elem2
> a.array.elem1.n = "one"
> a.array.elem2.n = "two"
> a.array.elem3.n = "three"
> assert(a.pointer.n == "two") -- assertion fails !
>
> This behavior can be improved by storing weak references to all created
> objects.
> https://gist.github.com/Egor-Skriptunoff/4ae0f2dbda089f368f3df52ef00c7554
Please click on "edit" near the bottom left corner of the webpage and add
this comment and patch there, so that it becomes available to all future
readers of the Wiki entry.