Skip to content

Commit

Permalink
✨ New exhaustive check feature for vectors & similar
Browse files Browse the repository at this point in the history
  • Loading branch information
ShepherdSoasis authored and ThePhD committed Nov 9, 2022
1 parent c4e843b commit 3592851
Show file tree
Hide file tree
Showing 91 changed files with 797 additions and 389 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ x86/
scratch/

# CMake
/.cmake
build/
build-sol2/
CMakeCache.txt
Expand Down
2 changes: 1 addition & 1 deletion cmake/Packages/FindLuaBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function(find_lua_build LUA_VERSION)
else()
set(LUA_BUILD_LIBNAME lua-${LUA_VERSION})
endif()
set(LUA_BUILD_TOPLEVEL "${CMAKE_BINARY_DIR}/vendor/${LUA_BUILD_LIBNAME}")
set(LUA_BUILD_TOPLEVEL "${CMAKE_BINARY_DIR}/_deps/${LUA_BUILD_LIBNAME}")
set(LUA_BUILD_INSTALL_DIR "${LUA_BUILD_TOPLEVEL}")
# # Misc needed variables
set(LUA_BUILD_LIBRARY_DESCRIPTION "The base name of the library to build either the static or the dynamic library")
Expand Down
71 changes: 26 additions & 45 deletions cmake/Packages/FindLuaBuild/LuaVanilla.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ elseif (LUA_VANILLA_VERSION MATCHES "^5\\.2")
set(LUA_VANILLA_LIB_SOURCES lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c
lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c
lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c
lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c
lauxlib.c lbaselib.c lcorolib.c ldblib.c liolib.c
lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c)
set(LUA_VANILLA_LUA_SOURCES lua.c )
if (LUA_BUILD_LUA_COMPILER)
Expand Down Expand Up @@ -144,7 +144,7 @@ if (LUA_BUILD_LUA_COMPILER)
endif()
set(LUA_VANILLA_GENERATE_LUA_HPP false)
else()
MESSAGE(WARNING "Using Lua 5.4.1 file list for ${LUA_VERSION} version")
MESSAGE(WARNING "Using Lua 5.4.4 file list for ${LUA_VERSION} version")
set(LUA_VANILLA_LIB_SOURCES lapi.c lauxlib.c lbaselib.c lcode.c lcorolib.c
lctype.c ldblib.c ldebug.c ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c
llex.c lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c loslib.c
Expand All @@ -157,66 +157,49 @@ endif()
set(LUA_VANILLA_GENERATE_LUA_HPP false)
endif()

set(LUA_VANILLA_SOURCE_DIR "${LUA_BUILD_TOPLEVEL}/src")
prepend(LUA_VANILLA_LIB_SOURCES "${LUA_VANILLA_SOURCE_DIR}/" ${LUA_VANILLA_LIB_SOURCES})
prepend(LUA_VANILLA_LUA_SOURCES "${LUA_VANILLA_SOURCE_DIR}/" ${LUA_VANILLA_LUA_SOURCES})

# download, just for the sake of download + extract
# or pull from local folder
if (LUA_LOCAL_DIR)
set(LUA_VANILLA_SOURCE_DIR ${LUA_BUILD_TOPLEVEL}-src)
list(TRANSFORM LUA_VANILLA_LIB_SOURCES PREPEND "${LUA_VANILLA_SOURCE_DIR}/src/")
list(TRANSFORM LUA_VANILLA_LUA_SOURCES PREPEND "${LUA_VANILLA_SOURCE_DIR}/src/")
file(COPY "${LUA_LOCAL_DIR}/src"
DESTINATION "${LUA_BUILD_TOPLEVEL}")
DESTINATION "${LUA_VANILLA_SOURCE_DIR}/")
file(COPY "${LUA_LOCAL_DIR}/include"
DESTINATION "${LUA_BUILD_TOPLEVEL}")
DESTINATION "${LUA_VANILLA_SOURCE_DIR}/")
add_custom_target(LUA_VANILLA
DEPENDS "${LUA_VANILLA_LIB_SOURCES}" "${LUA_VANILLA_LUA_SOURCES}")
set(LUA_VANILLA_INCLUDE_DIRS ${LUA_VANILLA_INCLUDE_DIRS} "${LUA_VANILLA_SOURCE_DIR}" "${LUA_BUILD_TOPLEVEL}/include")
set(LUA_VANILLA_INCLUDE_DIRS ${LUA_VANILLA_INCLUDE_DIRS} "${LUA_VANILLA_SOURCE_DIR}/include")
else()
ExternalProject_Add(LUA_VANILLA
BUILD_IN_SOURCE TRUE
BUILD_ALWAYS FALSE
TLS_VERIFY TRUE
PREFIX ${LUA_BUILD_TOPLEVEL}
SOURCE_DIR ${LUA_BUILD_TOPLEVEL}
DOWNLOAD_DIR ${LUA_BUILD_TOPLEVEL}
TMP_DIR "${LUA_BUILD_TOPLEVEL}-tmp"
STAMP_DIR "${LUA_BUILD_TOPLEVEL}-stamp"
INSTALL_DIR "${LUA_BUILD_INSTALL_DIR}"
URL ${LUA_VANILLA_DOWNLOAD_URL}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
BUILD_BYPRODUCTS "${LUA_VANILLA_LIB_SOURCES}" "${LUA_VANILLA_LUA_SOURCES}")

# make a quick lua.hpp for 5.1 targets that don't have it
include(FetchContent)
FetchContent_Declare(
lua-vanilla
URL ${LUA_VANILLA_DOWNLOAD_URL})
FetchContent_GetProperties(lua-vanilla)
if ( NOT lua-vanilla_POPULATED)
# Fetch the content using previously declared details
FetchContent_Populate(lua-vanilla)
# do not add_subdirectory / build: we are JUST using ti as a download step!
endif()
list(TRANSFORM LUA_VANILLA_LIB_SOURCES PREPEND "${lua-vanilla_SOURCE_DIR}/src/")
list(TRANSFORM LUA_VANILLA_LUA_SOURCES PREPEND "${lua-vanilla_SOURCE_DIR}/src/")
# make a quick lua.hpp for targets that don't have it
if (LUA_VANILLA_GENERATE_LUA_HPP)
set(LUA_VANILLA_LUA_HPP_CONTENT "// lua.hpp
// Lua header files for C++
// <<extern \"C\">> not supplied automatically because Lua also compiles as C++
extern \"C\" {
#include \"lua.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_LUA_HPP_CONTENT}")
set(LUA_VANILLA_SOURCE_LUA_HPP "${lua-vanilla_SOURCE_DIR}/include/lua.hpp")
file(CONFIGURE OUTPUT "${LUA_VANILLA_SOURCE_LUA_HPP}" CONTENT "${LUA_VANILLA_LUA_HPP_CONTENT}" @ONLY)
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
prebuild
# after download, before build
DEPENDEES download
DEPENDERS build
BYPRODUCTS "${LUA_VANILLA_DESTINATION_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()

set(LUA_VANILLA_INCLUDE_DIRS ${LUA_VANILLA_SOURCE_DIR})
set(LUA_VANILLA_INCLUDE_DIRS ${lua-vanilla_SOURCE_DIR}/include)
endif()

# # Target names
Expand All @@ -233,7 +216,7 @@ set(luacompiler "luac-${LUA_VANILLA_VERSION}")

# make an actual, buildable target
# that other parts of the code can depend on
add_library(${liblua} ${LUA_BUILD_LIBRARY_TYPE} "${LUA_VANILLA_LIB_SOURCES}")
add_library(${liblua} ${LUA_BUILD_LIBRARY_TYPE} ${LUA_VANILLA_LIB_SOURCES})
set_target_properties(${liblua}
PROPERTIES
LANGUAGE ${LUA_VANILLA_LANGUAGE}
Expand All @@ -259,8 +242,6 @@ else()
PRIVATE -w)
endif()
if (WIN32)
#target_compile_definitions(${liblua}
# PRIVATE LUA_USE_WINDOWS)
else()
target_compile_definitions(${liblua}
PRIVATE LUA_USE_LINUX)
Expand Down Expand Up @@ -353,4 +334,4 @@ set(LUA_INTERPRETER ${luainterpreter})
if (LUA_BUILD_LUA_COMPILER)
set(LUA_COMPILER ${luacompiler})
endif()
set(LUA_INCLUDE_DIRS "${LUA_VANILLA_SOURCE_DIR}")
set(LUA_INCLUDE_DIRS ${LUA_VANILLA_INCLUDE_DIRS})
2 changes: 1 addition & 1 deletion documentation/source/tutorial/all-the-things.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ asserts / prerequisites

You'll need to ``#include <sol/sol.hpp>`` somewhere in your code. sol is header-only, so you don't need to compile anything. However, **Lua must be compiled and available**. See the :doc:`getting started tutorial<getting-started>` for more details.

Below, you will see use of a function called ``sol_c_assert``. This is an assert macro that comes with sol2 for the expression purpose of checking things; it's value is immaterial.
Below, you will see use of a function called ``SOL_ASSERT``. This is an assert macro that comes with sol2 for the expression purpose of checking things; it's value is immaterial.



Expand Down
10 changes: 5 additions & 5 deletions examples/interop/LuaBridge/source/LuaBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,24 @@ void register_sol_stuff(lua_State* L) {
"luabridge-created A { "
<< from_luabridge.value() << " }"
<< std::endl;
sol_c_assert(from_luabridge.value() == 24);
SOL_ASSERT(from_luabridge.value() == 24);
},
[](A& from_luabridge, int second_arg) {
std::cout << "calling 2-argument version with "
"luabridge-created A { "
<< from_luabridge.value()
<< " } and integer argument of "
<< second_arg << std::endl;
sol_c_assert(from_luabridge.value() == 24);
sol_c_assert(second_arg == 5);
SOL_ASSERT(from_luabridge.value() == 24);
SOL_ASSERT(second_arg == 5);
});
}

void check_with_sol(lua_State* L) {
sol::state_view lua(L);
A& obj = lua["obj"];
(void)obj;
sol_c_assert(obj.value() == 24);
SOL_ASSERT(obj.value() == 24);
}

int main(int, char*[]) {
Expand Down Expand Up @@ -132,4 +132,4 @@ f(obj, 5) -- call 2 argument version
check_with_sol(L);

return 0;
}
}
10 changes: 5 additions & 5 deletions examples/interop/kaguya/source/kaguya.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,24 @@ void register_sol_stuff(lua_State* L) {
"kaguya-created ABC { "
<< from_kaguya.value() << " }"
<< std::endl;
sol_c_assert(from_kaguya.value() == 24);
SOL_ASSERT(from_kaguya.value() == 24);
},
[](ABC& from_kaguya, int second_arg) {
std::cout << "calling 2-argument version with "
"kaguya-created ABC { "
<< from_kaguya.value()
<< " } and integer argument of "
<< second_arg << std::endl;
sol_c_assert(from_kaguya.value() == 24);
sol_c_assert(second_arg == 5);
SOL_ASSERT(from_kaguya.value() == 24);
SOL_ASSERT(second_arg == 5);
});
}

void check_with_sol(lua_State* L) {
sol::state_view lua(L);
ABC& obj = lua["obj"];
(void)obj;
sol_c_assert(obj.value() == 24);
SOL_ASSERT(obj.value() == 24);
}

int main(int, char*[]) {
Expand Down Expand Up @@ -138,4 +138,4 @@ f(obj, 5) -- call 2 argument version
check_with_sol(state.state());

return 0;
}
}
10 changes: 5 additions & 5 deletions examples/interop/luwra/source/luwra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,24 @@ void register_sol_stuff(lua_State* L) {
"luwra-created ABC { "
<< from_luwra.value() << " }"
<< std::endl;
sol_c_assert(from_luwra.value() == 24);
SOL_ASSERT(from_luwra.value() == 24);
},
[](ABC& from_luwra, int second_arg) {
std::cout << "calling 2-argument version with "
"luwra-created ABC { "
<< from_luwra.value()
<< " } and integer argument of "
<< second_arg << std::endl;
sol_c_assert(from_luwra.value() == 24);
sol_c_assert(second_arg == 5);
SOL_ASSERT(from_luwra.value() == 24);
SOL_ASSERT(second_arg == 5);
});
}

void check_with_sol(lua_State* L) {
sol::state_view lua(L);
ABC& obj = lua["obj"];
(void)obj;
sol_c_assert(obj.value() == 24);
SOL_ASSERT(obj.value() == 24);
}

int main(int, char*[]) {
Expand Down Expand Up @@ -128,4 +128,4 @@ f(obj, 5) -- call 2 argument version
check_with_sol(state);

return 0;
}
}
10 changes: 5 additions & 5 deletions examples/interop/tolua/source/tolua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ void register_sol_stuff(lua_State* L) {
"tolua-created Player { health:"
<< from_tolua.getHealth() << " }"
<< std::endl;
sol_c_assert(from_tolua.getHealth() == 4);
SOL_ASSERT(from_tolua.getHealth() == 4);
},
[](Player& from_tolua, int second_arg) {
std::cout << "calling 2-argument version with "
"tolua-created Player { health: "
<< from_tolua.getHealth()
<< " } and integer argument of "
<< second_arg << std::endl;
sol_c_assert(from_tolua.getHealth() == 4);
sol_c_assert(second_arg == 5);
SOL_ASSERT(from_tolua.getHealth() == 4);
SOL_ASSERT(second_arg == 5);
});
}

void check_with_sol(lua_State* L) {
sol::state_view lua(L);
Player& obj = lua["obj"];
(void)obj;
sol_c_assert(obj.getHealth() == 4);
SOL_ASSERT(obj.getHealth() == 4);
}

int main(int, char*[]) {
Expand Down Expand Up @@ -110,4 +110,4 @@ f(obj, 5) -- call 2 argument version
check_with_sol(L);

return 0;
}
}
6 changes: 3 additions & 3 deletions examples/require_dll_example/source/require_from_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ print(obj.value))";
std::cout << "Something bad happened: " << err.what()
<< std::endl;
}
sol_c_assert(script_result.valid());
SOL_ASSERT(script_result.valid());
my_object::test& obj = lua["obj"];
sol_c_assert(obj.value == 24);
SOL_ASSERT(obj.value == 24);

return 0;
}
}
8 changes: 4 additions & 4 deletions examples/source/any_return.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ int main() {

int result = lua["f"](1, 2);
// result == 3
sol_c_assert(result == 3);
SOL_ASSERT(result == 3);
double result2 = lua["f"](false, 2.5);
// result2 == 2.5
sol_c_assert(result2 == 2.5);
SOL_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
sol_c_assert(result3 == 16.5);
SOL_ASSERT(result3 == 16.5);

std::cout << "=== any_return ===" << std::endl;
std::cout << "result : " << result << std::endl;
Expand All @@ -50,4 +50,4 @@ int main() {
std::cout << std::endl;

return 0;
}
}
6 changes: 3 additions & 3 deletions examples/source/as_returns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ int main() {
std::string v2 = lua["v2"];
std::string v3 = lua["v3"];

sol_c_assert(v1 == "arf");
sol_c_assert(v2 == "bark");
sol_c_assert(v3 == "woof");
SOL_ASSERT(v1 == "arf");
SOL_ASSERT(v2 == "bark");
SOL_ASSERT(v3 == "woof");

return 0;
}
4 changes: 2 additions & 2 deletions examples/source/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main() {
"appear above this one!"
<< std::endl;
int value = result;
sol_c_assert(value == 24);
SOL_ASSERT(value == 24);
}
else {
std::cout << "the third script failed, check the "
Expand All @@ -63,7 +63,7 @@ int main() {
"wasn't supposed to! Panic!"
<< std::endl;
int value = result;
sol_c_assert(value == 24);
SOL_ASSERT(value == 24);
}
else {
sol::error err = result;
Expand Down
10 changes: 5 additions & 5 deletions examples/source/c_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ int main() {
)");

something& s = lua["s"];
sol_c_assert(s.arr[0] == 5);
sol_c_assert(s.arr[1] == 6);
sol_c_assert(s.arr[2] == 40);
sol_c_assert(s.arr[3] == 8);
SOL_ASSERT(s.arr[0] == 5);
SOL_ASSERT(s.arr[1] == 6);
SOL_ASSERT(s.arr[2] == 40);
SOL_ASSERT(s.arr[3] == 8);

std::string string_array[] = {
"first string",
Expand All @@ -49,7 +49,7 @@ int main() {
print(str_arr[3])
)");

sol_c_assert(string_array[2] == "third string: modified");
SOL_ASSERT(string_array[2] == "third string: modified");

return 0;
}
Loading

0 comments on commit 3592851

Please sign in to comment.