Re: [luabind] passing a pointer to an array
Brought to you by:
arvidn,
daniel_wallin
From: Arvid N. <c9...@cs...> - 2005-12-31 01:06:59
|
On Dec 31, 2005, at 01:26, Andrew Davis wrote: > Thanks for the response. I was thinking of doing the accessor to > get each individual particle. I thought that might be kind of > innefficient, but it will work, so I will do it that way! Thanks > again. I think letting lua run each particle individually in the first place may be the biggest bottleneck. However, what you want to do is possible if you combine a thin wrapper with the return_stl_iterator policy [1]. Something like this (from the top of my head) could work: struct container_interface { typedef particle value_type; typedef particle* iterator; container_interface(iterator*& p, int& s): ptr(p), size(s) {} iterator begin() { return ptr; } iterator end() { return ptr + size; } iterator*& ptr; int& size; }; struct particle_system { particle_system() : m_interface(m_particles, m_num_particles) { // .. } particle* m_particles; int m_num_particles; container_interface m_interface; }; class_<particle_system> .def_readwrite("particles", &particle_system::m_interface, return_stl_iterator) then the attribute "particles" will return a generator that can be used in lua's for statements. container_interface is supposed to implement the ContainerConcept [2], but these members may be enough for the return_stl_interface policy. -- Arvid Norberg [1]: http://www.rasterbar.com/products/luabind/docs.html#return-stl- iterator [2]: http://www.sgi.com/tech/stl/Container.html |