force usage of lua_nil across everything and add a proper macro / feature-test for it

This commit is contained in:
ThePhD 2017-09-22 07:30:41 -04:00
parent 1b23ad8b4f
commit 0114882e13
7 changed files with 49 additions and 37 deletions

View File

@ -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-09-22 01:32:30.111717 UTC
// This header was generated with sol v2.18.2 (revision 61d610b)
// Generated 2017-09-22 11:30:13.483049 UTC
// This header was generated with sol v2.18.3 (revision 1b23ad8)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP
@ -95,7 +95,7 @@
#ifndef SOL_CHECK_ARGUMENTS
#endif // Check Arguments
#ifndef SOL_SAFE_USERTYPE
#define SOL_SAFE_USERTYPE
#define SOL_SAFE_USERTYPE 1
#endif // Safe Usertypes
#endif // NDEBUG
#endif // Debug
@ -118,7 +118,7 @@
#ifndef SOL_CHECK_ARGUMENTS
#endif // Check Arguments
#ifndef SOL_SAFE_USERTYPE
#define SOL_SAFE_USERTYPE
#define SOL_SAFE_USERTYPE 1
#endif // Safe Usertypes
#endif // g++ optimizer flag
#endif // Not Debug
@ -139,10 +139,16 @@
#ifndef SOL_SAFE_USERTYPE
#ifdef SOL_CHECK_ARGUMENTS
#define SOL_SAFE_USERTYPE
#define SOL_SAFE_USERTYPE 1
#endif // Turn on Safety for all
#endif // Safe Usertypes
#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil)
#ifndef SOL_NO_NIL
#define SOL_NO_NIL 1
#endif
#endif // avoiding nil defines / keywords
// end of sol/feature_test.hpp
namespace sol {
@ -4516,7 +4522,7 @@ namespace sol {
inline bool operator!=(lua_nil_t, lua_nil_t) {
return false;
}
#ifndef __OBJC__
#if !defined(SOL_NO_NIL)
typedef lua_nil_t nil_t;
const nil_t nil{};
#endif
@ -4921,7 +4927,7 @@ namespace sol {
enum class type : int {
none = LUA_TNONE,
lua_nil = LUA_TNIL,
#if !defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || !defined(__OBJC__) || !defined(nil)
#if !defined(SOL_NO_NIL)
nil = lua_nil,
#endif // Objective C/C++ Keyword that's found in OSX SDK and OBJC -- check for all forms to protect
string = LUA_TSTRING,
@ -7682,8 +7688,8 @@ namespace stack {
}
bool isnil = false;
for (int vi = 0; vi < lua_size<V>::value; ++vi) {
type t = static_cast<type>(lua_geti(L, index, i + vi));
isnil = t == type::lua_nil;
type vt = static_cast<type>(lua_geti(L, index, i + vi));
isnil = vt == type::lua_nil;
if (isnil) {
if (i == 0) {
break;
@ -8128,7 +8134,7 @@ namespace stack {
struct getter<this_state> {
static this_state get(lua_State* L, int, record& tracking) {
tracking.use(0);
return this_state( L );
return this_state(L);
}
};
@ -8136,7 +8142,7 @@ namespace stack {
struct getter<this_main_state> {
static this_main_state get(lua_State* L, int, record& tracking) {
tracking.use(0);
return this_main_state( main_thread(L, L) );
return this_main_state(main_thread(L, L));
}
};
@ -8279,7 +8285,7 @@ namespace stack {
template <typename... Args>
static R apply(std::index_sequence<>, lua_State*, int, record&, Args&&... args) {
// Fuck you too, VC++
return R{std::forward<Args>(args)...};
return R{ std::forward<Args>(args)... };
}
template <std::size_t I, std::size_t... Ix, typename... Args>
@ -8297,7 +8303,7 @@ namespace stack {
template <typename A, typename B>
struct getter<std::pair<A, B>> {
static decltype(auto) get(lua_State* L, int index, record& tracking) {
return std::pair<decltype(stack::get<A>(L, index)), decltype(stack::get<B>(L, index))>{stack::get<A>(L, index, tracking), stack::get<B>(L, index + tracking.used, tracking)};
return std::pair<decltype(stack::get<A>(L, index)), decltype(stack::get<B>(L, index))>{ stack::get<A>(L, index, tracking), stack::get<B>(L, index + tracking.used, tracking) };
}
};

View File

@ -57,7 +57,7 @@
//#define SOL_CHECK_ARGUMENTS
#endif // Check Arguments
#ifndef SOL_SAFE_USERTYPE
#define SOL_SAFE_USERTYPE
#define SOL_SAFE_USERTYPE 1
#endif // Safe Usertypes
#endif // NDEBUG
#endif // Debug
@ -83,7 +83,7 @@
// But do check userdata by default:
#endif // Check Arguments
#ifndef SOL_SAFE_USERTYPE
#define SOL_SAFE_USERTYPE
#define SOL_SAFE_USERTYPE 1
#endif // Safe Usertypes
#endif // g++ optimizer flag
#endif // Not Debug
@ -104,8 +104,14 @@
#ifndef SOL_SAFE_USERTYPE
#ifdef SOL_CHECK_ARGUMENTS
#define SOL_SAFE_USERTYPE
#define SOL_SAFE_USERTYPE 1
#endif // Turn on Safety for all
#endif // Safe Usertypes
#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil)
#ifndef SOL_NO_NIL
#define SOL_NO_NIL 1
#endif
#endif // avoiding nil defines / keywords
#endif // SOL_FEATURE_TEST_HPP

View File

@ -129,8 +129,8 @@ namespace stack {
}
bool isnil = false;
for (int vi = 0; vi < lua_size<V>::value; ++vi) {
type t = static_cast<type>(lua_geti(L, index, i + vi));
isnil = t == type::lua_nil;
type vt = static_cast<type>(lua_geti(L, index, i + vi));
isnil = vt == type::lua_nil;
if (isnil) {
if (i == 0) {
break;
@ -575,7 +575,7 @@ namespace stack {
struct getter<this_state> {
static this_state get(lua_State* L, int, record& tracking) {
tracking.use(0);
return this_state( L );
return this_state(L);
}
};
@ -583,7 +583,7 @@ namespace stack {
struct getter<this_main_state> {
static this_main_state get(lua_State* L, int, record& tracking) {
tracking.use(0);
return this_main_state( main_thread(L, L) );
return this_main_state(main_thread(L, L));
}
};
@ -726,7 +726,7 @@ namespace stack {
template <typename... Args>
static R apply(std::index_sequence<>, lua_State*, int, record&, Args&&... args) {
// Fuck you too, VC++
return R{std::forward<Args>(args)...};
return R{ std::forward<Args>(args)... };
}
template <std::size_t I, std::size_t... Ix, typename... Args>
@ -744,7 +744,7 @@ namespace stack {
template <typename A, typename B>
struct getter<std::pair<A, B>> {
static decltype(auto) get(lua_State* L, int index, record& tracking) {
return std::pair<decltype(stack::get<A>(L, index)), decltype(stack::get<B>(L, index))>{stack::get<A>(L, index, tracking), stack::get<B>(L, index + tracking.used, tracking)};
return std::pair<decltype(stack::get<A>(L, index)), decltype(stack::get<B>(L, index))>{ stack::get<A>(L, index, tracking), stack::get<B>(L, index + tracking.used, tracking) };
}
};

View File

@ -182,7 +182,7 @@ namespace sol {
inline bool operator!=(lua_nil_t, lua_nil_t) {
return false;
}
#ifndef __OBJC__
#if !defined(SOL_NO_NIL)
typedef lua_nil_t nil_t;
const nil_t nil{};
#endif
@ -587,7 +587,7 @@ namespace sol {
enum class type : int {
none = LUA_TNONE,
lua_nil = LUA_TNIL,
#if !defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || !defined(__OBJC__) || !defined(nil)
#if !defined(SOL_NO_NIL)
nil = lua_nil,
#endif // Objective C/C++ Keyword that's found in OSX SDK and OBJC -- check for all forms to protect
string = LUA_TSTRING,

View File

@ -967,14 +967,14 @@ end
int r = sf(set, 8);
REQUIRE(r == 8);
sol::object rn = sf(set, 9);
REQUIRE(rn == sol::nil);
REQUIRE(rn == sol::lua_nil);
}
{
int r = sf(map, 3);
REQUIRE(r == 6);
sol::object rn = sf(map, 9);
REQUIRE(rn == sol::nil);
REQUIRE(rn == sol::lua_nil);
}
i(lua["arr"]);

View File

@ -664,8 +664,8 @@ TEST_CASE("advanced/get and call", "Checks for lambdas returning values after a
REQUIRE_NOTHROW(lua.set_function("h", [] {}));
REQUIRE_NOTHROW(lua.get<sol::function>("h").call());
REQUIRE_NOTHROW(lua.set_function("i", [] { return sol::nil; }));
REQUIRE(lua.get<sol::function>("i").call<sol::nil_t>() == sol::nil);
REQUIRE_NOTHROW(lua.set_function("i", [] { return sol::lua_nil; }));
REQUIRE(lua.get<sol::function>("i").call<sol::nil_t>() == sol::lua_nil);
REQUIRE_NOTHROW(lua.set_function("j", [] { return std::make_tuple(1, 6.28f, 3.14, std::string("heh")); }));
REQUIRE((lua.get<sol::function>("j").call<int, float, double, std::string>() == heh_tuple));
}
@ -699,8 +699,8 @@ TEST_CASE("advanced/operator[] call", "Checks for lambdas returning values using
REQUIRE_NOTHROW(lua.set_function("h", [] {}));
REQUIRE_NOTHROW(lua["h"].call());
REQUIRE_NOTHROW(lua.set_function("i", [] { return sol::nil; }));
REQUIRE(lua["i"].call<sol::nil_t>() == sol::nil);
REQUIRE_NOTHROW(lua.set_function("i", [] { return sol::lua_nil; }));
REQUIRE(lua["i"].call<sol::nil_t>() == sol::lua_nil);
REQUIRE_NOTHROW(lua.set_function("j", [] { return std::make_tuple(1, 6.28f, 3.14, std::string("heh")); }));
REQUIRE((lua["j"].call<int, float, double, std::string>() == heh_tuple));
}
@ -848,7 +848,7 @@ TEST_CASE("functions/stack atomic", "make sure functions don't impede on the sta
REQUIRE(sg.check_stack());
{
sol::protected_function_result errresult = Stringtest(sol::nil);
sol::protected_function_result errresult = Stringtest(sol::lua_nil);
REQUIRE_FALSE(errresult.valid());
sol::error err = errresult;
std::string msg = err.what();

View File

@ -275,7 +275,7 @@ TEST_CASE("object/conversions", "make sure all basic reference types can be made
auto osl = sol::make_object(lua, "Bark bark bark");
auto os = sol::make_object(lua, somestring);
auto omn = sol::make_object(lua, sol::nil);
auto omn = sol::make_object(lua, sol::lua_nil);
REQUIRE(ot.get_type() == sol::type::table);
REQUIRE(ot2.get_type() == sol::type::table);
@ -329,7 +329,7 @@ TEST_CASE("object/main_* conversions", "make sure all basic reference types can
auto osl = sol::make_object(lua, "Bark bark bark");
auto os = sol::make_object(lua, somestring);
auto omn = sol::make_object(lua, sol::nil);
auto omn = sol::make_object(lua, sol::lua_nil);
REQUIRE(ot.get_type() == sol::type::table);
REQUIRE(ot2.get_type() == sol::type::table);
@ -554,14 +554,14 @@ TEST_CASE("proxy/proper-pushing", "allow proxies to reference other proxies and
TEST_CASE("proxy/equality", "check to make sure equality tests work") {
sol::state lua;
REQUIRE((lua["a"] == sol::nil));
REQUIRE((lua["a"] == sol::lua_nil));
REQUIRE_FALSE((lua["a"] == nullptr));
REQUIRE_FALSE((lua["a"] == 0));
REQUIRE_FALSE((lua["a"] == 2));
lua["a"] = 2;
REQUIRE_FALSE((lua["a"] == sol::nil)); //0
REQUIRE_FALSE((lua["a"] == sol::lua_nil)); //0
REQUIRE_FALSE((lua["a"] == nullptr)); //0
REQUIRE_FALSE((lua["a"] == 0)); //0
REQUIRE((lua["a"] == 2)); //1