lua-users home
lua-l archive

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


On 04/10/2014 12:38 PM, steve donovan wrote:
On Thu, Apr 10, 2014 at 11:51 AM, Andrew Starks <andrew.starks@trms.com> wrote:
local a, b, c = t[1]

...becoming a common idiom is reason enough for me.

I would not suggest or expect this to become a common idiom.

But this is very ambiguous; my Lua brain immediately assigns t[1] to
a, and leaves b and c unassigned.  Ah, but you say:  t has a special
metamethod!  But I say, I can't tell from the static code context,
which is where human readers operate.

If you find it confusing then please just don't use it.
It would take conscious work from your part to create a special 't'
to become exposed to this.

My point is, for simplicity and efficiency in these little buffers,
I used __call to feed data into them and I tried to use __index to
access data. Then I was surprised to find __index to be so limited.

Now instead of just returning data from __index, I wrote another
method for access. Yet I still had to implement __index in order to
push that other method. More code on the C-side of things *and* more
code for the user of the Object in Lua (which is me) *and* more work
for the CPU to do.

Is there is a good technical reason for this truncation?