Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does LuaGlue support default parameters? #68

Open
amerkoleci opened this issue Sep 1, 2014 · 4 comments
Open

Does LuaGlue support default parameters? #68

amerkoleci opened this issue Sep 1, 2014 · 4 comments

Comments

@amerkoleci
Copy link

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

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

@Tomasu
Copy link
Owner

Tomasu commented Sep 1, 2014

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
Copy link
Owner

Tomasu commented Sep 3, 2014

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.

@JMLX42
Copy link
Contributor

JMLX42 commented Sep 3, 2014

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
#68 (comment).

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

@Tomasu
Copy link
Owner

Tomasu commented Sep 3, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants