diff --git a/.clang-format b/.clang-format index a81f12f2..706391ba 100644 --- a/.clang-format +++ b/.clang-format @@ -51,7 +51,7 @@ ReflowComments: true # Macros AlignEscapedNewlines: Left -IndentPPDirectives: None +#IndentPPDirectives: None # Functions AllowShortFunctionsOnASingleLine: None diff --git a/sol/load_result.hpp b/sol/load_result.hpp index 930c2e5d..1f3db24b 100644 --- a/sol/load_result.hpp +++ b/sol/load_result.hpp @@ -122,7 +122,7 @@ namespace sol { template decltype(auto) call(Args&&... args) { -#if defined(_MSC_FULL_VER) && _MSC_FULL_VER <= 191326131 && _MSC_FULL_VER >= 191200000 +#if defined(_MSC_FULL_VER) && _MSC_FULL_VER <= 191426428 && _MSC_FULL_VER >= 191200000 // MSVC is ass sometimes return get().call(std::forward(args)...); #else diff --git a/sol/proxy.hpp b/sol/proxy.hpp index 67ac9521..862f6326 100644 --- a/sol/proxy.hpp +++ b/sol/proxy.hpp @@ -126,7 +126,7 @@ namespace sol { template decltype(auto) call(Args&&... args) { -#if defined(_MSC_FULL_VER) && _MSC_FULL_VER <= 191326131 && _MSC_FULL_VER >= 191200000 +#if defined(_MSC_FULL_VER) && _MSC_FULL_VER <= 191426428 && _MSC_FULL_VER >= 191200000 // MSVC is ass sometimes return get().call(std::forward(args)...); #else diff --git a/sol/stack_check.hpp b/sol/stack_check.hpp index a282c4d9..5aef2ef9 100644 --- a/sol/stack_check.hpp +++ b/sol/stack_check.hpp @@ -199,6 +199,16 @@ namespace stack { } }; + template + struct checker { + template + static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { + checker c{}; + (void)c; + return !c.check(L, index, std::forward(handler), tracking); + } + }; + template struct checker : checker {}; diff --git a/sol/stack_core.hpp b/sol/stack_core.hpp index a606bd24..37993d5d 100644 --- a/sol/stack_core.hpp +++ b/sol/stack_core.hpp @@ -450,7 +450,7 @@ namespace sol { template struct field_getter; - template + template struct probe_field_getter; template struct field_setter; @@ -831,24 +831,24 @@ namespace sol { get_field(L, std::forward(key), tableindex); } - template + template probe probe_get_field(lua_State* L, Key&& key) { - return probe_field_getter, global, raw>{}.get(L, std::forward(key)); + return probe_field_getter, C, global, raw>{}.get(L, std::forward(key)); } - template + template probe probe_get_field(lua_State* L, Key&& key, int tableindex) { - return probe_field_getter, global, raw>{}.get(L, std::forward(key), tableindex); + return probe_field_getter, C, global, raw>{}.get(L, std::forward(key), tableindex); } - template + template probe probe_raw_get_field(lua_State* L, Key&& key) { - return probe_get_field(L, std::forward(key)); + return probe_get_field(L, std::forward(key)); } - template + template probe probe_raw_get_field(lua_State* L, Key&& key, int tableindex) { - return probe_get_field(L, std::forward(key), tableindex); + return probe_get_field(L, std::forward(key), tableindex); } template diff --git a/sol/stack_probe.hpp b/sol/stack_probe.hpp index e6f5fbb4..05cacc01 100644 --- a/sol/stack_probe.hpp +++ b/sol/stack_probe.hpp @@ -30,7 +30,7 @@ namespace sol { namespace stack { - template + template struct probe_field_getter { template probe get(lua_State* L, Key&& key, int tableindex = -2) { @@ -38,12 +38,12 @@ namespace stack { return probe(false, 0); } get_field(L, std::forward(key), tableindex); - return probe(!check(L), 1); + return probe(check

(L), 1); } }; - template - struct probe_field_getter, b, raw, C> { + template + struct probe_field_getter, P, b, raw, C> { template probe get(lua_State* L, Keys&& keys, int tableindex = -2) { if (!b && !maybe_indexable(L, tableindex)) { @@ -54,16 +54,16 @@ namespace stack { return probe(false, 1); } get_field(L, std::get<1>(keys), tableindex); - return probe(!check(L), 2); + return probe(check

(L), 2); } }; - template - struct probe_field_getter, b, raw, C> { + template + struct probe_field_getter, P, b, raw, C> { template probe apply(std::index_sequence, int sofar, lua_State* L, Keys&& keys, int tableindex) { get_field < I<1 && b, raw>(L, std::get(keys), tableindex); - return probe(!check(L), sofar); + return probe(check

(L), sofar); } template diff --git a/sol/table_core.hpp b/sol/table_core.hpp index 9222043f..e07cb0cb 100644 --- a/sol/table_core.hpp +++ b/sol/table_core.hpp @@ -135,7 +135,7 @@ namespace sol { template decltype(auto) traverse_get_deep_optional(int& popcount, Key&& key) const { typedef decltype(stack::get(base_t::lua_state())) R; - auto p = stack::probe_get_field(base_t::lua_state(), std::forward(key), lua_gettop(base_t::lua_state())); + auto p = stack::probe_get_field(base_t::lua_state(), std::forward(key), lua_gettop(base_t::lua_state())); popcount += p.levels; if (!p.success) return R(nullopt); diff --git a/sol/types.hpp b/sol/types.hpp index b0f72c06..053c917d 100644 --- a/sol/types.hpp +++ b/sol/types.hpp @@ -108,10 +108,14 @@ namespace sol { return false; } typedef lua_nil_t nil_t; -#if !defined(SOL_NO_NIL) +#if !defined(SOL_NO_NIL) || (SOL_NO_NIL == 0) const nil_t nil{}; #endif + namespace detail { + struct non_lua_nil_t {}; + } + struct metatable_t {}; const metatable_t metatable_key = {}; @@ -862,6 +866,9 @@ namespace sol { template <> struct lua_type_of : std::integral_constant {}; + template <> + struct lua_type_of : std::integral_constant {}; + template <> struct lua_type_of : std::integral_constant {}; diff --git a/tests/test_proxies.cpp b/tests/test_proxies.cpp index e4dfb336..7102d5bb 100644 --- a/tests/test_proxies.cpp +++ b/tests/test_proxies.cpp @@ -48,3 +48,52 @@ TEST_CASE("proxy/function results", "make sure that function results return prop REQUIRE(accum == 10); } } + +TEST_CASE("proxy/optional conversion", "make sure optional conversions out of a table work properly") { + sol::state state{}; + sol::table table = state.create_table_with("func", 42); + sol::optional func = table["func"]; + REQUIRE(func == sol::nullopt); +} + +TEST_CASE("proxy/proper-pushing", "allow proxies to reference other proxies and be serialized as the proxy itself and not a function or something") { + sol::state lua; + lua.open_libraries(sol::lib::base, sol::lib::io); + + class T {}; + lua.new_usertype("T"); + + T t; + lua["t1"] = &t; + lua["t2"] = lua["t1"]; + lua.safe_script("b = t1 == t2"); + bool b = lua["b"]; + REQUIRE(b); +} + +TEST_CASE("proxy/equality", "check to make sure equality tests work") { + sol::state lua; +#ifndef __clang__ + REQUIRE((lua["a"] == sol::lua_nil)); + REQUIRE((lua["a"] == nullptr)); + REQUIRE_FALSE((lua["a"] != sol::lua_nil)); + REQUIRE_FALSE((lua["a"] != nullptr)); + REQUIRE_FALSE((lua["a"] == 0)); + REQUIRE_FALSE((lua["a"] == 2)); + REQUIRE((lua["a"] != 0)); + REQUIRE((lua["a"] != 2)); +#endif // clang screws up by trying to access int128 types that it doesn't support, even when we don't ask for them + + lua["a"] = 2; + +#ifndef __clang__ + REQUIRE_FALSE((lua["a"] == sol::lua_nil)); + REQUIRE_FALSE((lua["a"] == nullptr)); + REQUIRE((lua["a"] != sol::lua_nil)); + REQUIRE((lua["a"] != nullptr)); + REQUIRE_FALSE((lua["a"] == 0)); + REQUIRE((lua["a"] == 2)); + REQUIRE((lua["a"] != 0)); + REQUIRE_FALSE((lua["a"] != 2)); +#endif // clang screws up by trying to access int128 types that it doesn't support, even when we don't ask for them +} diff --git a/tests/tests.cpp b/tests/tests.cpp index e0aac7b5..4cd8801d 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -21,8 +21,6 @@ // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -#define CATCH_CONFIG_MAIN 1 - #include "test_sol.hpp" #include @@ -570,47 +568,6 @@ TEST_CASE("pusher/constness", "Make sure more types can handle being const and j REQUIRE(x == 20); } -TEST_CASE("proxy/proper-pushing", "allow proxies to reference other proxies and be serialized as the proxy itself and not a function or something") { - sol::state lua; - lua.open_libraries(sol::lib::base, sol::lib::io); - - class T {}; - lua.new_usertype("T"); - - T t; - lua["t1"] = &t; - lua["t2"] = lua["t1"]; - lua.safe_script("b = t1 == t2"); - bool b = lua["b"]; - REQUIRE(b); -} - -TEST_CASE("proxy/equality", "check to make sure equality tests work") { - sol::state lua; -#ifndef __clang__ - REQUIRE((lua["a"] == sol::lua_nil)); - REQUIRE_FALSE((lua["a"] == nullptr)); - REQUIRE_FALSE((lua["a"] != sol::lua_nil)); - REQUIRE((lua["a"] != nullptr)); - REQUIRE_FALSE((lua["a"] == 0)); - REQUIRE_FALSE((lua["a"] == 2)); - REQUIRE((lua["a"] != 0)); - REQUIRE((lua["a"] != 2)); - lua["a"] = 2; -#endif // clang screws up by trying to access int128 types that it doesn't support, even when we don't ask for them - -#ifndef __clang__ - REQUIRE_FALSE((lua["a"] == sol::lua_nil)); - REQUIRE_FALSE((lua["a"] == nullptr)); - REQUIRE((lua["a"] != sol::lua_nil)); - REQUIRE((lua["a"] != nullptr)); - REQUIRE_FALSE((lua["a"] == 0)); - REQUIRE((lua["a"] == 2)); - REQUIRE((lua["a"] != 0)); - REQUIRE_FALSE((lua["a"] != 2)); -#endif // clang screws up by trying to access int128 types that it doesn't support, even when we don't ask for them -} - TEST_CASE("compilation/const regression", "make sure constness in tables is respected all the way down") { struct State { public: diff --git a/tests/tests_main.cpp b/tests/tests_main.cpp new file mode 100644 index 00000000..b74b7bb9 --- /dev/null +++ b/tests/tests_main.cpp @@ -0,0 +1,7 @@ +#define CATCH_CONFIG_RUNNER +#include "catch.hpp" + +int main(int argc, char* argv[]) { + int result = Catch::Session().run(argc, argv); + return result; +}