[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Detecting read or write access in __index metamethod
- From: Marc Balmer <marc@...>
- Date: Wed, 15 Dec 2010 17:22:37 +0100
Am 15.12.10 17:09, schrieb Luiz Henrique de Figueiredo:
>> Is there a way to detect in an __index meta-method, written in C, if the
>> access is for reading or writing a value? I.e. to distinguish between
>>
>> a.b.c = 42
>>
>> and
>>
>> local answer = a.b.c
>
> Perhaps you mean this? http://lua-users.org/wiki/AutomagicTables
Similar, yes. I successfully created it in C to access ClearSilver HDF
structures, however
a.b.c.d = "a.b and a.b.c are automatically created"
this part works. But when I access a not-yet existing valued, e.g.
local n = a.b.x.y
Then I want to get nil. Unfortunately what happens, is that a.b and
a.b.x, a.b.x.y get created.
So write access should create the whole chain, whereas read access
should not.