lua-users home
lua-l archive

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


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