diff --git a/.gitignore b/.gitignore index 69d77b94..7d7e7db8 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,4 @@ desktop.ini # Miscellaneous external/ +scratch/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 41ee4905..e87f7592 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,10 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # # # sol2 +# # # Required minimum version statement cmake_minimum_required(VERSION 3.5.0) + +# # # project declaration project(sol2 VERSION 2.19.0 LANGUAGES CXX C) # # # General Project Requirements @@ -63,8 +66,6 @@ else() list(APPEND CMAKE_C_FLAGS "-m32") list(APPEND CMAKE_CXX_FLAGS "-m32") list(APPEND CMAKE_EXE_LINKER_FLAGS "-m32") - list(APPEND CMAKE_MODULE_LINKER_FLAGS "-m32") - list(APPEND CMAKE_STATIC_LINKER_FLAGS "-m32") list(APPEND CMAKE_SHARED_LINKER_FLAGS "-m32") endif() add_compile_options(-Wno-unknown-warning -Wno-unknown-warning-option -Wall -Wextra -Wpedantic -pedantic -pedantic-errors) @@ -105,7 +106,6 @@ include(CMakePackageConfigHelpers) # # Cached defines, strings, paths and options set(LUA_VERSION "5.3.4" CACHE STRING "The version of Lua needed. Can be 5.1, 5.2, 5.3, LuaJIT, or a more specific 3-part version number for a specifc Lua (e.g., 5.3.4 or luajit-2.0.5)") set(BUILD_LUA TRUE CACHE BOOL "Always build Lua, do not search for it in the system") -set(BUILD_LUAJIT FALSE CACHE BOOL "Always build LuaJIT, do not search for it in the system") set(PLATFORM "x64" CACHE STRING "Target platform to compile for when building binaries (x86, x64)") option(CI "Enable build of tests" OFF) option(TESTS "Enable build of tests" OFF) @@ -213,10 +213,10 @@ if (TESTS OR TESTS_SINGLE OR TESTS_EXAMPLES OR EXAMPLES OR EXAMPLES_SINGLE) endif() find_package(Threads) # Find way to get Lua: build if requested, or attempt to build if no matching version is found - if (BUILD_LUA OR BUILD_LUAJIT) - include(LuaBuild) + if (BUILD_LUA) + find_package(LuaBuild ${LUA_VERSION} REQUIRED) elseif (NOT LUA_VERSION) - # can't do anything + find_package(LuaBuild REQUIRED) else() string(TOLOWER ${LUA_VERSION} NORMALIZED_LUA_VERSION) if (NORMALIZED_LUA_VERSION MATCHES "5.1") @@ -228,11 +228,11 @@ if (TESTS OR TESTS_SINGLE OR TESTS_EXAMPLES OR EXAMPLES OR EXAMPLES_SINGLE) elseif(NORMALIZED_LUA_VERSION MATCHES "luajit") find_package(LuaJIT REQUIRED) else() - include(LuaBuild) + find_package(LuaBuild ${LUA_VERSION} REQUIRED) endif() endif() - if (NOT LUA_FOUND) + if (NOT LUA_FOUND AND NOT LUABUILD_FOUND) message(FATAL_ERROR "sol2 Lua \"${LUA_VERSION}\" not found and could not be targeted for building.") endif() diff --git a/cmake/Modules/FindLuaBuild.cmake b/cmake/Modules/FindLuaBuild.cmake new file mode 100644 index 00000000..7f10c3e5 --- /dev/null +++ b/cmake/Modules/FindLuaBuild.cmake @@ -0,0 +1,112 @@ +# # # # sol2 +# The MIT License (MIT) +# +# Copyright (c) 2013-2017 Rapptz, ThePhD, and contributors +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# 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. + +# # Standard CMake Libraries +include(FindPackageHandleStandardArgs) + +# Contain literally everything inside of this function to prevent spillage +function(find_lua_build LUA_VERSION) + # # # Variables + # # Core Paths + string(TOLOWER ${LUA_VERSION} LUA_BUILD_NORMALIZED_LUA_VERSION) + if (LUA_BUILD_NORMALIZED_LUA_VERSION MATCHES "luajit") + set(LUA_BUILD_LIBNAME ${LUA_VERSION}) + elseif (BUILD_LUAJIT) + set(LUA_BUILD_LIBNAME luajit-${LUA_VERSION}) + elseif (LUA_BUILD_NORMALIZED_LUA_VERSION MATCHES "lua") + set(LUA_BUILD_LIBNAME ${LUA_VERSION}) + elseif (BUILD_LUA) + set(LUA_BUILD_LIBNAME lua-${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_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") + + # Object file suffixes + if (MSVC) + set(LUA_BUILD_BUILD_DLL_DEFAULT ON) + set(LUA_BUILD_OBJECT_FILE_SUFFIX .obj) + else() + set(LUA_BUILD_BUILD_DLL_DEFAULT OFF) + set(LUA_BUILD_OBJECT_FILE_SUFFIX .o) + endif() + + + # # # Options + option(BUILD_LUA_AS_DLL ${LUA_BUILD_BUILD_DLL_DEFAULT} "Build Lua or LuaJIT as a Shared/Dynamic Link Library") + + STRING(TOLOWER ${LUA_BUILD_LIBNAME} LUA_BUILD_NORMALIZED_LIBNAME) + if (NOT LUA_LIBRARY_NAME) + if (LUA_BUILD_NORMALIZED_LIBNAME MATCHES "luajit") + set(LUA_LIBRARY luajit) + else() + set(LUA_LIBRARY ${LUA_BUILD_LIBNAME}) + endif() + else() + set(LUA_LIBRARY_NAME ${LUA_LIBRARY_NAME} + CACHE STRING + ${LUA_BUILD_LIBRARY_DESCRIPTION}) + endif() + # # Dependent Variables + # If we're building a DLL, then set the library type to SHARED + if (BUILD_LUA_AS_DLL) + set(LUA_BUILD_LIBRARY_TYPE SHARED) + else() + set(LUA_BUILD_LIBRARY_TYPE STATIC) + endif() + + + # # # Build Lua + # # Select either LuaJIT or Vanilla Lua here, based on what we discover + if (BUILD_LUAJIT OR LUA_BUILD_NORMALIZED_LUA_VERSION MATCHES "luajit") + include(${CMAKE_CURRENT_LIST_DIR}/FindLuaBuild/LuaJIT.cmake) + set(LUA_VERSION_STRING ${LUA_JIT_VERSION}) + else() + include(${CMAKE_CURRENT_LIST_DIR}/FindLuaBuild/LuaVanilla.cmake) + set(LUA_VERSION_STRING ${LUA_VANILLA_VERSION}) + endif() + + # # Export variables to the parent scope + set(LUA_LIBRARIES ${LUA_LIBRARIES} PARENT_SCOPE) + set(LUA_INTERPRETER ${LUA_INTERPRETER} PARENT_SCOPE) + set(LUA_VERSION_STRING ${LUA_VERSION_STRING} PARENT_SCOPE) + set(LUABUILD_FOUND TRUE PARENT_SCOPE) +endfunction(find_lua_build) + +# Call and then immediately undefine to avoid polluting the global scope +if (FIND_PACKAGE_VERSION) + set(LUA_VERSION ${PACKAGE_FIND_VERSION}) +else() + set(LUA_VERSION 5.3.4) +endif() +find_lua_build(${LUA_VERSION}) +unset(find_lua_build) + +# handle the QUIETLY and REQUIRED arguments and set LUABUILD_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaBuild + FOUND_VAR LUABUILD_FOUND + REQUIRED_VARS LUA_LIBRARIES LUA_INTERPRETER + VERSION_VAR LUA_VERSION_STRING) diff --git a/cmake/Modules/LuaJITBuild.cmake b/cmake/Modules/FindLuaBuild/LuaJIT.cmake similarity index 93% rename from cmake/Modules/LuaJITBuild.cmake rename to cmake/Modules/FindLuaBuild/LuaJIT.cmake index 2f4b20b1..041f1b75 100644 --- a/cmake/Modules/LuaJITBuild.cmake +++ b/cmake/Modules/FindLuaBuild/LuaJIT.cmake @@ -20,15 +20,15 @@ # 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. -# import necessary standard modules -include(ExternalProject) - # protect from multiple inclusion if(lua_jit_build_included) - return() + return() endif(lua_jit_build_included) set(lua_jit_build_included true) +# import necessary standard modules +include(ExternalProject) + # Latest iterations for specific sub-versions of LuaJIT set(LUA_JIT_2.0_LATEST_VERSION 2.0.5) set(LUA_JIT_${LUA_JIT_2.0_LATEST_VERSION}_COMMIT c88602f080dcafea6ba222a2f7cc1ea0e41ef3cc) @@ -117,7 +117,9 @@ else() MESSAGE(FATAL "Cannot deduce LuaJIT version from ${LUA_VERSION}") endif() -MESSAGE(STATUS "Selecting LuaJIT ${LUA_JIT_VERSION} from '${LUA_VERSION}' and building a ${LUA_BUILD_LIBRARY_TYPE} library...") +FIND_PACKAGE_MESSAGE(LUABUILD + "Selecting LuaJIT ${LUA_JIT_VERSION} from '${LUA_VERSION}' and building a ${LUA_BUILD_LIBRARY_TYPE} library..." + "[${LUA_JIT_VERSION}][${LUA_VERSION}][${LUA_BUILD_LIBRARY_TYPE}]") # Get hashes for the build # LuaJIT unfortunately does not give us SHA1 hashes as well @@ -156,6 +158,7 @@ set(LUA_JIT_LIB_FILE "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${LUA_JIT_LIB_FILENAME}" set(LUA_JIT_IMP_LIB_FILE "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${LUA_JIT_IMP_LIB_FILENAME}") set(LUA_JIT_LIB_EXP_FILE "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${LUA_JIT_LIB_EXP_FILENAME}") set(LUA_JIT_DLL_FILE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${LUA_JIT_DLL_FILENAME}") +set(LUA_JIT_EXE_FILE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${LUA_JIT_EXE_FILENAME}") # # # Do the build if (MSVC) @@ -205,6 +208,7 @@ else () endif() set(lualib luajitlib_${LUA_JIT_VERSION}) +set(luainterpreter luajit_${LUA_JIT_VERSION}) file(TO_NATIVE_PATH "${LUA_JIT_SOURCE_DIR}/${LUA_JIT_PREBUILT_LIB}" LUA_JIT_SOURCE_LUA_LIB) file(TO_NATIVE_PATH "${LUA_JIT_LIB_FILE}" LUA_JIT_DESTINATION_LUA_LIB) @@ -214,6 +218,8 @@ file(TO_NATIVE_PATH "${LUA_JIT_SOURCE_DIR}/${LUA_JIT_PREBUILT_DLL}" LUA_JIT_SOUR file(TO_NATIVE_PATH "${LUA_JIT_DLL_FILE}" LUA_JIT_DESTINATION_LUA_DLL) file(TO_NATIVE_PATH "${LUA_JIT_SOURCE_DIR}/${LUA_JIT_PREBUILT_EXP}" LUA_JIT_SOURCE_LUA_LIB_EXP) file(TO_NATIVE_PATH "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${LUA_JIT_LIB_EXP_FILENAME}" LUA_JIT_DESTINATION_LUA_LIB_EXP) +file(TO_NATIVE_PATH "${LUA_JIT_SOURCE_DIR}/luajit${CMAKE_EXECUTABLE_SUFFIX}" LUA_JIT_SOURCE_LUA_INTERPRETER) +file(TO_NATIVE_PATH "${LUA_JIT_EXE_FILE}" LUA_JIT_DESTINATION_LUA_INTERPRETER) if (WIN32 AND NOT MSVC) string(COMPARE EQUAL ${LUA_JIT_VERSION} ${LUA_JIT_2.0_LATEST_VERSION} lua_jit_same_version_20) @@ -311,10 +317,16 @@ else() COMMENT "Library - Moving \"${LUA_JIT_SOURCE_LUA_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_LIB}\"..." COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_LIB}" "${LUA_JIT_DESTINATION_LUA_LIB}" && echo Successfully moved!) endif() -# # TODO: +ExternalProject_Add_Step(LUA_JIT + postbuild.exe + DEPENDEES build + COMMENT "Library - Moving \"${LUA_JIT_SOURCE_LUA_INTERPRETER}\" to \"${LUA_JIT_DESTINATION_LUA_INTERPRETER}\"..." + COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_JIT_SOURCE_LUA_INTERPRETER}" "${LUA_JIT_DESTINATION_LUA_INTERPRETER}" && echo Successfully moved!) +# # TODO: # Add additional post-build step to move all necessary headers/lua files # for now, we just point directly to the `src` directory... +# # Lua Library add_library(${lualib} ${LUA_BUILD_LIBRARY_TYPE} IMPORTED) # make sure the library we export really does depend on Lua JIT's external project add_dependencies(${lualib} LUA_JIT) @@ -344,7 +356,13 @@ if (XCODE) PUBLIC -pagezero_size 10000 -image_base 100000000) endif () +# # Lua Executable +add_executable(${luainterpreter} IMPORTED) +# Point EXE to fiel +set_target_properties(${luainterpreter} + PROPERTIES + IMPORTED_LOCATION "${LUA_JIT_EXE_FILE}") + # set externally-visible target indicator set(LUA_LIBRARIES ${lualib}) -set(LUAJIT_FOUND TRUE) -set(LUA_FOUND TRUE) +set(LUA_INTERPRETER ${luainterpreter}) diff --git a/cmake/Modules/LuaVanillaBuild.cmake b/cmake/Modules/FindLuaBuild/LuaVanilla.cmake similarity index 97% rename from cmake/Modules/LuaVanillaBuild.cmake rename to cmake/Modules/FindLuaBuild/LuaVanilla.cmake index 03961578..5ccef363 100644 --- a/cmake/Modules/LuaVanillaBuild.cmake +++ b/cmake/Modules/FindLuaBuild/LuaVanilla.cmake @@ -20,16 +20,15 @@ # 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. +# Include guard +if(_lua_vanilla_build_included) + return() +endif(_lua_vanilla_build_included) +set(_lua_vanilla_build_included true) + # import necessary standard modules include(ExternalProject) -if(lua_build_included) - return() -endif(lua_build_included) -set(lua_build_included true) - - - # Latest versions for specific sub-versions of Lua set(LUA_VANILLA_5.1_LATEST_VERSION 5.1.5) set(LUA_VANILLA_5.2_LATEST_VERSION 5.2.4) @@ -141,7 +140,9 @@ else() message(FATAL_ERROR "Cannot deduce the proper Lua version from ${LUA_VERSION}") endif() -message(STATUS "Selecting PUC-RIO Lua ${LUA_VANILLA_VERSION} from '${LUA_VERSION}' and building a ${LUA_BUILD_LIBRARY_TYPE} library...") +FIND_PACKAGE_MESSAGE(LUABUILD + "Selecting PUC-RIO Lua ${LUA_VANILLA_VERSION} from '${LUA_VERSION}' and building a ${LUA_BUILD_LIBRARY_TYPE} library..." + "[${LUA_VANILLA_VERSION}][${LUA_VERSION}][${LUA_BUILD_LIBRARY_TYPE}]") # Get Hashes to use for download set(LUA_VANILLA_SHA1 ${LUA_VANILLA_SHA1_${LUA_VANILLA_VERSION}}) @@ -238,7 +239,6 @@ ExternalProject_Add(LUA_VANILLA # make a quick lua.hpp for 5.1 targets that don't have it if (LUA_VANILLA_GENERATE_LUA_HPP) - message(STATUS "Will generate lua.hpp for this version of Lua...") set(LUA_VANILLA_LUA_HPP_CONTENT "// lua.hpp // Lua header files for C++ // <> not supplied automatically because Lua also compiles as C++ @@ -399,4 +399,5 @@ endif() # set externally-visible target indicator set(LUA_LIBRARIES ${liblua}) -set(LUA_FOUND TRUE) +set(LUA_INTERPRETER ${luainterpreter}) +set(LUA_COMPILER ${luacompiler}) diff --git a/cmake/Modules/LuaBuild.cmake b/cmake/Modules/LuaBuild.cmake deleted file mode 100644 index 06903701..00000000 --- a/cmake/Modules/LuaBuild.cmake +++ /dev/null @@ -1,91 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2017 Rapptz, ThePhD, and contributors -# -# Permission is hereby granted, free of charge, to any person obtaining a copy of -# this software and associated documentation files (the "Software"), to deal in -# the Software without restriction, including without limitation the rights to -# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -# the Software, and to permit persons to whom the Software is furnished to do so, -# subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -# 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. - -# # # Variables -# # Core Paths -string(TOLOWER ${LUA_VERSION} LUA_BUILD_NORMALIZED_LUA_VERSION) -if (LUA_BUILD_NORMALIZED_LUA_VERSION MATCHES "luajit") - set(LUA_BUILD_LIBNAME ${LUA_VERSION}) -elseif (BUILD_LUAJIT) - set(LUA_BUILD_LIBNAME luajit-${LUA_VERSION}) -elseif (LUA_BUILD_NORMALIZED_LUA_VERSION MATCHES "lua") - set(LUA_BUILD_LIBNAME ${LUA_VERSION}) -elseif (BUILD_LUA) - set(LUA_BUILD_LIBNAME lua-${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_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") - -# Object file suffixes -if (MSVC) - set(LUA_BUILD_BUILD_DLL_DEFAULT ON) - set(LUA_BUILD_OBJECT_FILE_SUFFIX .obj) -else() - set(LUA_BUILD_BUILD_DLL_DEFAULT OFF) - set(LUA_BUILD_OBJECT_FILE_SUFFIX .o) -endif() - - -# # # Options -option(BUILD_LUA_AS_DLL ${LUA_BUILD_BUILD_DLL_DEFAULT} "Build Lua or LuaJIT as a Shared/Dynamic Link Library") - -STRING(TOLOWER ${LUA_BUILD_LIBNAME} LUA_BUILD_NORMALIZED_LIBNAME) -if (NOT LUA_LIBRARY_NAME) - if (LUA_BUILD_NORMALIZED_LIBNAME MATCHES "luajit") - set(LUA_LIBRARY luajit) - else() - set(LUA_LIBRARY ${LUA_BUILD_LIBNAME}) - endif() -else() - set(LUA_LIBRARY_NAME ${LUA_LIBRARY_NAME} - CACHE STRING - ${LUA_BUILD_LIBRARY_DESCRIPTION}) -endif() -# # Dependent Variables -# If we're building a DLL, then set the library type to SHARED -if (BUILD_LUA_AS_DLL) - set(LUA_BUILD_LIBRARY_TYPE SHARED) -else() - set(LUA_BUILD_LIBRARY_TYPE STATIC) -endif() - - -# # # Build Lua -# # Select either LuaJIT or Vanilla Lua here, based on what we discover -if (BUILD_LUAJIT OR LUA_BUILD_NORMALIZED_LUA_VERSION MATCHES "luajit") - include(LuaJITBuild) -else() - include(LuaVanillaBuild) -endif() - -# # # Variable cleanup -unset(LUA_BUILD_LIBNAME) -unset(LUA_BUILD_NORMALIZED_LUA_VERSION) -unset(LUA_BUILD_LIBRARY_DESCRIPTION) -unset(LUA_BUILD_DYNAMIC_LIBRARY_DESCRIPTION) -unset(LUA_BUILD_BUILD_DLL_DEFAULT) -unset(LUA_BUILD_OBJECT_FILE_SUFFIX) -unset(LUA_BUILD_LIBRARY_TYPE) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index bf28d4af..1e845232 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 2018-01-20 19:31:24.245892 UTC -// This header was generated with sol v2.19.0 (revision cbd7923) +// Generated 2018-01-23 16:58:47.295340 UTC +// This header was generated with sol v2.19.0 (revision 6ae78d9) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -8626,7 +8626,7 @@ namespace stack { thread_local std::wstring_convert> convert; std::wstring r = convert.from_bytes(str, str + len); #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 7 - // Fuck you, MinGW, and fuck you libstdc++ for introducing this absolutely asinine bug + // Thanks, MinGW and libstdc++, for introducing this absolutely asinine bug // https://sourceforge.net/p/mingw-w64/bugs/538/ // http://chat.stackoverflow.com/transcript/message/32271369#32271369 for (auto& c : r) { @@ -16652,6 +16652,7 @@ namespace sol { // end of sol/usertype_core.hpp #include +#include namespace sol { namespace usertype_detail { @@ -17011,7 +17012,7 @@ namespace sol { void* baseclasscheck; void* baseclasscast; bool secondarymeta; - std::array properties; + std::bitset<32> properties; template >> = meta::enabler> lua_CFunction make_func() const { @@ -17076,12 +17077,11 @@ namespace sol { luaL_Reg reg = usertype_detail::make_reg(std::forward(n), make_func()); for (std::size_t i = 0; i < properties.size(); ++i) { meta_function mf = static_cast(i); - bool& prop = properties[i]; const std::string& mfname = to_string(mf); if (mfname == reg.name) { switch (mf) { case meta_function::construct: - if (prop) { + if (properties[i]) { #ifndef SOL_NO_EXCEPTIONS throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems"); #else @@ -17102,17 +17102,17 @@ namespace sol { case meta_function::index: indexfunc = reg.func; mustindex = true; - prop = true; + properties.set(i); return; case meta_function::new_index: newindexfunc = reg.func; mustindex = true; - prop = true; + properties.set(i); return; default: break; } - prop = true; + properties.set(i); break; } } @@ -17123,7 +17123,7 @@ namespace sol { template > usertype_metatable(Args&&... args) : usertype_metatable_core(&usertype_detail::indexing_fail, &usertype_detail::metatable_newindex), usertype_detail::registrar(), functions(std::forward(args)...), destructfunc(nullptr), callconstructfunc(nullptr), indexbase(&core_indexing_call), newindexbase(&core_indexing_call), indexbaseclasspropogation(usertype_detail::walk_all_bases), newindexbaseclasspropogation(usertype_detail::walk_all_bases), baseclasscheck(nullptr), baseclasscast(nullptr), secondarymeta(contains_variable()), properties() { - properties.fill(false); + properties.reset(); std::initializer_list ilist{{std::pair(usertype_detail::make_string(std::get(functions)), usertype_detail::call_information(&usertype_metatable::real_find_call, &usertype_metatable::real_find_call))}...}; diff --git a/single/sol/sol_forward.hpp b/single/sol/sol_forward.hpp index 92f1971c..e4a05064 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 2018-01-20 19:31:24.431906 UTC -// This header was generated with sol v2.19.0 (revision cbd7923) +// Generated 2018-01-23 16:58:47.490358 UTC +// This header was generated with sol v2.19.0 (revision 6ae78d9) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP diff --git a/sol/inheritance.hpp b/sol/inheritance.hpp index 41c16a4d..b6d4e702 100644 --- a/sol/inheritance.hpp +++ b/sol/inheritance.hpp @@ -25,7 +25,6 @@ #define SOL_INHERITANCE_HPP #include "types.hpp" -#include namespace sol { template @@ -46,19 +45,6 @@ namespace sol { template bool has_derived::value = false; - inline std::size_t unique_id() { - static std::atomic x(0); - return ++x; - } - - template - struct id_for { - static const std::size_t value; - }; - - template - const std::size_t id_for::value = unique_id(); - inline decltype(auto) base_class_check_key() { static const auto& key = "class_check"; return key; @@ -81,32 +67,32 @@ namespace sol { template struct inheritance { - static bool type_check_bases(types<>, std::size_t) { + static bool type_check_bases(types<>, const std::string& ti) { return false; } template - static bool type_check_bases(types, std::size_t ti) { - return ti == id_for::value || type_check_bases(types(), ti); + static bool type_check_bases(types, const std::string& ti) { + return ti == usertype_traits::qualified_name() || type_check_bases(types(), ti); } - static bool type_check(std::size_t ti) { - return ti == id_for::value || type_check_bases(types(), ti); + static bool type_check(const std::string& ti) { + return ti == usertype_traits::qualified_name() || type_check_bases(types(), ti); } - static void* type_cast_bases(types<>, T*, std::size_t) { + static void* type_cast_bases(types<>, T*, const std::string&) { return nullptr; } template - static void* type_cast_bases(types, T* data, std::size_t ti) { + static void* type_cast_bases(types, T* data, const std::string& ti) { // Make sure to convert to T first, and then dynamic cast to the proper type - return ti != id_for::value ? type_cast_bases(types(), data, ti) : static_cast(static_cast(data)); + return ti != usertype_traits::qualified_name() ? type_cast_bases(types(), data, ti) : static_cast(static_cast(data)); } - static void* type_cast(void* voiddata, std::size_t ti) { + static void* type_cast(void* voiddata, const std::string& ti) { T* data = static_cast(voiddata); - return static_cast(ti != id_for::value ? type_cast_bases(types(), data, ti) : data); + return static_cast(ti != usertype_traits::qualified_name() ? type_cast_bases(types(), data, ti) : data); } }; diff --git a/sol/stack_check.hpp b/sol/stack_check.hpp index deed4ba8..f3165d32 100644 --- a/sol/stack_check.hpp +++ b/sol/stack_check.hpp @@ -456,7 +456,7 @@ namespace stack { if (type_of(L, -1) != type::lua_nil) { void* basecastdata = lua_touserdata(L, -1); detail::inheritance_check_function ic = reinterpret_cast(basecastdata); - success = ic(detail::id_for::value); + success = ic(usertype_traits::qualified_name()); } } if (!success) { diff --git a/sol/stack_get.hpp b/sol/stack_get.hpp index 79fb988d..7e267bf0 100644 --- a/sol/stack_get.hpp +++ b/sol/stack_get.hpp @@ -467,7 +467,7 @@ namespace stack { thread_local std::wstring_convert> convert; std::wstring r = convert.from_bytes(str, str + len); #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 7 - // Fuck you, MinGW, and fuck you libstdc++ for introducing this absolutely asinine bug + // Thanks, MinGW and libstdc++, for introducing this absolutely asinine bug // https://sourceforge.net/p/mingw-w64/bugs/538/ // http://chat.stackoverflow.com/transcript/message/32271369#32271369 for (auto& c : r) { @@ -664,7 +664,7 @@ namespace stack { void* basecastdata = lua_touserdata(L, -1); detail::inheritance_cast_function ic = reinterpret_cast(basecastdata); // use the casting function to properly adjust the pointer for the desired T - udata = ic(udata, detail::id_for::value); + udata = ic(udata, usertype_traits::qualified_name()); lua_pop(L, 1); } T* obj = static_cast(udata); diff --git a/tests/test_state.cpp b/tests/test_state.cpp index 3b1c8c2b..c2677bbb 100644 --- a/tests/test_state.cpp +++ b/tests/test_state.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "test_stack_guard.hpp"