From 42253cadfb741d0ec4d67e305da14625fadde7f3 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Mon, 12 Jun 2017 10:45:51 -0400 Subject: [PATCH] guard against `is_integral` accepting booleans as integers --- single/sol/sol.hpp | 12 ++++++------ sol/stack_field.hpp | 8 ++++---- test_tables.cpp | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 80121bca..5018e42d 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2017-06-07 16:52:57.840137 UTC -// This header was generated with sol v2.17.5 (revision 02110a5) +// Generated 2017-06-12 14:43:06.223161 UTC +// This header was generated with sol v2.17.5 (revision 50935ae) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -7110,7 +7110,7 @@ namespace sol { #if SOL_LUA_VERSION >= 503 template - struct field_getter::value>> { + struct field_getter::value && !std::is_same::value>> { template void get(lua_State* L, Key&& key, int tableindex = -1) { lua_geti(L, tableindex, static_cast(key)); @@ -7128,7 +7128,7 @@ namespace sol { #endif // Lua 5.3.x template - struct field_getter::value>> { + struct field_getter::value && !std::is_same::value>> { template void get(lua_State* L, Key&& key, int tableindex = -1) { lua_rawgeti(L, tableindex, static_cast(key)); @@ -7227,7 +7227,7 @@ namespace sol { #if SOL_LUA_VERSION >= 503 template - struct field_setter::value>> { + struct field_setter::value && !std::is_same::value>> { template void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) { push(L, std::forward(value)); @@ -7237,7 +7237,7 @@ namespace sol { #endif // Lua 5.3.x template - struct field_setter::value>> { + struct field_setter::value && !std::is_same::value>> { template void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) { push(L, std::forward(value)); diff --git a/sol/stack_field.hpp b/sol/stack_field.hpp index 10c0c9f1..6db32580 100644 --- a/sol/stack_field.hpp +++ b/sol/stack_field.hpp @@ -88,7 +88,7 @@ namespace sol { #if SOL_LUA_VERSION >= 503 template - struct field_getter::value>> { + struct field_getter::value && !std::is_same::value>> { template void get(lua_State* L, Key&& key, int tableindex = -1) { lua_geti(L, tableindex, static_cast(key)); @@ -106,7 +106,7 @@ namespace sol { #endif // Lua 5.3.x template - struct field_getter::value>> { + struct field_getter::value && !std::is_same::value>> { template void get(lua_State* L, Key&& key, int tableindex = -1) { lua_rawgeti(L, tableindex, static_cast(key)); @@ -205,7 +205,7 @@ namespace sol { #if SOL_LUA_VERSION >= 503 template - struct field_setter::value>> { + struct field_setter::value && !std::is_same::value>> { template void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) { push(L, std::forward(value)); @@ -215,7 +215,7 @@ namespace sol { #endif // Lua 5.3.x template - struct field_setter::value>> { + struct field_setter::value && !std::is_same::value>> { template void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) { push(L, std::forward(value)); diff --git a/test_tables.cpp b/test_tables.cpp index cb8f291e..3b7b47d7 100644 --- a/test_tables.cpp +++ b/test_tables.cpp @@ -546,3 +546,22 @@ TEST_CASE("tables/add", "Basic test to make sure the 'add' feature works") { REQUIRE(val == bigvec[i]); } } + +TEST_CASE("tables/bool-keys", "make sure boolean keys don't get caught up in `is_integral` specializations") { + sol::state lua; + lua.open_libraries(sol::lib::base); + + lua.script(R"( +tbl = {} +tbl[true] = 10 +tbl[1] = 20 + +print(tbl[true]) +print(tbl[1]) +)"); + sol::table tbl = lua["tbl"]; + int v1 = tbl[true]; + int v2 = tbl[1]; + REQUIRE(v1 == 10); + REQUIRE(v2 == 10); +}