lua-users home
lua-l archive

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

On 1/5/2011 8:49 AM, Jose Luis Hidalgo wrote:
>    I've been trying to see how to deal with registering accessors, and
> the problem I see is how you would use the accessors from lua. For
> example, if you register an accessor (a def_readwrite to a variable
> foo of a class bar) in lua:
> b = bar()
> b:foo = 5
> print(b:foo)

That's not legal Lua, AFAIK. b:foo expects function arguments.

Ideally it would actually work like this:

b=bar(); = 5;

That's how it works in, e.g., tolua++ and LuaBind. In fact you can not
only register accessors to public data, you can register an accessor
that calls existing accessors on a C++ class, so the code above could be
calling the C++ member functions bar::setFoo() and bar::getFoo().

And you can still add new members to extend b:

b.somenewmember = 5

I had to dig through tolua++ to fix how that worked WRT
shared_ptr-wrapped objects, so I happen to know how it's done in at
least tolua++; if you're curious I can explain, but there are several
options in Lua.

SLB not having these features was a deal killer for me, so beo wulf
isn't the only person who considers them important. :)