LuaGlue icon indicating copy to clipboard operation
LuaGlue copied to clipboard

Does LuaGlue support default parameters?

Open amerkoleci opened this issue 11 years ago • 4 comments

I have the method:

static CameraPtr CreatePerspective(float fieldOfView = MATH_PIOVER4, float aspectRatio = 1.33333333333333f, float nearPlane = 0.2f, float farPlane = 100000.0f);

CameraPtr is shared_ptr<Camera>

Will this work and can I omit default params in Lua?

amerkoleci avatar Sep 01 '14 08:09 amerkoleci

Due to the way call's are generated at compile time, it may not work. but please test it if you can. I've had some ideas on how to make it work (if it doesn't).

Tomasu avatar Sep 01 '14 16:09 Tomasu

It looks like no, as is it isn't supported. The magic C++ template magic is not able to detect default arguments. I'm not actually sure how to support variable number of arguments at the moment because of the way we bind to functions using stored function pointers that pull their type from the passed function.

I have an idea, but i'm not sure if it'll actually work. I will try to implement it, but I give no guarantees.

Tomasu avatar Sep 03 '14 19:09 Tomasu

Yet you know how many arguments you have in the lua stack. So "reading" only those arguments and calling the function with only those doesn't work ?

On Wed, Sep 3, 2014 at 9:02 PM, Thomas Fjellstrom [email protected] wrote:

It looks like no, as is it isn't supported. The magic C++ template magic is not able to detect default arguments. I'm not actually sure how to support variable number of arguments at the moment because of the way we bind to functions using stored function pointers that pull their type from the passed function.

I have an idea, but i'm not sure if it'll actually work. I will try to implement it, but I give no guarantees.

— Reply to this email directly or view it on GitHub https://github.com/Tomasu/LuaGlue/issues/68#issuecomment-54348703.

Jean-Marc Le Roux

Founder and CEO of Aerys (http://aerys.in)

Blog: http://blogs.aerys.in/jeanmarc-leroux Cell: (+33)6 20 56 45 78 Phone: (+33)9 72 40 17 58

JMLX42 avatar Sep 03 '14 19:09 JMLX42

Yes, we do know how many items are in the stack when our internal call method is called, the main problem is when storing function pointers, they store ALL of the parameters as part of the function pointer type, not just the required ones. So we actually have to pass ALL of the parameters or the compiler will complain when we try to call the function through that function pointer.

A separate set of code that stores the function pointer as a var-arg function pointer might work, but thats a bunch of code duplication, and may be less safe. I'm also not convinced it'll end up working properly either.

Tomasu avatar Sep 03 '14 19:09 Tomasu