Selene
Selene copied to clipboard
Error when registering function with shared_ptr as argument.
Hello,
I tried to register a function using a std::shared_ptr as an argument but that results in a bunch of compilation errors. Here is a minimal example:
#include <Selene/selene.h>
#include <iostream>
#include <memory>
using namespace std;
class Demo
{
public:
void sayHello() const
{
cout << "Hello!" << endl;
}
};
void test_func(std::shared_ptr<Demo> p)
{
if (p)
{
p->sayHello();
}
}
int main(int argc, char* argv[])
{
if (argc != 2)
{
cerr << "Script file expected!" << endl;
return 1;
}
sel::State state{true};
state["test_func"] = &test_func;
state.Load(argv[1]);
return 0;
}
Part of the compiler output (g++ -Wall -std=c++11 -o test1 -I<path/to/selene> test1.cpp):
selene/BaseFun.h: In instantiation of ‘std::tuple<_Elements ...> sel::detail::get_args(lua_State, sel::detail::_indices<N ...>) [with T = std::shared_ptr<Demo>; long unsigned int ...N = 0ul; lua_State = lua_State]’: /home/philipp/Code/Libs/include/Selene/selene/BaseFun.h:56:27: required from ‘std::tuple<Elements ...> sel::detail::get_args(lua_State) [with T = {std::shared_ptr<Demo>}; lua_State = lua_State]’ selene/Fun.h:54:64: required from ‘int sel::Fun<0, void, Args ...>::Apply(lua_State) [with Args = {std::shared_ptr<Demo>}; lua_State = lua_State]’ src/main.cpp:39:1: required from here /home/philipp/Code/Libs/include/Selene/selene/BaseFun.h:50:39: error: no matching function for call to ‘_check_get(sel::detail::idstd::shared_ptr<Demo >, lua_State&, long unsigned int)’ return std::tuple<T...>{_check_get(_id<T>{}, state, N + 1)...}; ^ ^
In file included from /usr/include/c++/5/functional:55:0, from /home/philipp/Code/Libs/include/Selene/selene/exception.h:2, from /home/philipp/Code/Libs/include/Selene/selene/State.h:3, from /home/philipp/Code/Libs/include/Selene/selene.h:7, from src/main.cpp:1: /usr/include/c++/5/tuple:538:2: note: candidate: template<class _Alloc, class ... _UElements, class> std::tuple<
>::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_Args2 ...>&&) tuple(allocator_arg_t __tag, const _Alloc& __a, ^ /usr/include/c++/5/tuple:538:2: note: template argument deduction/substitution failed: /usr/include/c++/5/tuple:529:2: note: candidate: template<class _Alloc, class ... _UElements, class> std::tuple< >::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_Args2 ...>&) tuple(allocator_arg_t __tag, const _Alloc& __a, ^
I'm using g++ 5.2.1 on Ubuntu 15.10. I don't know if I'm using Selene incorrectly or if using shared_ptr as function arguments is not yet supported.