[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: __index returns truncated to one, why?
- From: duz <duz@...>
- Date: Thu, 10 Apr 2014 09:06:36 +0200
Hello All,
I see you're happily making suggestions for changes to Lua,
so I'll drop in mine. Its quite small.
The other day, I built a fancy tracker of some incoming data,
think of a ring buffer. In various flavours. In C and exported
to Lua per userdata.
These beasts were able to record multiple tracks of incoming
data, like a tape machine. Then I thought: How nice, I can
access the most recent set of numbers using [-1] and the first
ever recorded as [1]. In effect, I could traverse the data
back and forth by using indices >0 or <0.
This didn't work for multiple "tracks" of data, as the
multiplie values I was pushing to the Lua Stack from within
__index were truncated to one. For no reason I could see.
tracker = my_fancy_tracker(3) -- three tracks...
...
tracker (1, 2, 3) -- using __call to eat data.
tracker (7, 8, 9)
Now I was hoping to use __index and allow for this semantics:
local a, b, c = tracker[-1]
setting a,b,c=7,8,9 and
local e, f, g = tracker[1]
setting e,f,g=1,2,3
But no luck. The language processing past [] dropped all but
the first value. I had to use an accessor function to be called
like this:
local a,b,c = tracker:at(1)
This looks comparatively clumsy and is less efficient.
So my request would be:
Please do not truncate the results returned from __index to 1!
Cheers,
Dirk
- Follow-Ups:
- Re: __index returns truncated to one, why?, Dirk Laurie
- Bug: __index returns truncated to one., Dirk Zoller
- Re: __index returns truncated to one, why?, Hisham
- Re: __index returns truncated to one, why?, Peng Zhicheng
- Re: __index returns truncated to one, why?, Peng Zhicheng
- Re: __index returns truncated to one, why?, Peng Zhicheng