Iterate over std::vector from LUA.
"Valery" <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <086601c9e4ed$fd77f8d0$80aea8c0@winxpvpc> |
Hello,
I would like to iterate over std::vector from LUA. The vector contains my
simple class. I tryed many ways, but no success. My last simple version
returns "No such operator defined". I tryed return_stl_iterator, but it is
not clear for me how to use it, because my VectorOfA is typedef and not an
other class with the member.
Can anybody help?
Thanks,
Valery.
.cpp
class A
{
int _i;
public:
A() : _i(0){}
A(int i) : _i(i){}
int get() {return _i;}
};
typedef std::vector< A > VectorOfA;
module(L)
[
class_<A>("A")
.def(constructor<>())
.def(constructor<int>())
.def("get", &A::get),
class_<VectorOfA>("VectorOfA")
.def(constructor<>())
];
.lua
function test_iter()
local x = VectorOfA()
for i in x do
print(i:get())
end
end
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get