guard against is_integral accepting booleans as integers

This commit is contained in:
ThePhD 2017-06-12 10:45:51 -04:00
parent 50935ae66b
commit 42253cadfb
3 changed files with 29 additions and 10 deletions

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2017-06-07 16:52:57.840137 UTC // Generated 2017-06-12 14:43:06.223161 UTC
// This header was generated with sol v2.17.5 (revision 02110a5) // This header was generated with sol v2.17.5 (revision 50935ae)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP #ifndef SOL_SINGLE_INCLUDE_HPP
@ -7110,7 +7110,7 @@ namespace sol {
#if SOL_LUA_VERSION >= 503 #if SOL_LUA_VERSION >= 503
template <typename T> template <typename T>
struct field_getter<T, false, false, std::enable_if_t<std::is_integral<T>::value>> { struct field_getter<T, false, false, std::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> {
template <typename Key> template <typename Key>
void get(lua_State* L, Key&& key, int tableindex = -1) { void get(lua_State* L, Key&& key, int tableindex = -1) {
lua_geti(L, tableindex, static_cast<lua_Integer>(key)); lua_geti(L, tableindex, static_cast<lua_Integer>(key));
@ -7128,7 +7128,7 @@ namespace sol {
#endif // Lua 5.3.x #endif // Lua 5.3.x
template <typename T> template <typename T>
struct field_getter<T, false, true, std::enable_if_t<std::is_integral<T>::value>> { struct field_getter<T, false, true, std::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> {
template <typename Key> template <typename Key>
void get(lua_State* L, Key&& key, int tableindex = -1) { void get(lua_State* L, Key&& key, int tableindex = -1) {
lua_rawgeti(L, tableindex, static_cast<lua_Integer>(key)); lua_rawgeti(L, tableindex, static_cast<lua_Integer>(key));
@ -7227,7 +7227,7 @@ namespace sol {
#if SOL_LUA_VERSION >= 503 #if SOL_LUA_VERSION >= 503
template <typename T> template <typename T>
struct field_setter<T, false, false, std::enable_if_t<std::is_integral<T>::value>> { struct field_setter<T, false, false, std::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> {
template <typename Key, typename Value> template <typename Key, typename Value>
void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) { void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) {
push(L, std::forward<Value>(value)); push(L, std::forward<Value>(value));
@ -7237,7 +7237,7 @@ namespace sol {
#endif // Lua 5.3.x #endif // Lua 5.3.x
template <typename T> template <typename T>
struct field_setter<T, false, true, std::enable_if_t<std::is_integral<T>::value>> { struct field_setter<T, false, true, std::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> {
template <typename Key, typename Value> template <typename Key, typename Value>
void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) { void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) {
push(L, std::forward<Value>(value)); push(L, std::forward<Value>(value));

View File

@ -88,7 +88,7 @@ namespace sol {
#if SOL_LUA_VERSION >= 503 #if SOL_LUA_VERSION >= 503
template <typename T> template <typename T>
struct field_getter<T, false, false, std::enable_if_t<std::is_integral<T>::value>> { struct field_getter<T, false, false, std::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> {
template <typename Key> template <typename Key>
void get(lua_State* L, Key&& key, int tableindex = -1) { void get(lua_State* L, Key&& key, int tableindex = -1) {
lua_geti(L, tableindex, static_cast<lua_Integer>(key)); lua_geti(L, tableindex, static_cast<lua_Integer>(key));
@ -106,7 +106,7 @@ namespace sol {
#endif // Lua 5.3.x #endif // Lua 5.3.x
template <typename T> template <typename T>
struct field_getter<T, false, true, std::enable_if_t<std::is_integral<T>::value>> { struct field_getter<T, false, true, std::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> {
template <typename Key> template <typename Key>
void get(lua_State* L, Key&& key, int tableindex = -1) { void get(lua_State* L, Key&& key, int tableindex = -1) {
lua_rawgeti(L, tableindex, static_cast<lua_Integer>(key)); lua_rawgeti(L, tableindex, static_cast<lua_Integer>(key));
@ -205,7 +205,7 @@ namespace sol {
#if SOL_LUA_VERSION >= 503 #if SOL_LUA_VERSION >= 503
template <typename T> template <typename T>
struct field_setter<T, false, false, std::enable_if_t<std::is_integral<T>::value>> { struct field_setter<T, false, false, std::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> {
template <typename Key, typename Value> template <typename Key, typename Value>
void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) { void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) {
push(L, std::forward<Value>(value)); push(L, std::forward<Value>(value));
@ -215,7 +215,7 @@ namespace sol {
#endif // Lua 5.3.x #endif // Lua 5.3.x
template <typename T> template <typename T>
struct field_setter<T, false, true, std::enable_if_t<std::is_integral<T>::value>> { struct field_setter<T, false, true, std::enable_if_t<std::is_integral<T>::value && !std::is_same<bool, T>::value>> {
template <typename Key, typename Value> template <typename Key, typename Value>
void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) { void set(lua_State* L, Key&& key, Value&& value, int tableindex = -2) {
push(L, std::forward<Value>(value)); push(L, std::forward<Value>(value));

View File

@ -546,3 +546,22 @@ TEST_CASE("tables/add", "Basic test to make sure the 'add' feature works") {
REQUIRE(val == bigvec[i]); 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);
}