[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: best way to add field to userdata?
- From: Ted Unangst <ted.unangst@...>
- Date: Thu, 22 Apr 2010 09:12:21 -0400
On Thu, Apr 22, 2010 at 3:33 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> On Thu, Apr 22, 2010 at 9:27 AM, Ted Unangst <ted.unangst@gmail.com> wrote:
>> But in order to get access to the width and height, I needed to use
>> getters ("img:width()", as a call) which are annoying. I want
>> "img.width" to work.
>
> I'd suggest getting it to work in vanilla Lua first. This sounds like
> a job for the 'proxy table' pattern. Property access fires __index,
> which is a function which looks up the value in the actual table (and
> may even call a setter, if defined). Ditto for __newindex.
I think that's exactly what I have, I just don't like it. :) Compared
to the ease with which luaL_register works, writing my own index
function is real work.
I was thinking about extracting the generic parts, somewhat like
Wesley's approach, so I'll try that some more. Thanks all.