Re: boost bind/lambda
Tony Kostanjsek <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
I might've been mistaken on the function pointer issue, but I've only used it that way. ----- Ursprüngliche Mail ---- Von: beo wulf <[email protected]> An: [email protected] Gesendet: Mittwoch, den 5. Januar 2011, 6:55:19 Uhr Betreff: Re: [luabind] boost bind/lambda Why does wrapping it on a tag_function work then? Writing wrappers is out of the question -- there are too many functions. On Tue, Jan 4, 2011 at 9:51 PM, Tony Kostanjsek <[email protected]> wrote: > "def" requires an address or function pointer, but bind returns a temporary > functor instance. Try to use a static instance or write a wrapper function > implementation and pass that. > > Something like <type> func = bind(...) > .def("glLightfv", &func) > I'm not sure what <type> would look like though. > > Alternatively, something like this might work: > void wrappedGlLightfv(GLenum light, GLenum pname, const > boost::shared_ptr<std::vector<GLfloat>> fv) > { > glLightfv(light, pname, &fv->get()->front()); // not quite sure about front(), > but you get the idea > } > > ... > .def("glLightfv", wrappedGlLightfv) > ... > > ----- Ursprüngliche Mail ---- > Von: beo wulf <[email protected]> > An: [email protected] > Gesendet: Mittwoch, den 5. Januar 2011, 6:35:09 Uhr > Betreff: [luabind] boost bind/lambda > > Goal: I want to luabind all of OpenGL. > Problem: glLightfv( int, int, GLfloat*) > > Almost solution: boost::bind > > The following code almost works -- it can use boost::bind to convert > functions that take arg GLfloat* to take an arg of > boost::shared_ptr<std::vector<GLfloat>> instead. However, boost::bind > and luabind seem to not work with each other (in particular, the line > > , def("glLightfv2", bind(glLightfv, _1, _2, _3)) // ths line does not compile > > Why? > > Full code below: > > > > #include <boost/shared_ptr.hpp> > #include <boost/bind.hpp> > > #include <vector> > #include <iostream> > > #include <luabind/luabind.hpp> > #include <luabind/operator.hpp> > #include <luabind/adopt_policy.hpp> > #include <luabind/copy_policy.hpp> > #include <luabind/class_info.hpp> > > #include <GL/gl.h> > > > > #define P boost::shared_ptr > #define V std::vector > > float foo(int x, int y, float* f) { > float ans = 0; > ans = x + y + f[0] + f[1] + f[2]; > return ans; > } > > float* get_raw(P<V<float> > p) { > return &((*p)[0]); > } > > void test() { // works fine > P<V<float> > p(new V<float>()); > p->push_back(1); > p->push_back(2); > p->push_back(3); > > // I want this to output 9 > std::cout << bind(foo, _1, _2, bind(get_raw, _3))(1, 2, p) << std::endl; > } > > > int main() { > using namespace luabind; > > lua_State *L; > > module( L ) > [ > namespace_("gl") [ > def( "glLightfv", glLightfv) > // Why do these two lines not compile? > // , def( "glLightfv2", bind(glLightfv, _1, _2, _3)) > // , def( "glLightfv3", bind(glLightfv, _1, _2, bind(get_raw, _3))) > ] > ] > > ; > } > > ------------------------------------------------------------------------------ > Learn how Oracle Real Application Clusters (RAC) One Node allows customers > to consolidate database storage, standardize their database environment, and, > should the need arise, upgrade to a full multi-node Oracle RAC database > without downtime or disruption > http://p.sf.net/sfu/oracle-sfdevnl > _______________________________________________ > luabind-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > > > ------------------------------------------------------------------------------ > Learn how Oracle Real Application Clusters (RAC) One Node allows customers > to consolidate database storage, standardize their database environment, and, > should the need arise, upgrade to a full multi-node Oracle RAC database > without downtime or disruption > http://p.sf.net/sfu/oracle-sfdevnl > _______________________________________________ > luabind-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/luabind-user > ------------------------------------------------------------------------------ Learn how Oracle Real Application Clusters (RAC) One Node allows customers to consolidate database storage, standardize their database environment, and, should the need arise, upgrade to a full multi-node Oracle RAC database without downtime or disruption http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ luabind-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/luabind-user ------------------------------------------------------------------------------ Learn how Oracle Real Application Clusters (RAC) One Node allows customers to consolidate database storage, standardize their database environment, and, should the need arise, upgrade to a full multi-node Oracle RAC database without downtime or disruption http://p.sf.net/sfu/oracle-sfdevnl