diff --git a/.new.travis.yml b/.new.travis.yml index 7e78573d..acf43527 100644 --- a/.new.travis.yml +++ b/.new.travis.yml @@ -30,7 +30,7 @@ before_install: - sudo docker ps -a script: -- sudo docker +- sudo docker run -it ubuntu notifications: webhooks: diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d3f3aa5..3de2b6da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,8 @@ option(SINGLE "Enable build of single header files" ON) # Single tests will only be turned on if both SINGLE and TESTS are defined CMAKE_DEPENDENT_OPTION(TESTS_SINGLE "Enable build of tests using the generated single headers" ON "SINGLE;TESTS" OFF) +CMAKE_DEPENDENT_OPTION(EXAMPLES_SINGLE "Enable build of tests using the generated single headers" OFF + "SINGLE;EXAMPLES" OFF) if (TESTS AND EXAMPLES) option(TESTS_EXAMPLES "Enable build of examples as tests" ON) else() diff --git a/appveyor.yml b/appveyor.yml index 2f8cfd43..a04d14c2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,6 +22,8 @@ version: 1.0.{build} +max_jobs: 4 + pull_requests: do_not_increment_build_number: true @@ -29,18 +31,15 @@ image: - Visual Studio 2017 - Visual Studio 2015 -configuration: -- Release - environment: matrix: - - LUA_VERSION: 5.3.4 - - LUA_VERSION: 5.2.4 - - LUA_VERSION: 5.1.5 - LUA_VERSION: 5.3.4 MINGW_VERSION: 6.3.0 - LUA_VERSION: 5.3.4 MINGW_VERSION: 5.3.0 + - LUA_VERSION: 5.3.4 + - LUA_VERSION: 5.2.4 + - LUA_VERSION: 5.1.5 platform: - x86 @@ -48,8 +47,10 @@ platform: matrix: allow_failures: + # oldest compiler is allowed to fail here due to esoteric bugs - MINGW_VERSION: 5.3.0 - - MINGW_VERSION: 6.3.0 + # 32-bit builds are temperamental with exceptions + - platform: x86 exclude: - platform: x86 LUA_VERSION: 5.2.4 @@ -57,12 +58,16 @@ matrix: LUA_VERSION: 5.1.5 - platform: x86 MINGW_VERSION: 6.3.0 - - platform: x86 - MINGW_VERSION: 5.3.0 - image: Visual Studio 2017 MINGW_VERSION: 6.3.0 - image: Visual Studio 2017 MINGW_VERSION: 5.3.0 + - image: Visual Studio 2015 + LUA_VERSION: 5.1.5 + - image: Visual Studio 2015 + LUA_VERSION: 5.2.4 + - image: Visual Studio 2015 + platform: x86 init: # make sure we have Ninja diff --git a/cmake/Modules/LuaVanillaBuild.cmake b/cmake/Modules/LuaVanillaBuild.cmake index 79cda6d1..d626eed0 100644 --- a/cmake/Modules/LuaVanillaBuild.cmake +++ b/cmake/Modules/LuaVanillaBuild.cmake @@ -246,13 +246,13 @@ if (LUA_VANILLA_GENERATE_LUA_HPP) extern \"C\" { #include \"lua.h\" -#include \"liblua.h\" +#include \"lualib.h\" #include \"lauxlib.h\" } ") set(LUA_VANILLA_SOURCE_LUA_HPP "${LUA_BUILD_TOPLEVEL}-tmp/lua.hpp") set(LUA_VANILLA_DESTINATION_LUA_HPP "${LUA_VANILLA_SOURCE_DIR}/lua.hpp") - file(WRITE "${LUA_VANILLA_SOURCE_LUA_HPP}" "${LUA_VANILLA_HPP_CONTENT}") + file(WRITE "${LUA_VANILLA_SOURCE_LUA_HPP}" "${LUA_VANILLA_LUA_HPP_CONTENT}") file(TO_NATIVE_PATH "${LUA_VANILLA_SOURCE_LUA_HPP}" LUA_VANILLA_SOURCE_LUA_HPP) file(TO_NATIVE_PATH "${LUA_VANILLA_DESTINATION_LUA_HPP}" LUA_VANILLA_DESTINATION_LUA_HPP) ExternalProject_Add_Step(LUA_VANILLA @@ -261,6 +261,7 @@ extern \"C\" { DEPENDEES download DEPENDERS build BYPRODUCTS "${LUA_VANILLA_TARGET_LUA_HPP}" + COMMENT "Moving \"${LUA_VANILLA_SOURCE_LUA_HPP}\" to \"${LUA_VANILLA_DeSTINATION_LUA_HPP}\"..." COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_VANILLA_SOURCE_LUA_HPP}" "${LUA_VANILLA_DESTINATION_LUA_HPP}") endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index eff673a3..96825cb3 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -83,7 +83,10 @@ endfunction(MAKE_EXAMPLE) foreach(example_source_file ${EXAMPLES_SRC}) MAKE_EXAMPLE(${example_source_file} FALSE) - if (TESTS_SINGLE AND SOL2_SINGLE_FOUND) - MAKE_EXAMPLE(${example_source_file} TRUE) - endif() endforeach() + +if (EXAMPLES_SINGLE AND SOL2_SINGLE_FOUND) + foreach(example_source_file ${EXAMPLES_SRC}) + MAKE_EXAMPLE(${example_source_file} TRUE) + endforeach() +endif() diff --git a/examples/any_return.cpp b/examples/any_return.cpp index a9bf833f..df82f9c5 100644 --- a/examples/any_return.cpp +++ b/examples/any_return.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "assert.hpp" // Uses some of the fancier bits of sol2, including the "transparent argument", // sol::this_state, which gets the current state and does not increment @@ -27,17 +27,17 @@ int main() { int result = lua["f"](1, 2); // result == 3 - assert(result == 3); + c_assert(result == 3); double result2 = lua["f"](false, 2.5); // result2 == 2.5 - assert(result2 == 2.5); + c_assert(result2 == 2.5); // call in Lua, get result // notice we only need 2 arguments here, not 3 (sol::this_state is transparent) lua.script("result3 = f(true, 5.5)"); double result3 = lua["result3"]; // result3 == 16.5 - assert(result3 == 16.5); + c_assert(result3 == 16.5); std::cout << "=== any_return example ===" << std::endl; std::cout << "result : " << result << std::endl; diff --git a/examples/assert.hpp b/examples/assert.hpp new file mode 100644 index 00000000..f247fca4 --- /dev/null +++ b/examples/assert.hpp @@ -0,0 +1,30 @@ +#ifndef MY_ASSERT_HPP +#define MY_ASSERT_HPP + +#ifndef NDEBUG +# define m_assert(condition, message) \ + do { \ + if (! (condition)) { \ + std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \ + << " line " << __LINE__ << ": " << message << std::endl; \ + std::terminate(); \ + } \ + } while (false) + +# define c_assert(condition) \ + do { \ + if (! (condition)) { \ + std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \ + << " line " << __LINE__ << std::endl; \ + std::terminate(); \ + } \ + } while (false) +#else +#include +#include + +# define m_c_assert(condition, message) do { (void)sizeof(condition); (void)sizeof(message); } while (false) +# define c_assert(condition) do { (void)sizeof(condition); } while (false) +#endif + +#endif // MY_ASSERT_HPP diff --git a/examples/basic.cpp b/examples/basic.cpp index db255d74..04b8a95a 100644 --- a/examples/basic.cpp +++ b/examples/basic.cpp @@ -2,6 +2,7 @@ #include #include +#include "assert.hpp" int main() { std::cout << "=== basic example ===" << std::endl; @@ -37,7 +38,7 @@ int main() { if (result.valid()) { std::cout << "the third script worked, and a double-hello statement should appear above this one!" << std::endl; int value = result; - assert(value == 24); + c_assert(value == 24); } else { std::cout << "the third script failed, check the result type for more information!" << std::endl; @@ -49,7 +50,7 @@ int main() { if (result.valid()) { std::cout << "the fourth script worked, which it wasn't supposed to! Panic!" << std::endl; int value = result; - assert(value == 24); + c_assert(value == 24); } else { sol::error err = result; diff --git a/examples/config.cpp b/examples/config.cpp index a751e789..c7a1b983 100644 --- a/examples/config.cpp +++ b/examples/config.cpp @@ -1,6 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include +#include "assert.hpp" #include #include @@ -31,9 +32,9 @@ height = 1080 screen.name = lua.get("name"); screen.width = lua.get("width"); screen.height = lua.get("height"); - assert(screen.name == "Asus"); - assert(screen.width == 1920); - assert(screen.height == 1080); + c_assert(screen.name == "Asus"); + c_assert(screen.width == 1920); + c_assert(screen.height == 1080); std::cout << "=== config example ===" << std::endl; screen.print(); diff --git a/examples/container_usertype_as_container.cpp b/examples/container_usertype_as_container.cpp index c333b805..8e43c342 100644 --- a/examples/container_usertype_as_container.cpp +++ b/examples/container_usertype_as_container.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include "assert.hpp" #include class number_storage { @@ -64,8 +64,8 @@ print("accumulate after :", ns:accumulate()) number_storage& ns = lua["ns"]; number_storage& ns_container = lua["ns_container"]; - assert(&ns == &ns_container); - assert(ns.size() == 3); + c_assert(&ns == &ns_container); + c_assert(ns.size() == 3); std::cout << std::endl; diff --git a/examples/containers_as_table.cpp b/examples/containers_as_table.cpp index d3872403..663b6c15 100644 --- a/examples/containers_as_table.cpp +++ b/examples/containers_as_table.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include "assert.hpp" #include @@ -15,10 +15,10 @@ void demo(sol::nested>> src) { std::cout << "demo, sol::nested<...>" << std::endl; const auto& listmap = src.source; - assert(listmap.size() == 2); + c_assert(listmap.size() == 2); for (const auto& kvp : listmap) { const std::vector& strings = kvp.second; - assert(strings.size() == 3); + c_assert(strings.size() == 3); std::cout << "\t" << kvp.first << " = "; for (const auto& s : strings) { std::cout << "'" << s << "'" << " "; @@ -39,11 +39,11 @@ void demo_explicit (sol::as_table_t" << std::endl; // Have to access the "source" member variable for as_table_t const auto& listmap = src.source; - assert(listmap.size() == 2); + c_assert(listmap.size() == 2); for (const auto& kvp : listmap) { // Have to access the internal "source" for the inner as_table_t, as well const std::vector& strings = kvp.second.source; - assert(strings.size() == 3); + c_assert(strings.size() == 3); std::cout << "\t" << kvp.first << " = "; for (const auto& s : strings) { std::cout << "'" << s << "'" << " "; diff --git a/examples/coroutine_state.cpp b/examples/coroutine_state.cpp index f99b5da4..e1f3264b 100644 --- a/examples/coroutine_state.cpp +++ b/examples/coroutine_state.cpp @@ -1,6 +1,7 @@ #define SOL_CHECK_ARGUMENTS #include +#include "assert.hpp" #include int main(int, char*[]) { @@ -41,7 +42,7 @@ int main(int, char*[]) { transferred_into(); // check int i = lua["i"]; - assert(i == 1); + c_assert(i == 1); std::cout << std::endl; diff --git a/examples/customization.cpp b/examples/customization.cpp index 945c2597..f56ff9cb 100644 --- a/examples/customization.cpp +++ b/examples/customization.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "assert.hpp" struct two_things { int a; @@ -85,8 +85,8 @@ int main() { sol::function f = lua["f"]; two_things things = f(two_things{ 24, false }); - assert(things.a == 24); - assert(things.b == false); + c_assert(things.a == 24); + c_assert(things.b == false); // things.a == 24 // things.b == true diff --git a/examples/customization_convert_on_get.cpp b/examples/customization_convert_on_get.cpp index ba024f87..3efe7b0e 100644 --- a/examples/customization_convert_on_get.cpp +++ b/examples/customization_convert_on_get.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include "assert.hpp" struct number_shim { double num = 0; @@ -61,8 +61,8 @@ int main() { number_shim thingsf = lua["vf"]; number_shim thingsg = lua["vg"]; - assert(thingsf.num == 25); - assert(thingsg.num == 35); + c_assert(thingsf.num == 25); + c_assert(thingsg.num == 35); return 0; } diff --git a/examples/dynamic_object.cpp b/examples/dynamic_object.cpp index 36dc4989..f4f13b5c 100644 --- a/examples/dynamic_object.cpp +++ b/examples/dynamic_object.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "assert.hpp" // use as-is, // add as a member of your class, @@ -75,7 +75,7 @@ assert(value == 15) // does not work on d1: 'run' wasn't added to d1, only d2 auto script_result = lua.safe_script("local value = d1:run(5)", sol::script_pass_on_error); - assert(!script_result.valid()); + c_assert(!script_result.valid()); sol::error err = script_result; std::cout << "received expected error: " << err.what() << std::endl; std::cout << std::endl; diff --git a/examples/environment_snooping.cpp b/examples/environment_snooping.cpp index 06e1cb82..cd980c0f 100644 --- a/examples/environment_snooping.cpp +++ b/examples/environment_snooping.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" #include // Simple sol2 version of the below diff --git a/examples/environments_on_functions.cpp b/examples/environments_on_functions.cpp index 063a1d30..48b79d57 100644 --- a/examples/environments_on_functions.cpp +++ b/examples/environments_on_functions.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" #include int main(int, char**) { @@ -20,7 +20,7 @@ int main(int, char**) { // the function returns the value from the environment table int result = f(); - assert(result == 31); + c_assert(result == 31); // You can also protect from variables @@ -33,13 +33,13 @@ int main(int, char**) { g(); // the value can be retrieved from the env table int test = env_g["test"]; - assert(test == 5); + c_assert(test == 5); // the global environment // is not polluted at all, despite both functions being used and set sol::object global_test = lua["test"]; - assert(!global_test.valid()); + c_assert(!global_test.valid()); // You can retrieve environments in C++ @@ -58,9 +58,9 @@ int main(int, char**) { int test_target_env = target_env["test"]; // the environment for f the one gotten from `target` // are the same - assert(test_env_f == test_target_env); - assert(test_env_f == 31); - assert(env_f == target_env); + c_assert(test_env_f == test_target_env); + c_assert(test_env_f == 31); + c_assert(env_f == target_env); } ); lua.set_function("check_g_env", @@ -69,9 +69,9 @@ int main(int, char**) { sol::environment target_env = sol::get_environment(target); int test_env_g = env_g["test"]; int test_target_env = target_env["test"]; - assert(test_env_g == test_target_env); - assert(test_env_g == 5); - assert(env_g == target_env); + c_assert(test_env_g == test_target_env); + c_assert(test_env_g == 5); + c_assert(env_g == target_env); } ); diff --git a/examples/functions.cpp b/examples/functions.cpp index 3ce8fa9d..6851b8fd 100644 --- a/examples/functions.cpp +++ b/examples/functions.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" #include inline int my_add(int x, int y) { @@ -35,10 +35,10 @@ int main() { lua.set_function("mult_by_five", &multiplier::by_five); // assert that the functions work - lua.script("assert(my_add(10, 11) == 21)"); - lua.script("assert(my_mul(4.5, 10) == 45)"); - lua.script("assert(mult_by_ten(50) == 500)"); - lua.script("assert(mult_by_five(10) == 50)"); + lua.script("c_assert(my_add(10, 11) == 21)"); + lua.script("c_assert(my_mul(4.5, 10) == 45)"); + lua.script("c_assert(mult_by_ten(50) == 500)"); + lua.script("c_assert(mult_by_five(10) == 50)"); // using lambdas, functions can have state. int x = 0; @@ -46,7 +46,7 @@ int main() { // calling a stateful lambda modifies the value lua.script("inc()"); - assert(x == 10); + c_assert(x == 10); if (x == 10) { // Do something based on this information std::cout << "Yahoo! x is " << x << std::endl; @@ -58,7 +58,7 @@ inc() inc() inc() )"); - assert(x == 40); + c_assert(x == 40); if (x == 40) { // Do something based on this information std::cout << "Yahoo! x is " << x << std::endl; @@ -70,8 +70,8 @@ inc() int value = add(10, 11); // second way to call the function int value2 = add.call(10, 11); - assert(value == 21); - assert(value2 == 21); + c_assert(value == 21); + c_assert(value2 == 21); if (value == 21 && value2 == 21) { std::cout << "Woo, value is 21!" << std::endl; } diff --git a/examples/indirect_function_calls.cpp b/examples/indirect_function_calls.cpp index 129fc70e..ebaa209d 100644 --- a/examples/indirect_function_calls.cpp +++ b/examples/indirect_function_calls.cpp @@ -1,6 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include +#include "assert.hpp" #include sol::variadic_results call_it(sol::object function_name, sol::variadic_args args, sol::this_environment env, sol::this_state L) { @@ -66,8 +67,8 @@ end int subtract_result = lua["subtract_result"]; int add_result = lua["add_result"]; - assert(add_result == 6); - assert(subtract_result == 4); + c_assert(add_result == 6); + c_assert(subtract_result == 4); std::cout << std::endl; return 0; diff --git a/examples/interop/LuaBridge.cpp b/examples/interop/LuaBridge.cpp index 72da26d7..f88f975f 100644 --- a/examples/interop/LuaBridge.cpp +++ b/examples/interop/LuaBridge.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include "assert.hpp" // LuaBridge, // no longer maintained by VinnieFalco: @@ -79,7 +79,7 @@ void check_with_sol(lua_State* L) { sol::state_view lua(L); A& obj = lua["obj"]; (void)obj; - assert(obj.value() == 24); + c_assert(obj.value() == 24); } int main(int, char* []) { diff --git a/examples/interop/assert.hpp b/examples/interop/assert.hpp new file mode 100644 index 00000000..f247fca4 --- /dev/null +++ b/examples/interop/assert.hpp @@ -0,0 +1,30 @@ +#ifndef MY_ASSERT_HPP +#define MY_ASSERT_HPP + +#ifndef NDEBUG +# define m_assert(condition, message) \ + do { \ + if (! (condition)) { \ + std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \ + << " line " << __LINE__ << ": " << message << std::endl; \ + std::terminate(); \ + } \ + } while (false) + +# define c_assert(condition) \ + do { \ + if (! (condition)) { \ + std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \ + << " line " << __LINE__ << std::endl; \ + std::terminate(); \ + } \ + } while (false) +#else +#include +#include + +# define m_c_assert(condition, message) do { (void)sizeof(condition); (void)sizeof(message); } while (false) +# define c_assert(condition) do { (void)sizeof(condition); } while (false) +#endif + +#endif // MY_ASSERT_HPP diff --git a/examples/interop/kaguya.cpp b/examples/interop/kaguya.cpp index 9a2aef5e..0d9f3945 100644 --- a/examples/interop/kaguya.cpp +++ b/examples/interop/kaguya.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include "assert.hpp" // kaguya code lifted from README.md, // written by satoren: @@ -98,7 +98,7 @@ void check_with_sol(lua_State* L) { sol::state_view lua(L); ABC& obj = lua["obj"]; (void)obj; - assert(obj.value() == 24); + c_assert(obj.value() == 24); } int main(int, char* []) { diff --git a/examples/interop/luwra.cpp b/examples/interop/luwra.cpp index f217f82f..d1159f83 100644 --- a/examples/interop/luwra.cpp +++ b/examples/interop/luwra.cpp @@ -5,7 +5,7 @@ #include #include -#include +#include "assert.hpp" // luwra, // another C++ wrapper library: @@ -91,7 +91,7 @@ void check_with_sol(lua_State* L) { sol::state_view lua(L); ABC& obj = lua["obj"]; (void)obj; - assert(obj.value() == 24); + c_assert(obj.value() == 24); } int main(int, char* []) { diff --git a/examples/interop/tolua.cpp b/examples/interop/tolua.cpp index 1d86bd0a..72862214 100644 --- a/examples/interop/tolua.cpp +++ b/examples/interop/tolua.cpp @@ -9,7 +9,7 @@ #include "tolua_Player.h" #include -#include +#include "assert.hpp" // tolua code lifted from some blog, if the link dies // I don't know where else you're gonna find the reference, @@ -52,7 +52,7 @@ void check_with_sol(lua_State* L) { sol::state_view lua(L); Player& obj = lua["obj"]; (void)obj; - assert(obj.getHealth() == 4); + c_assert(obj.getHealth() == 4); } int main(int, char* []) { diff --git a/examples/multi_results.cpp b/examples/multi_results.cpp index e51b7bb8..d3bc6219 100644 --- a/examples/multi_results.cpp +++ b/examples/multi_results.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "assert.hpp" #include int main() { @@ -21,7 +21,7 @@ int main() { lua.script("print('calling multi_tuple')"); lua.script("print(multi_tuple())"); lua.script("x, y = multi_tuple()"); - lua.script("assert(x == 10 and y == 'goodbye')"); + lua.script("c_assert(x == 10 and y == 'goodbye')"); auto multi = lua.get("multi_tuple"); int first; @@ -30,8 +30,8 @@ int main() { sol::tie(first, second) = multi(); // use the values - assert(first == 10); - assert(second == "goodbye"); + c_assert(first == 10); + c_assert(second == "goodbye"); // sol::as_returns // works with any iterable, @@ -50,9 +50,9 @@ int main() { int b = lua["b"]; int c = lua["c"]; - assert(a == 55); - assert(b == 66); - assert(c == 77); + c_assert(a == 55); + c_assert(b == 66); + c_assert(c == 77); // sol::variadic_results // you can push objects of different types @@ -73,9 +73,9 @@ int main() { bool u = lua["u"]; std::string v = lua["v"]; - assert(t == 42); - assert(u); - assert(v == "awoo"); + c_assert(t == 42); + c_assert(u); + c_assert(v == "awoo"); return 0; } \ No newline at end of file diff --git a/examples/overloading.cpp b/examples/overloading.cpp index 6044ebc2..7dc71320 100644 --- a/examples/overloading.cpp +++ b/examples/overloading.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" #include inline int my_add(int x, int y) { diff --git a/examples/require.cpp b/examples/require.cpp index 8d5d190f..db4a85c7 100644 --- a/examples/require.cpp +++ b/examples/require.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" #include struct some_class { @@ -38,7 +38,7 @@ s = my_lib.some_class.new() s.bark = 20; )"); some_class& s = lua["s"]; - assert(s.bark == 20); + c_assert(s.bark == 20); std::cout << "s.bark = " << s.bark << std::endl; std::cout << std::endl; diff --git a/examples/require_dll_example/assert.hpp b/examples/require_dll_example/assert.hpp new file mode 100644 index 00000000..f247fca4 --- /dev/null +++ b/examples/require_dll_example/assert.hpp @@ -0,0 +1,30 @@ +#ifndef MY_ASSERT_HPP +#define MY_ASSERT_HPP + +#ifndef NDEBUG +# define m_assert(condition, message) \ + do { \ + if (! (condition)) { \ + std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \ + << " line " << __LINE__ << ": " << message << std::endl; \ + std::terminate(); \ + } \ + } while (false) + +# define c_assert(condition) \ + do { \ + if (! (condition)) { \ + std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \ + << " line " << __LINE__ << std::endl; \ + std::terminate(); \ + } \ + } while (false) +#else +#include +#include + +# define m_c_assert(condition, message) do { (void)sizeof(condition); (void)sizeof(message); } while (false) +# define c_assert(condition) do { (void)sizeof(condition); } while (false) +#endif + +#endif // MY_ASSERT_HPP diff --git a/examples/require_dll_example/require_from_dll.cpp b/examples/require_dll_example/require_from_dll.cpp index d02f494e..969a56a0 100644 --- a/examples/require_dll_example/require_from_dll.cpp +++ b/examples/require_dll_example/require_from_dll.cpp @@ -2,9 +2,9 @@ #include #include "my_object.hpp" +#include "assert.hpp" #include -#include int main(int, char*[]) { std::cout << "=== require from DLL example ===" << std::endl; @@ -20,7 +20,7 @@ print(obj.value) )"); my_object::test& obj = lua["obj"]; - assert(obj.value == 24); + c_assert(obj.value == 24); return 0; } \ No newline at end of file diff --git a/examples/runtime_additions.cpp b/examples/runtime_additions.cpp index 2dc4b81e..b10f8ef8 100644 --- a/examples/runtime_additions.cpp +++ b/examples/runtime_additions.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" #include struct object { @@ -35,7 +35,7 @@ obj:print() )"); object& obj = lua["obj"]; - assert(obj.value == 1); + c_assert(obj.value == 1); return 0; } diff --git a/examples/script_error_handling.cpp b/examples/script_error_handling.cpp index 66c4e3e1..2968c363 100644 --- a/examples/script_error_handling.cpp +++ b/examples/script_error_handling.cpp @@ -1,6 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include +#include "assert.hpp" #include int main(int, char**) { @@ -26,7 +27,7 @@ return 24 int value = lua.script(code, sol::script_default_on_error); // This will never be reached std::cout << value << std::endl; - assert(value == 24); + c_assert(value == 24); } catch (const sol::error& err) { std::cout << "Something went horribly wrong: thrown error" << "\n\t" << err.what() << std::endl; @@ -40,7 +41,7 @@ return 24 // This will check code validity and also whether or not it runs well { sol::protected_function_result result = lua.script(code, sol::script_pass_on_error); - assert(!result.valid()); + c_assert(!result.valid()); if (!result.valid()) { sol::error err = result; sol::call_status status = result.status(); @@ -58,7 +59,7 @@ return 24 // The two previous approaches are recommended { sol::load_result loaded_chunk = lua.load(code); - assert(!loaded_chunk.valid()); + c_assert(!loaded_chunk.valid()); if (!loaded_chunk.valid()) { sol::error err = loaded_chunk; sol::load_status status = loaded_chunk.status(); @@ -66,7 +67,7 @@ return 24 } else { // Because the syntax is bad, this will never be reached - assert(false); + c_assert(false); // If there is a runtime error (lua GC memory error, nil access, etc.) // it will be caught here sol::protected_function script_func = loaded_chunk; diff --git a/examples/self_from_lua.cpp b/examples/self_from_lua.cpp index ba10738b..b5e1f07e 100644 --- a/examples/self_from_lua.cpp +++ b/examples/self_from_lua.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" // NOTE: // There are TWO ways to retrieve the "this" @@ -22,7 +22,7 @@ int main() { // definitely the same thing& self = selfobj.as(); - assert(&self == this); + c_assert(&self == this); } void func(sol::this_state ts) const { @@ -35,7 +35,7 @@ int main() { thing& self = selfobj.as(); // definitely the same - assert(&self == this); + c_assert(&self == this); } }; diff --git a/examples/stack_aligned_function.cpp b/examples/stack_aligned_function.cpp index 1148e2ea..3447e007 100644 --- a/examples/stack_aligned_function.cpp +++ b/examples/stack_aligned_function.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" int main(int, char*[]) { sol::state lua; @@ -27,8 +27,8 @@ int main(int, char*[]) { int result = func(sol::stack_count(2)); // make sure everything is clean - assert(result == 22); - assert(lua.stack_top() == 0); // stack is empty/balanced + c_assert(result == 22); + c_assert(lua.stack_top() == 0); // stack is empty/balanced return 0; } diff --git a/examples/static_variables.cpp b/examples/static_variables.cpp index 2eedc39d..93e88528 100644 --- a/examples/static_variables.cpp +++ b/examples/static_variables.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "assert.hpp" struct test { static int muh_variable; @@ -23,15 +23,15 @@ int main() { int direct_value = lua["test"]["direct"]; // direct_value == 2 - assert(direct_value == 2); + c_assert(direct_value == 2); std::cout << "direct_value: " << direct_value << std::endl; int global = lua["test"]["global"]; int global2 = lua["test"]["ref_global"]; // global == 25 // global2 == 25 - assert(global == 25); - assert(global2 == 25); + c_assert(global == 25); + c_assert(global2 == 25); std::cout << "First round of values --" << std::endl; std::cout << global << std::endl; @@ -50,8 +50,8 @@ int main() { // if muh_variable goes out of scope or is deleted // problems could arise, so be careful! - assert(global == 25); - assert(global2 == 542); + c_assert(global == 25); + c_assert(global2 == 542); std::cout << "Second round of values --" << std::endl; std::cout << "global : " << global << std::endl; diff --git a/examples/tutorials/quick_n_dirty/assert.hpp b/examples/tutorials/quick_n_dirty/assert.hpp new file mode 100644 index 00000000..f247fca4 --- /dev/null +++ b/examples/tutorials/quick_n_dirty/assert.hpp @@ -0,0 +1,30 @@ +#ifndef MY_ASSERT_HPP +#define MY_ASSERT_HPP + +#ifndef NDEBUG +# define m_assert(condition, message) \ + do { \ + if (! (condition)) { \ + std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \ + << " line " << __LINE__ << ": " << message << std::endl; \ + std::terminate(); \ + } \ + } while (false) + +# define c_assert(condition) \ + do { \ + if (! (condition)) { \ + std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \ + << " line " << __LINE__ << std::endl; \ + std::terminate(); \ + } \ + } while (false) +#else +#include +#include + +# define m_c_assert(condition, message) do { (void)sizeof(condition); (void)sizeof(message); } while (false) +# define c_assert(condition) do { (void)sizeof(condition); } while (false) +#endif + +#endif // MY_ASSERT_HPP diff --git a/examples/tutorials/quick_n_dirty/functions_all.cpp b/examples/tutorials/quick_n_dirty/functions_all.cpp index 5edee583..23cc2ac8 100644 --- a/examples/tutorials/quick_n_dirty/functions_all.cpp +++ b/examples/tutorials/quick_n_dirty/functions_all.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" #include void some_function() { diff --git a/examples/tutorials/quick_n_dirty/functions_easy.cpp b/examples/tutorials/quick_n_dirty/functions_easy.cpp index 44adb9f2..dc995301 100644 --- a/examples/tutorials/quick_n_dirty/functions_easy.cpp +++ b/examples/tutorials/quick_n_dirty/functions_easy.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" int main(int, char*[]) { sol::state lua; @@ -18,15 +18,15 @@ int main(int, char*[]) { std::function stdfx = fx; int is_one = stdfx(1, 34.5, 3, "bark"); - assert(is_one == 1); + c_assert(is_one == 1); int is_also_one = fx(1, "boop", 3, "bark"); - assert(is_also_one == 1); + c_assert(is_also_one == 1); // call through operator[] int is_three = lua["g"](1, 2); - assert(is_three == 3); + c_assert(is_three == 3); double is_4_8 = lua["g"](2.4, 2.4); - assert(is_4_8 == 4.8); + c_assert(is_4_8 == 4.8); return 0; } diff --git a/examples/tutorials/quick_n_dirty/make_tables.cpp b/examples/tutorials/quick_n_dirty/make_tables.cpp index 71653168..f703c762 100644 --- a/examples/tutorials/quick_n_dirty/make_tables.cpp +++ b/examples/tutorials/quick_n_dirty/make_tables.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" int main(int, char* []) { sol::state lua; diff --git a/examples/tutorials/quick_n_dirty/multiple_returns_from_lua.cpp b/examples/tutorials/quick_n_dirty/multiple_returns_from_lua.cpp index 9b955777..d21361cd 100644 --- a/examples/tutorials/quick_n_dirty/multiple_returns_from_lua.cpp +++ b/examples/tutorials/quick_n_dirty/multiple_returns_from_lua.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" int main(int, char* []) { sol::state lua; @@ -15,9 +15,9 @@ int main(int, char* []) { int b; std::string c; sol::tie(a, b, c) = lua["f"](100, 200, "bark"); - assert(a == 100); - assert(b == 200); - assert(c == "bark"); + c_assert(a == 100); + c_assert(b == 200); + c_assert(c == "bark"); return 0; } diff --git a/examples/tutorials/quick_n_dirty/multiple_returns_to_lua.cpp b/examples/tutorials/quick_n_dirty/multiple_returns_to_lua.cpp index 2c9ee7ff..42caf3b8 100644 --- a/examples/tutorials/quick_n_dirty/multiple_returns_to_lua.cpp +++ b/examples/tutorials/quick_n_dirty/multiple_returns_to_lua.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" int main(int, char* []) { sol::state lua; @@ -14,19 +14,19 @@ int main(int, char* []) { std::tuple result = lua["f"](100, 200, 300); const std::tuple expected(100, 200, 300); - assert(result == expected); + c_assert(result == expected); std::tuple result2; result2 = lua["f"](100, 200, "BARK BARK BARK!"); const std::tuple expected2(100, 200, "BARK BARK BARK!"); - assert(result2 == expected2); + c_assert(result2 == expected2); int a, b; std::string c; sol::tie(a, b, c) = lua["f"](100, 200, "bark"); - assert(a == 100); - assert(b == 200); - assert(c == "bark"); + c_assert(a == 100); + c_assert(b == 200); + c_assert(c == "bark"); lua.script(R"( a, b, c = f(150, 250, "woofbark") diff --git a/examples/tutorials/quick_n_dirty/namespacing.cpp b/examples/tutorials/quick_n_dirty/namespacing.cpp index 2c03aa44..c8b8e9fd 100644 --- a/examples/tutorials/quick_n_dirty/namespacing.cpp +++ b/examples/tutorials/quick_n_dirty/namespacing.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "assert.hpp" int main() { std::cout << "=== namespacing example ===" << std::endl; @@ -39,7 +39,7 @@ int main() { // calling this function also works lua.script("bark.print_my_class(obj)"); my_class& obj = lua["obj"]; - assert(obj.b == 25); + c_assert(obj.b == 25); std::cout << std::endl; diff --git a/examples/tutorials/quick_n_dirty/opening_a_state.cpp b/examples/tutorials/quick_n_dirty/opening_a_state.cpp index e7f6cce3..7b483781 100644 --- a/examples/tutorials/quick_n_dirty/opening_a_state.cpp +++ b/examples/tutorials/quick_n_dirty/opening_a_state.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "assert.hpp" int main(int, char*[]) { std::cout << "=== opening a state example ===" << std::endl; diff --git a/examples/tutorials/quick_n_dirty/running_lua_code.cpp b/examples/tutorials/quick_n_dirty/running_lua_code.cpp index 894c8007..86c7a20e 100644 --- a/examples/tutorials/quick_n_dirty/running_lua_code.cpp +++ b/examples/tutorials/quick_n_dirty/running_lua_code.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include "assert.hpp" int main(int, char*[]) { std::cout << "=== running lua code example ===" << std::endl; @@ -23,7 +23,7 @@ int main(int, char*[]) { // run a script, get the result int value = lua.script("return 54"); - assert(value == 54); + c_assert(value == 54); auto bad_code_result = lua.script("123 herp.derp", [](lua_State*, sol::protected_function_result pfr) { // pfr will contain things that went wrong, for either loading or executing the script @@ -32,7 +32,7 @@ int main(int, char*[]) { return pfr; }); // it did not work - assert(!bad_code_result.valid()); + c_assert(!bad_code_result.valid()); // the default handler panics or throws, depending on your settings // uncomment for explosions: diff --git a/examples/tutorials/quick_n_dirty/running_lua_code_low_level.cpp b/examples/tutorials/quick_n_dirty/running_lua_code_low_level.cpp index 0155fd18..a090f158 100644 --- a/examples/tutorials/quick_n_dirty/running_lua_code_low_level.cpp +++ b/examples/tutorials/quick_n_dirty/running_lua_code_low_level.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include "assert.hpp" int main(int, char*[]) { std::cout << "=== running lua code (low level) example ===" << std::endl; @@ -37,7 +37,7 @@ int main(int, char*[]) { sol::load_result script3 = lua.load("return 24"); // execute, get return value int value2 = script3(); - assert(value2 == 24); + c_assert(value2 == 24); std::cout << std::endl; diff --git a/examples/tutorials/quick_n_dirty/set_and_get_variables.cpp b/examples/tutorials/quick_n_dirty/set_and_get_variables.cpp index daf3ac9d..d605c104 100644 --- a/examples/tutorials/quick_n_dirty/set_and_get_variables.cpp +++ b/examples/tutorials/quick_n_dirty/set_and_get_variables.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" int main(int, char*[]) { sol::state lua; @@ -44,40 +44,40 @@ int main(int, char*[]) { // implicit conversion int number = lua["number"]; - assert(number == 24); + c_assert(number == 24); // explicit get auto number2 = lua.get("number2"); - assert(number2 == 24.5); + c_assert(number2 == 24.5); // strings too std::string important_string = lua["important_string"]; - assert(important_string == "woof woof"); + c_assert(important_string == "woof woof"); // dig into a table int value = lua["some_table"]["value"]; - assert(value == 24); + c_assert(value == 24); // get a function sol::function a_function = lua["a_function"]; int value_is_100 = a_function(); // convertible to std::function std::function a_std_function = a_function; int value_is_still_100 = a_std_function(); - assert(value_is_100 == 100); - assert(value_is_still_100 == 100); + c_assert(value_is_100 == 100); + c_assert(value_is_still_100 == 100); sol::object number_obj = lua.get("number"); // sol::type::number sol::type t1 = number_obj.get_type(); - assert(t1 == sol::type::number); + c_assert(t1 == sol::type::number); sol::object function_obj = lua["a_function"]; // sol::type::function sol::type t2 = function_obj.get_type(); - assert(t2 == sol::type::function); + c_assert(t2 == sol::type::function); bool is_it_really = function_obj.is>(); - assert(is_it_really); + c_assert(is_it_really); // will not contain data sol::optional check_for_me = lua["a_function"]; - assert(check_for_me == sol::nullopt); + c_assert(check_for_me == sol::nullopt); return 0; } diff --git a/examples/tutorials/quick_n_dirty/set_and_get_variables_exists.cpp b/examples/tutorials/quick_n_dirty/set_and_get_variables_exists.cpp index 74624dc4..f16d236b 100644 --- a/examples/tutorials/quick_n_dirty/set_and_get_variables_exists.cpp +++ b/examples/tutorials/quick_n_dirty/set_and_get_variables_exists.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" int main(int, char*[]) { sol::state lua; @@ -10,11 +10,11 @@ int main(int, char*[]) { lua.script("exists = 250"); int first_try = lua.get_or("exists", 322); - assert(first_try == 250); + c_assert(first_try == 250); lua.set("exists", sol::lua_nil); int second_try = lua.get_or("exists", 322); - assert(second_try == 322); + c_assert(second_try == 322); return 0; } diff --git a/examples/tutorials/quick_n_dirty/tables_and_nesting.cpp b/examples/tutorials/quick_n_dirty/tables_and_nesting.cpp index ac03384a..f4f3c68b 100644 --- a/examples/tutorials/quick_n_dirty/tables_and_nesting.cpp +++ b/examples/tutorials/quick_n_dirty/tables_and_nesting.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" int main(int, char*[]) { @@ -24,19 +24,19 @@ int main(int, char*[]) { int bark1 = def["ghi"]["bark"]; int bark2 = lua["def"]["ghi"]["bark"]; - assert(bark1 == 50); - assert(bark2 == 50); + c_assert(bark1 == 50); + c_assert(bark2 == 50); int abcval1 = abc[0]; int abcval2 = ghi["woof"][0]; - assert(abcval1 == 24); - assert(abcval2 == 24); + c_assert(abcval1 == 24); + c_assert(abcval2 == 24); sol::optional will_not_error = lua["abc"]["DOESNOTEXIST"]["ghi"]; - assert(will_not_error == sol::nullopt); + c_assert(will_not_error == sol::nullopt); int also_will_not_error = lua["abc"]["def"]["ghi"]["jklm"].get_or(25); - assert(also_will_not_error == 25); + c_assert(also_will_not_error == 25); // if you don't go safe, // will throw (or do at_panic if no exceptions) diff --git a/examples/tutorials/quick_n_dirty/userdata.cpp b/examples/tutorials/quick_n_dirty/userdata.cpp index daf8a8f4..7163bffc 100644 --- a/examples/tutorials/quick_n_dirty/userdata.cpp +++ b/examples/tutorials/quick_n_dirty/userdata.cpp @@ -1,6 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include +#include "assert.hpp" #include struct Doge { @@ -49,11 +50,11 @@ int main(int, char* []) { Doge& lua_dog_move = lua["dog_move"]; Doge& lua_dog_unique_ptr = lua["dog_unique_ptr"]; Doge& lua_dog_shared_ptr = lua["dog_shared_ptr"]; - assert(lua_dog.tailwag == 50); - assert(lua_dog_copy.tailwag == 30); - assert(lua_dog_move.tailwag == 30); - assert(lua_dog_unique_ptr.tailwag == 25); - assert(lua_dog_shared_ptr.tailwag == 31); + c_assert(lua_dog.tailwag == 50); + c_assert(lua_dog_copy.tailwag == 30); + c_assert(lua_dog_move.tailwag == 30); + c_assert(lua_dog_unique_ptr.tailwag == 25); + c_assert(lua_dog_shared_ptr.tailwag == 31); // lua will treat these types as opaque, and you will be able to pass them around // to C++ functions and Lua functions alike diff --git a/examples/usertype.cpp b/examples/usertype.cpp index 91073697..b2899157 100644 --- a/examples/usertype.cpp +++ b/examples/usertype.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "assert.hpp" #include struct foo { @@ -96,7 +96,7 @@ int main() { lua.script("v = vector.new()\n" "v = vector.new(12)\n" "v = vector.new(10, 10)\n" - "assert(not v:is_unit())\n"); + "c_assert(not v:is_unit())\n"); // You can even have C++-like member-variable-access // just pass is public member variables in the same style as functions @@ -108,7 +108,7 @@ int main() { "assert(not vars.low_gravity)\n" "vars.low_gravity = true\n" "local x = vars.low_gravity\n" - "assert(x)"); + "c_assert(x)"); std::cout << std::endl; diff --git a/examples/usertype_bitfields.cpp b/examples/usertype_bitfields.cpp index 6572ce63..7c80310e 100644 --- a/examples/usertype_bitfields.cpp +++ b/examples/usertype_bitfields.cpp @@ -95,7 +95,7 @@ namespace itsy_bitsy { } #include -#include +#include "assert.hpp" #if defined(_MSC_VER) || defined(__MINGW32__) #pragma pack(1) @@ -154,9 +154,9 @@ int main() { std::cout << "N: " << N << std::endl; std::cout << "D: " << D << std::endl; - assert(C); - assert(N); - assert(D == 0xDF); + c_assert(C); + c_assert(N); + c_assert(D == 0xDF); std::cout << std::endl; diff --git a/examples/usertype_dynamic_getter_setter.cpp b/examples/usertype_dynamic_getter_setter.cpp index e33e271d..67a82aee 100644 --- a/examples/usertype_dynamic_getter_setter.cpp +++ b/examples/usertype_dynamic_getter_setter.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include "assert.hpp" #include // Note that this is a bunch of if/switch statements @@ -149,8 +149,8 @@ int main() { sol::userdata v1 = lua["v1"]; double v1x = v1["x"]; double v1y = v1["y"]; - assert(v1x == 1.000); - assert(v1y == 0.000); + c_assert(v1x == 1.000); + c_assert(v1y == 0.000); v1[0] = 2.000; lua.script(R"( diff --git a/examples/usertype_initializers.cpp b/examples/usertype_initializers.cpp index 8aad45eb..1e4908a0 100644 --- a/examples/usertype_initializers.cpp +++ b/examples/usertype_initializers.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include "assert.hpp" struct holy { private: @@ -61,8 +61,8 @@ print('h2.data is ' .. h2.data) )"); holy& h1 = lua["h1"]; holy& h2 = lua["h2"]; - assert(h1.data == 50); - assert(h2.data == 0); + c_assert(h1.data == 50); + c_assert(h2.data == 0); } std::cout << std::endl; } \ No newline at end of file diff --git a/examples/usertype_simple.cpp b/examples/usertype_simple.cpp index 16bfe3bb..7986514b 100644 --- a/examples/usertype_simple.cpp +++ b/examples/usertype_simple.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include "assert.hpp" class generator { private: @@ -84,13 +84,13 @@ end std::vector& list1 = lua["list1"]; std::vector& list2 = lua["list2"]; std::vector& list3 = lua["list3"]; - assert(list1.size() == 5); - assert(list2.size() == 5); - assert(list3.size() == 5); + c_assert(list1.size() == 5); + c_assert(list2.size() == 5); + c_assert(list3.size() == 5); for (int i = 1; i <= 5; ++i) { - assert(list1[i - 1] == (mdata.first % 10) * i); - assert(list2[i - 1] == (mdata.second % 10) * i); - assert(list3[i - 1] == (mdata.third % 10) * i); + c_assert(list1[i - 1] == (mdata.first % 10) * i); + c_assert(list2[i - 1] == (mdata.second % 10) * i); + c_assert(list3[i - 1] == (mdata.third % 10) * i); } std::cout << std::endl; diff --git a/examples/usertype_special_functions.cpp b/examples/usertype_special_functions.cpp index f68ca56e..d957016d 100644 --- a/examples/usertype_special_functions.cpp +++ b/examples/usertype_special_functions.cpp @@ -1,7 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include -#include +#include "assert.hpp" #include struct vec { @@ -57,8 +57,8 @@ int main() { vec& a1 = lua["a1"]; vec& s1 = lua["s1"]; - assert(a1.x == 1 && a1.y == 1); - assert(s1.x == 1 && s1.y == -1); + c_assert(a1.x == 1 && a1.y == 1); + c_assert(s1.x == 1 && s1.y == -1); lua["a2"] = lua["a1"]; diff --git a/examples/usertype_var.cpp b/examples/usertype_var.cpp index 2142c857..9462c73e 100644 --- a/examples/usertype_var.cpp +++ b/examples/usertype_var.cpp @@ -1,6 +1,7 @@ #define SOL_CHECK_ARGUMENTS 1 #include +#include "assert.hpp" #include struct test { @@ -19,21 +20,21 @@ int main() { ); int direct_value = lua["test"]["direct"]; - assert(direct_value == 2); + c_assert(direct_value == 2); // direct_value == 2 int number = lua["test"]["number"]; - assert(number == 25); + c_assert(number == 25); int ref_number = lua["test"]["ref_number"]; - assert(ref_number == 25); + c_assert(ref_number == 25); test::number = 542; - assert(lua["test"]["number"] == 25); + c_assert(lua["test"]["number"] == 25); // number is its own memory: was passed by value // So does not change - assert(lua["test"]["ref_number"] == 542); + c_assert(lua["test"]["ref_number"] == 542); // ref_number is just test::number // passed through std::ref // so, it holds a reference diff --git a/examples/variables.cpp b/examples/variables.cpp index c8f5b7fd..04bb196f 100644 --- a/examples/variables.cpp +++ b/examples/variables.cpp @@ -17,8 +17,8 @@ int main() { lua.set("y", "hello"); // assert values are as given - lua.script("assert(x == 10)"); - lua.script("assert(y == 'hello')"); + lua.script("c_assert(x == 10)"); + lua.script("c_assert(y == 'hello')"); // basic retrieval of a variable diff --git a/examples/variadic_args.cpp b/examples/variadic_args.cpp index 591558a2..64b4dcdb 100644 --- a/examples/variadic_args.cpp +++ b/examples/variadic_args.cpp @@ -32,9 +32,9 @@ int main() { // will error: not enough arguments //lua.script("x4 = v(1)"); - lua.script("assert(x == 50)"); - lua.script("assert(x2 == 600)"); - lua.script("assert(x3 == 21)"); + lua.script("c_assert(x == 50)"); + lua.script("c_assert(x2 == 600)"); + lua.script("c_assert(x3 == 21)"); lua.script("print(x)"); // 50 lua.script("print(x2)"); // 600 lua.script("print(x3)"); // 21 diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index ba6f7b9f..185c6a1d 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-12-11 17:29:42.822392 UTC -// This header was generated with sol v2.19.0 (revision cf81d81) +// Generated 2017-12-26 04:26:55.295046 UTC +// This header was generated with sol v2.19.0 (revision acade46) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -64,17 +64,19 @@ // beginning of sol/feature_test.hpp -#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && _MSVC_LANG > 201402L))) +#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L)))) #ifndef SOL_CXX17_FEATURES #define SOL_CXX17_FEATURES 1 #endif // C++17 features macro #endif // C++17 features check -#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L))) +#ifdef SOL_CXX17_FEATURES +#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && (defined(_MSVC_LANG) && ((_MSVC_LANG >= 201703L) && defined(_WIN64)))) #ifndef SOL_NOEXCEPT_FUNCTION_TYPE #define SOL_NOEXCEPT_FUNCTION_TYPE 1 #endif // noexcept is part of a function's type -#endif +#endif // compiler-specific checks +#endif // C++17 only #if defined(_WIN32) || defined(_MSC_VER) #ifndef SOL_CODECVT_SUPPORT @@ -430,10 +432,10 @@ namespace sol { }; template - using tuple_element = std::tuple_element>; + using tuple_element = std::tuple_element>; template - using tuple_element_t = std::tuple_element_t>; + using tuple_element_t = std::tuple_element_t>; template using unqualified_tuple_element = unqualified>; @@ -1175,9 +1177,9 @@ namespace sol { struct always_true : std::true_type {}; struct is_invokable_tester { template - always_true()(std::declval()...))> static test(int); + static always_true()(std::declval()...))> test(int); template - std::false_type static test(...); + static std::false_type test(...); }; } // namespace meta_detail @@ -1406,6 +1408,11 @@ namespace sol { std::true_type supports_adl_to_string(const T&); std::false_type supports_adl_to_string(...); #endif + + template + struct is_matched_lookup_impl : std::false_type {}; + template + struct is_matched_lookup_impl : std::is_same {}; } // namespace meta_detail #if defined(_MSC_VER) && _MSC_VER <= 1910 @@ -1473,6 +1480,9 @@ namespace sol { template struct is_lookup : meta::all, has_value_type> {}; + template + struct is_matched_lookup : meta_detail::is_matched_lookup_impl, has_value_type>::value> {}; + template using is_string_constructible = any< std::is_same, const char*>, std::is_same, char>, std::is_same, std::string>, std::is_same, std::initializer_list> @@ -3085,38 +3095,38 @@ namespace sol { // workaround for missing traits in GCC and CLANG template struct is_nothrow_move_constructible { - constexpr static bool value = ::std::is_nothrow_constructible::value; + static constexprbool value = ::std::is_nothrow_constructible::value; }; template struct is_assignable { template - constexpr static bool has_assign(...) { + static constexprbool has_assign(...) { return false; } template () = ::std::declval(), true))> // the comma operator is necessary for the cases where operator= returns void - constexpr static bool has_assign(bool) { + static constexprbool has_assign(bool) { return true; } - constexpr static bool value = has_assign(true); + static constexprbool value = has_assign(true); }; template struct is_nothrow_move_assignable { template struct has_nothrow_move_assign { - constexpr static bool value = false; + static constexprbool value = false; }; template struct has_nothrow_move_assign { - constexpr static bool value = noexcept(::std::declval() = ::std::declval()); + static constexprbool value = noexcept(::std::declval() = ::std::declval()); }; - constexpr static bool value = has_nothrow_move_assign::value>::value; + static constexprbool value = has_nothrow_move_assign::value>::value; }; // end workaround @@ -3159,16 +3169,16 @@ namespace sol { template struct has_overloaded_addressof { template - constexpr static bool has_overload(...) { + static constexpr bool has_overload(...) { return false; } template ().operator&())> - constexpr static bool has_overload(bool) { + static constexpr bool has_overload(bool) { return true; } - constexpr static bool value = has_overload(true); + static constexpr bool value = has_overload(true); }; template )> @@ -5650,7 +5660,7 @@ namespace detail { inline std::string ctti_get_type_name() { // cardinal sins from MINGW using namespace std; - const static std::array removals = {{"{anonymous}", "(anonymous namespace)"}}; + static const std::array removals = {{"{anonymous}", "(anonymous namespace)"}}; std::string name = __PRETTY_FUNCTION__; std::size_t start = name.find_first_of('['); start = name.find_first_of('=', start); @@ -5684,7 +5694,7 @@ namespace detail { #elif defined(_MSC_VER) template inline std::string ctti_get_type_name() { - const static std::array removals = {{"public:", "private:", "protected:", "struct ", "class ", "`anonymous-namespace'", "`anonymous namespace'"}}; + static const std::array removals = {{"public:", "private:", "protected:", "struct ", "class ", "`anonymous-namespace'", "`anonymous namespace'"}}; std::string name = __FUNCSIG__; std::size_t start = name.find("get_type_name"); if (start == std::string::npos) @@ -10070,14 +10080,18 @@ namespace stack { struct popper { inline static decltype(auto) pop(lua_State* L) { record tracking{}; +#ifdef __INTEL_COMPILER + auto&& r = get(L, -lua_size::value, tracking); +#else decltype(auto) r = get(L, -lua_size::value, tracking); +#endif lua_pop(L, tracking.used); return r; } }; template - struct popper>::value>> { + struct popper>::value>> { static_assert(meta::neg>>::value, "You cannot pop something that derives from stack_reference: it will not remain on the stack and thusly will go out of scope!"); }; } @@ -10435,10 +10449,10 @@ namespace sol { template inline int push_as_upvalues(lua_State* L, T& item) { typedef std::decay_t TValue; - const static std::size_t itemsize = sizeof(TValue); - const static std::size_t voidsize = sizeof(void*); - const static std::size_t voidsizem1 = voidsize - 1; - const static std::size_t data_t_count = (sizeof(TValue) + voidsizem1) / voidsize; + static const std::size_t itemsize = sizeof(TValue); + static const std::size_t voidsize = sizeof(void*); + static const std::size_t voidsizem1 = voidsize - 1; + static const std::size_t data_t_count = (sizeof(TValue) + voidsizem1) / voidsize; typedef std::array data_t; data_t data{ {} }; @@ -10452,7 +10466,7 @@ namespace sol { template inline std::pair get_as_upvalues(lua_State* L, int index = 2) { - const static std::size_t data_t_count = (sizeof(T) + (sizeof(void*) - 1)) / sizeof(void*); + static const std::size_t data_t_count = (sizeof(T) + (sizeof(void*) - 1)) / sizeof(void*); typedef std::array data_t; data_t voiddata{ {} }; for (std::size_t i = 0, d = 0; d < sizeof(T); ++i, d += sizeof(void*)) { @@ -15188,25 +15202,36 @@ namespace sol { typedef container_traits deferred_traits; typedef meta::is_associative is_associative; typedef meta::is_lookup is_lookup; + typedef meta::is_matched_lookup is_matched_lookup; typedef typename T::iterator iterator; typedef typename T::value_type value_type; - typedef std::conditional_t, std::pair>> - KV; + typedef std::conditional_t, + std::conditional_t + > + > KV; typedef typename KV::first_type K; typedef typename KV::second_type V; typedef decltype(*std::declval()) iterator_return; + typedef std::conditional_t, + std::conditional_t + > captured_type; typedef typename meta::iterator_tag::type iterator_category; typedef std::is_same is_input_iterator; typedef std::conditional_t, iterator_return>>()))> - push_type; + decltype(detail::deref(std::declval())) + > push_type; typedef std::is_copy_assignable is_copyable; typedef meta::neg, std::is_const>, meta::neg>> - is_writable; + std::is_const, std::is_const>, meta::neg + >> is_writable; typedef meta::unqualified_t>()))> key_type; typedef meta::all, meta::neg>> is_linear_integral; @@ -15231,7 +15256,7 @@ namespace sol { } return *p.value(); #else - return stack::get(L, 1); + return stack::get(L, 1); #endif // Safe getting with error } @@ -15763,7 +15788,8 @@ namespace sol { template static int next(lua_State* L) { - return next_associative(is_associative(), L); + typedef meta::any>> is_assoc; + return next_associative(is_assoc(), L); } public: @@ -15851,11 +15877,13 @@ namespace sol { } static int pairs(lua_State* L) { - return pairs_associative(is_associative(), L); + typedef meta::any>> is_assoc; + return pairs_associative(is_assoc(), L); } static int ipairs(lua_State* L) { - return pairs_associative(is_associative(), L); + typedef meta::any>> is_assoc; + return pairs_associative(is_assoc(), L); } }; @@ -18352,8 +18380,8 @@ namespace sol { stack::check(lua_state(), -1, handler); #endif // Safety } - basic_table_core(lua_State* L, new_table nt) - : base_t(L, (lua_createtable(L, nt.sequence_hint, nt.map_hint), -1)) { + basic_table_core(lua_State* L, const new_table& nt) + : base_t(L, -stack::push(L, nt)) { if (!is_stack_based>::value) { lua_pop(L, 1); } diff --git a/single/sol/sol_forward.hpp b/single/sol/sol_forward.hpp index 438d5130..a7cd982d 100644 --- a/single/sol/sol_forward.hpp +++ b/single/sol/sol_forward.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-12-11 17:29:42.995868 UTC -// This header was generated with sol v2.19.0 (revision cf81d81) +// Generated 2017-12-26 04:26:55.501596 UTC +// This header was generated with sol v2.19.0 (revision acade46) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP @@ -31,17 +31,19 @@ // beginning of sol/feature_test.hpp -#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && _MSVC_LANG > 201402L))) +#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L)))) #ifndef SOL_CXX17_FEATURES #define SOL_CXX17_FEATURES 1 #endif // C++17 features macro #endif // C++17 features check -#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L))) +#ifdef SOL_CXX17_FEATURES +#if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && (defined(_MSVC_LANG) && ((_MSVC_LANG >= 201703L) && defined(_WIN64)))) #ifndef SOL_NOEXCEPT_FUNCTION_TYPE #define SOL_NOEXCEPT_FUNCTION_TYPE 1 #endif // noexcept is part of a function's type -#endif +#endif // compiler-specific checks +#endif // C++17 only #if defined(_WIN32) || defined(_MSC_VER) #ifndef SOL_CODECVT_SUPPORT