Re: Iterate over std::vector from LUA.

"Valery" <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <088501c9e507$6d6f1ce0$80aea8c0@winxpvpc>
Ilia,

I read it many times. First it is not clear for me what class A is. There is 
no its declaration not in module[]. Second, I would like to use iteration 
with typedef declaration (typedef std::vector<> X), but in the sample, 
std::vector is a member of class.

Thanks,
Valery.

----- Original Message ----- 
From: "Ilia Trendafilov" <[email protected]>
To: <[email protected]>
Sent: Thursday, June 04, 2009 12:18 PM
Subject: Re: [luabind] Iterate over std::vector from LUA.


Hi,

You should use the return_stl_iterator policy
There's an example in the documentation:
http://www.rasterbar.com/products/luabind/docs.html#return-stl-iterator

Ilia


On Thu, Jun 4, 2009 at 10:25 AM, Valery <[email protected]> wrote:
> 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
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>

------------------------------------------------------------------------------
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
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.