lua-users home
lua-l archive

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

On Jan 18, 2008 2:22 PM, derefed <> wrote:
> This compiles, but whenever I try to assign the value returned by
> v:at(0), for instance, I get an assertion error.

Out of curiosity, what is the assertion error? (I don't have a C++
compiler on hand at the moment.)

> You see, what I would like is to have the ability to grab a value out of
> the vector, manipulate it, and have the change be reflected in the
> vector. I can't seem to find any resources on the web as to how Lua
> mimics pointer/reference types... how is this accomplished?

Lua (and by association Luabind) uses pointers for user data (i.e.
classes) and copies primitives. I'm not sure there's an easy way to do
what you're looking for in Luabind, though it may be possible by using
some vanilla Lua. There's probably *a* way to do it, but I expect that
it's nontrivial. To be honest, I'm not entirely happy with Luabind's
handling of STL containers, and once we start working on 0.8, I'm
going to see about changing it.

As an aside, instead of making a wrapper, Luabind allows you to bind
free functions as member functions if the first parameter is a pointer
or reference to the object. So IntVector::at(int i) could be replaced
by at_wrapper(std::vector<int> &v,int i).

- Jim