From 4ba609375654acf480c835ec5c681439bfe6e9a7 Mon Sep 17 00:00:00 2001
From: Jeremy Ong <jeremycong@gmail.com>
Date: Tue, 21 Jan 2014 16:33:17 -0800
Subject: [PATCH] Change class registration syntax to avoid pairs.

---
 README.md          |  7 ++++---
 include/Class.h    | 10 +++++-----
 include/State.h    |  2 +-
 test/class_tests.h | 12 ++++++------
 4 files changed, 16 insertions(+), 15 deletions(-)

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 <string>
 #include "util.h"
-#include <utility>
 #include <vector>
 
 namespace sel {
@@ -38,14 +37,15 @@ class Class : public BaseClass {
 
     template <typename F, typename... Fs>
     void _register_funs(lua_State *state, T *t,
-                        std::pair<const char *, F> fun,
-                        std::pair<const char *, Fs>... 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<const char *, Funs>... 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 <typename T, typename... Funs>
     void Register(const std::string &name, T &t,
-                  std::pair<const char *, Funs>... funs) {
+                  Funs... funs) {
         Unregister(name);
         auto tmp = std::unique_ptr<BaseClass>(
             new Class<T, Funs...>{_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<int>("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<int>("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");