diff --git a/README.md b/README.md index fd5cb13..12ab7b1 100644 --- a/README.md +++ b/README.md @@ -126,10 +126,11 @@ sel::State state; Foo foo(2); // Binds the C++ instance foo to a table also called foo in Lua along -// with two methods bound to fields of that table +// with two methods bound to fields of that table. +// The user is not required to bind all methods state.Register("foo", foo, - std::make_pair("double_add", &Foo::DoubleAdd), - std::make_pair("set_x", &Foo::SetX)); + "double_add", &Foo::DoubleAdd, + "set_x", &Foo::SetX); state.CallField("foo", "set_x", 4); assert(foo.x == 4); diff --git a/include/Class.h b/include/Class.h index 357786e..a13e540 100644 --- a/include/Class.h +++ b/include/Class.h @@ -7,7 +7,6 @@ #include "State.h" #include #include "util.h" -#include #include namespace sel { @@ -38,14 +37,15 @@ class Class : public BaseClass { template void _register_funs(lua_State *state, T *t, - std::pair fun, - std::pair... funs) { - _register_fun(state, t, fun.first, fun.second); + const char *name, + F fun, + Fs... funs) { + _register_fun(state, t, name, fun); _register_funs(state, t, funs...); } public: Class(lua_State *&state, T *t, const std::string &name, - std::pair... funs) + Funs... funs) : _name(state, name) { lua_createtable(state, 0, sizeof...(Funs)); _register_funs(state, t, funs...); diff --git a/include/State.h b/include/State.h index f524764..1b3b209 100644 --- a/include/State.h +++ b/include/State.h @@ -120,7 +120,7 @@ class State { template void Register(const std::string &name, T &t, - std::pair... funs) { + Funs... funs) { Unregister(name); auto tmp = std::unique_ptr( new Class{_l, &t, name, funs...}); diff --git a/test/class_tests.h b/test/class_tests.h index 30f338b..eb8cca0 100644 --- a/test/class_tests.h +++ b/test/class_tests.h @@ -18,7 +18,7 @@ bool test_register_class() { sel::State state; state.Register("foo_instance", foo_instance, - std::make_pair("double_add", &Foo::DoubleAdd)); + "double_add", &Foo::DoubleAdd); const int answer = state.CallField("foo_instance", "double_add", 3); return (answer == 8); } @@ -28,7 +28,7 @@ bool test_mutate_instance() { sel::State state; state.Register("foo_instance", foo_instance, - std::make_pair("set_x", &Foo::SetX)); + "set_x", &Foo::SetX); state.CallField("foo_instance", "set_x", 4); return (foo_instance.x == 4); } @@ -38,8 +38,8 @@ bool test_multiple_methods() { sel::State state; state.Register("foo_instance", foo_instance, - std::make_pair("double_add", &Foo::DoubleAdd), - std::make_pair("set_x", &Foo::SetX)); + "double_add", &Foo::DoubleAdd, + "set_x", &Foo::SetX); state.CallField("foo_instance", "set_x", 4); const int answer = state.CallField("foo_instance", "double_add", 3); return (answer == 14); @@ -50,8 +50,8 @@ bool test_unregister_instance() { sel::State state; state.Register("foo_instance", foo_instance, - std::make_pair("double_add", &Foo::DoubleAdd), - std::make_pair("set_x", &Foo::SetX)); + "double_add", &Foo::DoubleAdd, + "set_x", &Foo::SetX); bool exists = !state.CheckNil("foo_instance"); state.Unregister("foo_instance"); return exists && state.CheckNil("foo_instance");