Re: LuaBind Function Default Values
Daniel Wallin <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Aug 30, 2010 at 11:07 PM, Julio Cesar Cunha <[email protected]> wrote: > I think that is the solution, but in this way i will redo all. > > Strange that luabind don't suporte this feature yet, searching on google i > found some binds that do that, like toLua++ and Boost:Python. > > Anyway, Don't rasterbar don't say nothing about this feature? maybe in some > future update. The problem is that it isn't technically possible to detect and use the default values. They are not part of the function signature. Boost.Python supports default values by generating a set of overloads with different arities using a macro (from docs): BOOST_PYTHON_FUNCTION_OVERLOADS(foo_overloads, foo, 1, 4) I'm planning to support default values in 1.0 by letting the user pass the values to def(), possibly using this syntax: def("f", &f, _2 = "default value") But for now, the only solution is to define thin wrapper functions. This is pretty easy to do, but not ideal of course: class X { public: void f(int x = 0, int y = 0); }; void f0(X& self) { self.f(); } void f1(X& self, int x) { self.f(x); } void f2(X& self, int x, int y) { self.f(x, y); } ... class_<X>("X") .def("f", &f0) .def("f", &f1) .def("f", &f2) -- Daniel Wallin BoostPro Computing http://www.boostpro.com ------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd