diff --git a/examples/docs/as_function_usertype_member_variable.cpp b/examples/docs/as_function_usertype_member_variable.cpp index 5cc5e0f6..15b8059d 100644 --- a/examples/docs/as_function_usertype_member_variable.cpp +++ b/examples/docs/as_function_usertype_member_variable.cpp @@ -8,7 +8,7 @@ int main () { }; sol::state lua; - lua.open_libraries(); + lua.open_libraries(sol::lib::base); lua.new_usertype("B", // bind as variable "b", &B::bvar, @@ -18,10 +18,11 @@ int main () { B b; lua.set("b", &b); - lua.script("x = b:f()"); - lua.script("y = b.b"); - int x = lua["x"]; - int y = lua["y"]; - assert(x == 24); - assert(y == 24); + lua.script(R"(x = b:f() + y = b.b + assert(x == 24) + assert(y == 24) + )"); + + return 0; } diff --git a/tests/test_functions.cpp b/tests/test_functions.cpp index e23ee0d7..84047f0d 100644 --- a/tests/test_functions.cpp +++ b/tests/test_functions.cpp @@ -335,7 +335,7 @@ TEST_CASE("functions/returning functions from C++", "check to see if returning a } } -#if defined(SOL_LUAJIT) || (defined(_WIN32) && (defined(_WIN64))) +#if !defined(SOL2_CI) TEST_CASE("functions/function_result and protected_function_result", "Function result should be the beefy return type for sol::function that allows for error checking and error handlers") { sol::state lua; lua.open_libraries(sol::lib::base, sol::lib::debug); @@ -1490,51 +1490,51 @@ TEST_CASE("functions/unique_usertype overloading", "make sure overloading can wo }; } -TEST_CASE("functions/lua style default arguments", "allow default arguments using sol::reference and sol::object") { - auto def_f1 = [](sol::object defaulted) -> int { - bool inactive = defaulted == sol::lua_nil; // inactive by default - if (inactive) { - return 20; - } - return 10; +TEST_CASE("functions/lua style default arguments", "allow default arguments using sol::reference and sol::object") { + auto def_f1 = [](sol::object defaulted) -> int { + bool inactive = defaulted == sol::lua_nil; // inactive by default + if (inactive) { + return 20; + } + return 10; }; - auto def_f2 = [](sol::reference defaulted) -> int { - bool inactive = defaulted == sol::lua_nil; // inactive by default - if (inactive) { - return 20; - } - return 10; + auto def_f2 = [](sol::reference defaulted) -> int { + bool inactive = defaulted == sol::lua_nil; // inactive by default + if (inactive) { + return 20; + } + return 10; }; - auto def_f3 = [](sol::stack_reference defaulted) -> int { - bool inactive = defaulted == sol::lua_nil; // inactive by default - if (inactive) { - return 20; - } - return 10; - }; - - sol::state lua; - lua.set_function("f1", def_f1); - lua.set_function("f2", def_f2); - lua.set_function("f3", def_f3); - - auto result = lua.safe_script(R"( - v1d, v1nd = f1(), f1(1) - v2d, v2nd = f2(), f2(1) - v3d, v3nd = f3(), f3(1) - )", sol::script_pass_on_error); - REQUIRE(result.valid()); - int v1d = lua["v1d"]; - int v1nd = lua["v1nd"]; - int v2d = lua["v2d"]; - int v2nd = lua["v2nd"]; - int v3d = lua["v3d"]; - int v3nd = lua["v3nd"]; - REQUIRE(20 == v1d); - REQUIRE(20 == v2d); - REQUIRE(20 == v3d); - REQUIRE(10 == v1nd); - REQUIRE(10 == v2nd); + auto def_f3 = [](sol::stack_reference defaulted) -> int { + bool inactive = defaulted == sol::lua_nil; // inactive by default + if (inactive) { + return 20; + } + return 10; + }; + + sol::state lua; + lua.set_function("f1", def_f1); + lua.set_function("f2", def_f2); + lua.set_function("f3", def_f3); + + auto result = lua.safe_script(R"( + v1d, v1nd = f1(), f1(1) + v2d, v2nd = f2(), f2(1) + v3d, v3nd = f3(), f3(1) + )", sol::script_pass_on_error); + REQUIRE(result.valid()); + int v1d = lua["v1d"]; + int v1nd = lua["v1nd"]; + int v2d = lua["v2d"]; + int v2nd = lua["v2nd"]; + int v3d = lua["v3d"]; + int v3nd = lua["v3nd"]; + REQUIRE(20 == v1d); + REQUIRE(20 == v2d); + REQUIRE(20 == v3d); + REQUIRE(10 == v1nd); + REQUIRE(10 == v2nd); REQUIRE(10 == v3nd); }