{"action":"created","issue":{"url":"https://api.github.com/repos/satoren/kaguya/issues/52","repository_url":"https://api.github.com/repos/satoren/kaguya","labels_url":"https://api.github.com/repos/satoren/kaguya/issues/52/labels{/name}","comments_url":"https://api.github.com/repos/satoren/kaguya/issues/52/comments","events_url":"https://api.github.com/repos/satoren/kaguya/issues/52/events","html_url":"https://github.com/satoren/kaguya/issues/52","id":174081905,"number":52,"title":"Template specialisation using return-type","user":{"login":"Mizugola","id":3835355,"avatar_url":"https://avatars.githubusercontent.com/u/3835355?v=3","gravatar_id":"","url":"https://api.github.com/users/Mizugola","html_url":"https://github.com/Mizugola","followers_url":"https://api.github.com/users/Mizugola/followers","following_url":"https://api.github.com/users/Mizugola/following{/other_user}","gists_url":"https://api.github.com/users/Mizugola/gists{/gist_id}","starred_url":"https://api.github.com/users/Mizugola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mizugola/subscriptions","organizations_url":"https://api.github.com/users/Mizugola/orgs","repos_url":"https://api.github.com/users/Mizugola/repos","events_url":"https://api.github.com/users/Mizugola/events{/privacy}","received_events_url":"https://api.github.com/users/Mizugola/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-30T17:47:09Z","updated_at":"2016-08-30T20:06:09Z","closed_at":"2016-08-30T20:06:09Z","body":"I created the following class in C++ : \r\n```cpp\r\nclass BaseAttribute\r\n{\r\n    private:\r\n\tstd::string data;\r\n    public:\r\n\tBaseAttribute(std::string data);\r\n\ttemplate <typename T> T get();\r\n\ttemplate <> inline int get() {\r\n            return std::stoi(data);\r\n\t}\r\n\ttemplate <> inline double get() {\r\n\t    return std::stod(data);\r\n\t}\r\n\ttemplate <> inline bool get() {\r\n\t    return (data == \"True\") ? true : false;\r\n\t}\r\n\ttemplate <> inline std::string get() {\r\n\t    return data;\r\n        }\r\n}\r\n```\r\n\r\nI used the following code to bind this class in Lua : \r\n```cpp\r\n(*lua)[\"BaseAttribute\"].setClass(kaguya::ClassMetatable<Data::BaseAttribute>()\r\n    .addConstructor<std::string, std::string, std::string>()\r\n    .addMember(\"get\", static_cast<int(Data::BaseAttribute::*)()>(&Data::BaseAttribute::get))\r\n    .addMember(\"get\", static_cast<double(Data::BaseAttribute::*)()>(&Data::BaseAttribute::get))\r\n    .addMember(\"get\", static_cast<bool(Data::BaseAttribute::*)()>(&Data::BaseAttribute::get))\r\n    .addMember(\"get\", static_cast<std::string(Data::BaseAttribute::*)()>(&Data::BaseAttribute::get))\r\n);\r\n```\r\n\r\n\"lua\" variable is a kaguya::State*\r\n\r\nNow when I use this in Lua : \r\n```lua\r\nlocal myattr = BaseAttribute.new(\"54.6\");\r\nprint(myattr.get());\r\n```\r\n\r\nIt'll only use the <int> version. Is there a way to specify the template implementation I want to use in Lua?\r\nLike with a `myattr.get<double>();`"},"comment":{"url":"https://api.github.com/repos/satoren/kaguya/issues/comments/243562469","html_url":"https://github.com/satoren/kaguya/issues/52#issuecomment-243562469","issue_url":"https://api.github.com/repos/satoren/kaguya/issues/52","id":243562469,"user":{"login":"Mizugola","id":3835355,"avatar_url":"https://avatars.githubusercontent.com/u/3835355?v=3","gravatar_id":"","url":"https://api.github.com/users/Mizugola","html_url":"https://github.com/Mizugola","followers_url":"https://api.github.com/users/Mizugola/followers","following_url":"https://api.github.com/users/Mizugola/following{/other_user}","gists_url":"https://api.github.com/users/Mizugola/gists{/gist_id}","starred_url":"https://api.github.com/users/Mizugola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mizugola/subscriptions","organizations_url":"https://api.github.com/users/Mizugola/orgs","repos_url":"https://api.github.com/users/Mizugola/repos","events_url":"https://api.github.com/users/Mizugola/events{/privacy}","received_events_url":"https://api.github.com/users/Mizugola/received_events","type":"User","site_admin":false},"created_at":"2016-08-30T20:06:09Z","updated_at":"2016-08-30T20:06:09Z","body":"I kinda resolved my problem by changing the name of the get for each templated specialisation :\r\nget_int\r\nget_bool\r\nget_string etc..."}}
{"actor":{"display_login":"Mizugola"}}