Re: LuaBind Function Default Values
Julio Cesar Cunha <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
I see this solution yesterday, i think i don't have much choise.
Others solution that i find is set many casts like this:
.def("beginScene", (bool (IVideoDriver::*)())&IVideoDriver::beginScene)
.def("beginScene", (bool (IVideoDriver::*)(bool,bool))&IVideoDriver::
beginScene)
.def("beginScene", (bool (IVideoDriver::*)(bool,bool,bool,bool))&
IVideoDriver::beginScene)
This solution work well with this type of parameter, but if you need to send
a point the program crash, because lua send trash to the point.
Thanks Daniel, i'm waiting the 1.0 version.
2010/8/31 Daniel Wallin <[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
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
--
http://wolfnime.com o futuro do anime esta aqui.
****Eu rejeito a sua Realidade e Substituo pela minha****
------------------------------------------------------------------------------
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
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user