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

Support for Template Constructor / Members / Functions #27

Closed
Sygmei opened this issue Jun 14, 2016 · 4 comments
Closed

Support for Template Constructor / Members / Functions #27

Sygmei opened this issue Jun 14, 2016 · 4 comments

Comments

@Sygmei
Copy link

Sygmei commented Jun 14, 2016

Do you plan to add support for templates when adding constructor, members or functions to a ClassMetatable ?
It works when you specify the type but could it be possible to leave the type empty and let Lua use any type ?

@satoren
Copy link
Owner

satoren commented Jun 14, 2016

I'm sorry, i dont understand.
Can you write example code?

@Sygmei
Copy link
Author

Sygmei commented Jun 14, 2016

For example if we have a simple function which add two things :
template<typename V> V addStuff(V a, V b) { return a + b; }

That I can use like the following :
int a = addStuff(3, 3); std::string b = addStuff((std::string)"foo", (std::string)"bar"); std::cout << a << std::endl; //Display 6 std::cout << b << std::endl; //Display foobar

I can't do that in kaguya :
kaguya::function(addStuff);

I can do this :
kaguya::function(addStuff<int>);

But I'll have to specify each type I want to use, is it possible to pass the entire function and use all the possible types in Lua ?
Either by using kaguya::templatedFunction (or something like this), or some overloading of kaguya::function (Same for addMember, addMemberFunction etc..).
I don't know if C++ allows to do this.

@satoren
Copy link
Owner

satoren commented Jun 14, 2016

Can not it. Instantiate of C++ template is compile time only.
When you invoke function from Lua, type determine runtime.

That you can is below only.

kaguya::overload(
//List the type that might be used
    addStuff<int>,
    addStuff<std::string>,
    addStuff<my_class>,
    addStuff<my_other_class>);

@Sygmei
Copy link
Author

Sygmei commented Jun 14, 2016

I understand :) Thanks anyway !

@Sygmei Sygmei closed this as completed Jun 14, 2016
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

2 participants