[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: AW: Why no for table-iterator like e. g. "hashpairs"?
- From: <michaelflad@...>
- Date: Tue, 5 Nov 2019 20:01:08 +0100
> -----Ursprüngliche Nachricht-----
> Von: lua-l-bounces@lists.lua.org <lua-l-bounces@lists.lua.org> Im Auftrag
> von bil til
> Gesendet: Dienstag, 5. November 2019 18:53
> An: lua-l@lists.lua.org
> Betreff: Re: Why no for table-iterator like e. g. "hashpairs"?
>
> Hi Javier,
> thank you for getting the curve back again to my post problem... .
>
> I just think that the tables you cite in your post are "special cases". If
in such
> special cases, some numbers would appear as hash, I would not mind.
>
> I just have in mind e. g. some polyline with e. g. 50 or 100 or 1000 xy
points,
> and then some further hash info like name, curve colour, curve thickness.
I
> think it is just a nightmare currently, to get access to this "further
hash info"
> ... complete waste of time to iterate through the complete table... .
>
> I would estimate, that of the tables which require "lengthy for loop
> iterations", about 90% of those tables would be a bit like such a
polyline, so a
> large linear assembly, plus some "further hash info", which is very
important
> of course but has only small percentage of storage space.
>
> If I want to look at such hash info currently with a lua for loop, it is
really a bit
> a sub-optimum support there ... with pairs and next.. (ipairs not working
for
> the hash part...). I could try next( #t), but as next seems to work
completly
> accidential somehow, the result of next(#t) seems to be completely
> undefined... .
If you need a list of vertices and some additonal properties it's as simple
as
using two tables, maybe just embeed one into the other.
local polyline = {
vertices = { 1, 43, 33, 66, 33, 22, 66, 32 },
name = "pretty cool line",
curve_color = { 0.3, 0.6, 0.1 },
}
If you need to iterate over the named values, mabey add the vertices
into the main table and add a properties subtable.
local polyline = {
properties = {
name = "another line",
thinckness = 100,
},
1, 3, 4, 56, 23, 23,
}