[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Best way to have table-like fields on userdata
- From: Sam Roberts <sroberts@...>
- Date: Tue, 28 Nov 2006 10:55:55 -0800
On Tue, Nov 28, 2006 at 10:28:17AM -0800, Brian McCallister wrote:
> What is the best way to support something akin to table like fields
> on userdata, so you can have:
>
> foo.status = 201
> foo:puts("hello world")
>
> where foo is a userdata?
>
> Using the metatable for adding methods as described in PiL works well
Yeah, the PIL shows how to implement methods, and how to implement
properties, but doesn't show how to implement both!
> Anyone have a good solution to this?
See
http://lua-users.org/wiki/ObjectProperties
At the bottom, the rewrite of the array example from the PIL.
Sam