diff --git a/third/sol2/.clang-format b/third/sol2/.clang-format deleted file mode 100644 index f75a5542..00000000 --- a/third/sol2/.clang-format +++ /dev/null @@ -1,110 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - ---- -BasedOnStyle: WebKit -IndentWidth: 5 -TabWidth: 5 -ContinuationIndentWidth: 5 -UseTab: ForIndentation - -# Namespaces -NamespaceIndentation: All -CompactNamespaces: true -FixNamespaceComments: true - -# Overall Alignment -ColumnLimit: 160 -AlignAfterOpenBracket: DontAlign # uses ContinuationIndentWidth for this instead -AccessModifierOffset: -5 # do not push public: or private: around -#AlignConsecutiveAssignments: true # affects more than what's expected: do not use -#AlignConsecutiveDeclarations: true # affects more than what's expected: do not use - -# Type Alignment -DerivePointerAlignment: false -PointerAlignment: Left -AlwaysBreakTemplateDeclarations: true -AlwaysBreakBeforeMultilineStrings: true - -# Comments -AlignTrailingComments: true -ReflowComments: true - -# Macros -AlignEscapedNewlines: Left -#IndentPPDirectives: None - -# Functions -AllowShortFunctionsOnASingleLine: None -AlwaysBreakAfterReturnType: None -BreakConstructorInitializers: BeforeComma -ConstructorInitializerIndentWidth: 0 -ConstructorInitializerAllOnOneLineOrOnePerLine: true -BinPackArguments: false -BinPackParameters: true - -# Classes -BreakBeforeInheritanceComma: false - -# Braces -Cpp11BracedListStyle: false -BreakBeforeBraces: Custom -BraceWrapping: - AfterEnum: false - AfterStruct: false - AfterControlStatement: false - AfterClass: false - AfterNamespace: false - AfterStruct: false - AfterUnion: false - BeforeElse: true - BeforeCatch: true - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyRecord: false - SplitEmptyNamespace: true - -# Control Statements -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -IndentCaseLabels: false - -# Spaces -SpaceAfterCStyleCast: false -SpacesInCStyleCastParentheses: false -SpaceAfterTemplateKeyword: true -SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesInAngles: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -MaxEmptyLinesToKeep: 3 - -# OCD -SortUsingDeclarations: true -SortIncludes: false - ---- -Language: Cpp -Standard: Cpp11 diff --git a/third/sol2/.dockerignore b/third/sol2/.dockerignore deleted file mode 100644 index 129e1179..00000000 --- a/third/sol2/.dockerignore +++ /dev/null @@ -1,27 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# Ignore literally everything -** - -# Except the script directory -!scripts/preparation* diff --git a/third/sol2/.github/ISSUE_TEMPLATE.md b/third/sol2/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index dae6f601..00000000 --- a/third/sol2/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,16 +0,0 @@ -Read these guidelines. They are relatively simple and will allow me to help you better! - -For Error Reports: - -1. Produce a simple, short, compilable test case that reproduces your problem. -2. Make a descriptive title that summarises the bug as a whole. -3. Explain the bug in as much detail as you can in the body of the issue. -4. Include Compiler/IDE (Visual Studio, XCode...), Build and Deployment System, Language (C++, Objective-C++), and any special defines you have set. - -If you want to request a feature: - -1. Produce any relevant imaginary code that illustrates what you would like or desired behavior. -2. Include a description and title of what you would like. -3. Annotate and describe the behavior through comments, asserts or just a small write up. - -Thanks for helping sol2 grow! diff --git a/third/sol2/.github/workflows/macos.yml b/third/sol2/.github/workflows/macos.yml deleted file mode 100644 index e0d35bb1..00000000 --- a/third/sol2/.github/workflows/macos.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Mac OS - -on: [push] - -env: - CTEST_OUTPUT_ON_FAILURE: 1 - -jobs: - build: - - runs-on: macos-latest - - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - - - name: configure - run: | - cmake -B build/debug -D CMAKE_BUILD_TYPE:STRING=Debug "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=OFF -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON - cmake -B build/release -D CMAKE_BUILD_TYPE:STRING=Release "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=OFF -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON - - name: build - run: | - cmake --build build/debug --config Debug - cmake --build build/release --config Release - - name: test - run: | - cd build/debug - ctest --build-config Debug - cd ../.. - cd build/release - ctest --build-config Release - cd ../.. diff --git a/third/sol2/.github/workflows/ubuntu.yml b/third/sol2/.github/workflows/ubuntu.yml deleted file mode 100644 index 0bc8c013..00000000 --- a/third/sol2/.github/workflows/ubuntu.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Ubuntu - -on: [push] - -env: - CTEST_OUTPUT_ON_FAILURE: 1 - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - - - name: configure - run: | - cmake -B build/debug -D CMAKE_BUILD_TYPE:STRING=Debug "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=OFF -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON - cmake -B build/release -D CMAKE_BUILD_TYPE:STRING=Release "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=OFF -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON - - name: build - run: | - cmake --build build/debug --config Debug - cmake --build build/release --config Release - - name: test - run: | - cd build/debug - ctest --build-config Debug - cd ../.. - cd build/release - ctest --build-config Release - cd ../.. diff --git a/third/sol2/.github/workflows/windows.yml b/third/sol2/.github/workflows/windows.yml deleted file mode 100644 index 1d2fa6bb..00000000 --- a/third/sol2/.github/workflows/windows.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Windows - -on: [push] - -env: - CTEST_OUTPUT_ON_FAILURE: true - UseMultiToolTask: true - EnforceProcessCountAcrossBuilds: true - - -jobs: - build: - - runs-on: windows-latest - - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - - - name: configure - run: | - $env:MultiProcMaxCount = ((Get-CimInstance -ClassName Win32_Processor | Measure-Object -Property NumberOfLogicalProcessors -Sum).Sum + 1) - cmake -B build/debug -D CMAKE_BUILD_TYPE:STRING=Debug "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=ON -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON - cmake -B build/release -D CMAKE_BUILD_TYPE:STRING=Release "-DSOL2_LUA_VERSION:STRING=5.4" -DSOL2_PLATFORM:STRING=x64 -DSOL2_CI=ON -DSOL2_BUILD_LUA:BOOL=ON -DBUILD_LUA_AS_DLL:BOOL=ON -DSOL2_TESTS:BOOL=ON -DSOL2_EXAMPLES:BOOL=ON -DSOL2_TESTS_EXAMPLES:BOOL=ON - - name: build - run: | - $env:MultiProcMaxCount = ((Get-CimInstance -ClassName Win32_Processor | Measure-Object -Property NumberOfLogicalProcessors -Sum).Sum + 1) - cmake --build build/debug --config Debug - cmake --build build/release --config Release - - name: test - run: | - cd build/debug - ctest --build-config Debug - cd ../.. - cd build/release - ctest --build-config Release - cd ../.. diff --git a/third/sol2/.gitignore b/third/sol2/.gitignore deleted file mode 100644 index 3efa816d..00000000 --- a/third/sol2/.gitignore +++ /dev/null @@ -1,131 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# Python (Bytecode) -*.pyc - -# ninja files -*.ninja - -# Visual Studio -*.props -*.user -.vs/ -Debug/ -Release/ -x64/ -x86/ -*.pyproj -*.vcxproj -*.vcxproj.filters -*.tlog -*.lastbuildstate -*.idb -*.sln -*.gitattributes - -# VSCode -.vscode/ - -# scratch space -/main.cpp -scratch/ - -# CMake -build/ -build-sol2/ -CMakeCache.txt -CMakeFiles/ - -# Compiler outputs -obj/* -bin/* -main.exe -main.o -lua53.dll -lua-5.3.4.dll -main.ilk -main.pdb - -# Dropbox interference -.dropbox* - -# QtCreator -*.creator.user.* -*.config -*.creator -*.files -*.includes - -# Local Lua Testbeds -lua-5.4.0-cxx/ -lua-5.4.0/ -lua-5.4.0-work1-cxx/ -lua-5.4.0-work1/ -lua-5.3.4-cxx/ -lua-5.3.4/ -lua-5.3.2/ -lua-5.3.1/ -lua-5.3.0/ -lua-5.2.4/ -lua-5.2.2/ -lua-5.2.3/ -lua-5.1.5/ -LuaJIT-2.1.0/ -luajit-2.0.5/ -luajit-2.0.3/ -liblua.a -lib/liblua5.2.a - -# Docs Artefacts -docs/build/ - -# Sublime Text -*.sublime-workspace -*.sublime-project - - -# MacOS Garbage -.DS_Store - -# Windows Crap -desktop.ini -*.db - -# Miscellaneous -external/ -vendor/ -.idea/ -cmake-build-debug/ -cmake-build-relwithdebinfo/ -cmake-build-release/ -/subprojects/* -!/subprojects/*.wrap -lua-5.3/ -lua-5.3-cxx/ -lua-5.4/ -LuaJIT-2.0/ -LuaJIT-2.1/ -lua-5.1/ -lua-5.2/ -~syncthing* -.tmp diff --git a/third/sol2/.style.yapf b/third/sol2/.style.yapf deleted file mode 100644 index d710c371..00000000 --- a/third/sol2/.style.yapf +++ /dev/null @@ -1,15 +0,0 @@ -[style] -based_on_style = pep8 -use_tabs = true -indent_width = 5 - -spaces_before_comment = 1 -spaces_around_power_operator = true -space_between_ending_comma_and_closing_bracket = true - -continuation_align_style = SPACE -split_before_first_argument = false -split_complex_comprehension = true -dedent_closing_brackets = false -coalesce_brackets = true -align_closing_bracket_with_visual_indent = false diff --git a/third/sol2/CMakeLists.txt b/third/sol2/CMakeLists.txt deleted file mode 100644 index 120dd38d..00000000 --- a/third/sol2/CMakeLists.txt +++ /dev/null @@ -1,311 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# # # # sol2 -# # # Required minimum version statement -cmake_minimum_required(VERSION 3.16.0) -# # # Project Include - file that is included after project declaration is finished -set(CMAKE_PROJECT_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Includes/Project.cmake") - -# # # project declaration -project(sol2 VERSION 4.0.0 LANGUAGES CXX C) - -if (sol2-is-top-level-project) - message(STATUS "sol2 is the top-level directory...") -endif() - -# Include standard modules -include(CMakePackageConfigHelpers) -include(CheckCXXCompilerFlag) -include(CMakeDependentOption) -include(GNUInstallDirs) -include(FetchContent) - -# # # Configuration -# # Cached defines, strings, paths and options -set(SOL2_LUA_VERSION "5.4.4" CACHE STRING "The version of Lua needed. Can be 5.1, 5.2, 5.3, 5.4, LuaJIT, or a more specific 3-part version number for a specifc Lua (e.g., 5.4.4 or luajit-2.0.5)") -set(SOL2_BUILD_LUA TRUE CACHE BOOL "Always build Lua, do not search for it in the system") -set(SOL2_PLATFORM "x64" CACHE STRING "Target platform to compile for when building binaries (x86, x64)") -option(SOL2_CI "Whether or not we are in continguous integration mode" OFF) -option(SOL2_SYSTEM_INCLUDE "Whether or not sol2 should be considered a system include. This helps suppress errors for when the sol2 author is a big derp and doesn't fix every single warning, ever." ON) -option(SOL2_TESTS "Enable build of tests" OFF) -option(SOL2_EXAMPLES "Enable build of examples" OFF) -option(SOL2_INTEROP_EXAMPLES "Enable build of interop examples" OFF) -option(SOL2_DYNAMIC_LOADING_EXAMPLES "Enable build of interop examples" OFF) -option(SOL2_SINGLE "Enable generation and build of single header files" OFF) -option(SOL2_DOCS "Enable build of documentation" OFF) -option(SOL2_ENABLE_INSTALL "Enable installation of Sol2" ON) -# Single tests and examples tests will only be turned on if both SINGLE and TESTS are defined -CMAKE_DEPENDENT_OPTION(SOL2_TESTS_SINGLE "Enable build of tests using the premade single headers" ON - "SOL2_SINGLE;SOL2_TESTS" OFF) -CMAKE_DEPENDENT_OPTION(SOL2_EXAMPLES_SINGLE "Enable build of examples using the generated single headers" OFF - "SOL2_SINGLE;SOL2_EXAMPLES" OFF) -CMAKE_DEPENDENT_OPTION(SOL2_INTEROP_EXAMPLES_SINGLE "Enable build of interop examples using the generated single headers" OFF - "SOL2_SINGLE;SOL2_INTEROP_EXAMPLES" OFF) -CMAKE_DEPENDENT_OPTION(SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE "Enable build of dynamic loading examples using the generated single headers" OFF - "SOL2_SINGLE;SOL2_DYNAMIC_LOADING_EXAMPLES" OFF) -CMAKE_DEPENDENT_OPTION(SOL2_TESTS_EXAMPLES "Enable build of examples as tests" ON - "SOL2_EXAMPLES" OFF) -CMAKE_DEPENDENT_OPTION(SOL2_TESTS_INTEROP_EXAMPLES "Enable build of interop examples as tests" ON - "SOL2_INTEROP_EXAMPLES" OFF) -CMAKE_DEPENDENT_OPTION(SOL2_TESTS_DYNAMIC_LOADING_EXAMPLES "Enable build of dynamic loading examples as tests" ON - "SOL2_DYNAMIC_LOADING_EXAMPLES" OFF) -CMAKE_DEPENDENT_OPTION(BUILD_LUA_AS_DLL "Build Lua as a DLL" ON - "SOL2_BUILD_LUA" OFF) - - -if (SOL2_SYSTEM_INCLUDE) - set(sol2-system-include SYSTEM) -endif() - -# # # sol2 Source Groups -# # Sources everyone is going to need -# Header files -file(GLOB_RECURSE sol2-headers - LIST_DIRECTORIES FALSE - CONFIGURE_DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/include/sol*.hpp -) - -file(GLOB_RECURSE sol2-sources - LIST_DIRECTORIES FALSE - CONFIGURE_DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/source/** -) - -# # # sol2 Library -# # Add a target for sol2's library to be included by external users -add_library(sol2 INTERFACE) -add_library(sol2::sol2 ALIAS sol2) -target_include_directories(sol2 ${sol2-system-include} - INTERFACE - $ - $) - -# # Version configurations -configure_package_config_file( - cmake/sol2-config.cmake.in - "${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-config.cmake" - INSTALL_DESTINATION lib/cmake/sol2 - NO_CHECK_REQUIRED_COMPONENTS_MACRO) - -write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-config-version.cmake" - COMPATIBILITY AnyNewerVersion) - -export(TARGETS sol2 - FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-targets.cmake") - -if(SOL2_ENABLE_INSTALL) - install(TARGETS sol2 - EXPORT sol2) - - install(EXPORT sol2 - FILE sol2-targets.cmake - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/sol2") - - install(DIRECTORY include/sol - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") - - install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/cmake/sol2-config-version.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/sol2") -endif() - -# # # sol2 Library - Single header target -if (SOL2_SINGLE) - message(STATUS "sol2 adding single...") - add_subdirectory(single) -endif() - -# # # documentation -# Generates the docs -if (SOL2_DOCS) - message(STATUS "sol2 adding docs...") - add_subdirectory(documentation) -endif() - -if(SOL2_ENABLE_INSTALL) - # pkg-config support, except on Windows - if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows) - set(PKGCONFIG_INSTALL_DIR - "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" - CACHE PATH "Path where sol2.pc is installed") - - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sol2.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/sol2.pc" @ONLY) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sol2.pc" DESTINATION "${PKGCONFIG_INSTALL_DIR}") - endif() -endif() - -if (SOL2_CI) - message(STATUS "sol2 Contiguous Integration is on") -endif() - -if (SOL2_EXAMPLES OR SOL2_TESTS_EXAMPLES OR SOL2_EXAMPLES_SINGLE OR SOL2_INTEROP_EXAMPLES OR SOL2_TESTS_INTEROP_EXAMPLES OR SOL2_INTEROP_EXAMPLES_SINGLE OR SOL2_DYNAMIC_LOADING_EXAMPLES OR SOL2_TESTS_DYNAMIC_LOADING_EXAMPLES OR SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE) - set(SOL2_DO_EXAMPLES TRUE) -else() - set(SOL2_DO_EXAMPLES FALSE) -endif() - -if (SOL2_TESTS OR SOL2_TESTS_SINGLE) - set(SOL2_DO_TESTS TRUE) -else() - set(SOL2_DO_TESTS FALSE) -endif() - -# # # Tests, Examples and other CI suites that come with sol2 -if (sol2-is-top-level-project) - # # # General project output locations - if (CMAKE_SIZEOF_VOID_P EQUAL 4) - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/lib") - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/bin") - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/bin") - else() - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/lib") - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/bin") - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/bin") - endif() - - if (NOT CMAKE_CXX_STANDARD GREATER_EQUAL 17) - set(CMAKE_CXX_STANDARD 17) - endif() - - if (NOT CMAKE_C_STANDARD GREATER_EQUAL 11) - set(CMAKE_C_STANDARD 11) - endif() - - # Build Flag Settings - # Basic/Normal flags - check_compiler_flag(disable-permissive MSVC /permissive- GCC -pedantic) - check_compiler_flag(utf8-literal-encoding MSVC /execution-charset:utf-8 GCC -fexec-charset=utf-8) - check_compiler_flag(utf8-source-encoding MSVC /source-charset:utf-8 GCC -finput-charset=utf-8) - check_compiler_flag(extra-constexpr-depth MSVC /constexpr:depth2147483647 GCC -fconstexpr-depth=2147483647 CLANG -fconstexpr-depth=2147483647) - check_compiler_flag(extra-constexpr-steps MSVC /constexpr:steps2147483647 GCC -fconstexpr-ops-limit=2147483647 CLANG -fconstexpr-steps=2147483647) - check_compiler_flag(template-debugging-mode GCC -ftemplate-backtrace-limit=0) - check_compiler_flag(big-obj MSVC /bigobj) - # Overall warning flags - check_compiler_flag(pedantic GCC -pedantic) - check_compiler_flag(warn-pedantic GCC -Wpedantic) - check_compiler_flag(warn-all MSVC /W4 GCC -Wall) - check_compiler_flag(warn-extra GCC -Wextra) - check_compiler_flag(warn-errors MSVC /WX GCC -Werror) - # Individual warnings/errors - check_compiler_diagnostic(unknown-warning) - check_compiler_diagnostic(unknown-warning-option) - check_compiler_diagnostic(microsoft-cast) - check_compiler_diagnostic(noexcept-type) - check_compiler_diagnostic(unreachable-code MSVC 4702) - check_compiler_diagnostic(padding-from-alignment MSVC 4324) - - # # # Libraries - # Here, we pull in all the necessary libraries for building examples and tests - # Find threading library - find_package(Threads REQUIRED) - - string(TOLOWER ${SOL2_LUA_VERSION} NORMALIZED_LUA_VERSION) - # Find way to get Lua: build if requested, or attempt to build if no matching version is found - if (SOL2_BUILD_LUA) - find_package(LuaBuild REQUIRED COMPONENTS ${SOL2_LUA_VERSION}) - elseif (NOT SOL2_LUA_VERSION) - find_package(LuaBuild REQUIRED) - else () - if (NORMALIZED_LUA_VERSION MATCHES "5.1") - set(CREATE_LUALIB_TARGET TRUE) - find_package(Lua 5.1 EXACT REQUIRED) - elseif(NORMALIZED_LUA_VERSION MATCHES "5.2") - set(CREATE_LUALIB_TARGET TRUE) - find_package(Lua 5.2 EXACT REQUIRED) - elseif(NORMALIZED_LUA_VERSION MATCHES "5.3") - set(CREATE_LUALIB_TARGET TRUE) - find_package(Lua 5.3 EXACT REQUIRED) - elseif(NORMALIZED_LUA_VERSION MATCHES "5.4") - set(CREATE_LUALIB_TARGET TRUE) - find_package(Lua 5.4 EXACT REQUIRED) - elseif(NORMALIZED_LUA_VERSION MATCHES "luajit") - set(CREATE_LUALIB_TARGET TRUE) - find_package(LuaJIT REQUIRED) - else() - find_package(LuaBuild ${SOL2_LUA_VERSION} REQUIRED) - endif() - endif() - - if (CREATE_LUALIB_TARGET AND LUA_FOUND) - set(lualib lua_imported_lib_${SOL2_LUA_VERSION}) - foreach(lua_search_lib ${LUA_LIBRARIES}) - get_filename_component(lsl_fname ${lua_search_lib} NAME) - if (lsl_fname MATCHES "lua" OR lsl_fname MATCHES "Lua" OR lsl_fname MATCHES "LUA") - if (lsl_fname MATCHES "\.so|\.dylib|\.dll") - set(lualibtype SHARED) - set(lualiblocation ${lua_search_lib}) - else() - set(lualibtype STATIC) - set(lualiblocation ${lua_search_lib}) - endif() - else() - set(LUA_SEARCH_DEPENDENCY_LIBS ${LUA_SEARCH_DEPENDENCY_LIBS} "${lua_search_lib}") - endif() - endforeach() - add_library(${lualib} ${lualibtype} IMPORTED) - set_target_properties(${lualib} - PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${LUA_INCLUDE_DIR} - INTERFACE_LINK_LIBRARIES "${LUA_SEARCH_DEPENDENCY_LIBS} ${CMAKE_DL_LIBS}" - IMPORTED_LINK_INTERFACE_LANGUAGES C - IMPORTED_LOCATION ${lualiblocation}) - set(LUA_LIBRARIES ${lualib}) - endif() - - if (NOT LUA_FOUND AND NOT LUABUILD_FOUND) - message(FATAL_ERROR "sol2 Lua \"${SOL2_LUA_VERSION}\" not found and could not be targeted for building") - endif() - - # # Enable test harness for regular, example or single tests - if (SOL2_DO_TESTS OR (SOL2_TESTS_EXAMPLES AND SOL2_DO_EXAMPLES)) - # enable ctest - message(STATUS "sol2 testing enabled...") - enable_testing() - endif() - - # # # Examples - # # Enable examples to be built against the library - if (SOL2_DO_EXAMPLES) - # NOTE: will also add to tests if TESTS is defined - message(STATUS "sol2 adding examples...") - add_subdirectory(examples) - endif() - - # # # Tests - # # Add tests here - if (SOL2_DO_TESTS) - # add subdir to get going - message(STATUS "sol2 adding tests...") - add_subdirectory(tests) - endif() - - # # # Scratch Space - # # Scratch space for diagnosing bugs and other shenanigans - if (SOL2_SCRATCH) - message(STATUS "sol2 adding scratch space...") - add_subdirectory(scratch) - endif() -endif() diff --git a/third/sol2/CONTRIBUTING.md b/third/sol2/CONTRIBUTING.md deleted file mode 100644 index 163dd3dc..00000000 --- a/third/sol2/CONTRIBUTING.md +++ /dev/null @@ -1,27 +0,0 @@ -## Contributing to sol - -Looking to contribute to sol? Well, first thing I want to mention is thank you! -Second of all, this is probably where you should look :) - -## Reporting Issues - -If you found a bug, please make sure to make an issue in the issue tracker. - -The guidelines for reporting a bug are relatively simple and are as follows: - -1. Produce a simple, short, compilable test case that reproduces your problem. -2. Make a descriptive title that summarises the bug as a whole. -3. Explain the bug in as much detail as you can in the body of the issue. - -If you have all of those requirements set, then your issue reporting is golden. - -## Submitting a pull request - -Submitting a pull request is fairly simple, just make sure it focuses on a single aspect and doesn't -manage to have scope creep and it's probably good to go. It would be incredibly lovely if the style is -consistent to those found in the repository. - -To help with this, a `.clang-format` is included. Please run it on your code before you push anything. - -If you don't meet all of these style guidelines, don't fret. I'll probably fix it. But please -do make an effort to actually meet them. Otherwise I'm more likely to reject the pull request. diff --git a/third/sol2/CONTRIBUTORS.md b/third/sol2/CONTRIBUTORS.md deleted file mode 100644 index 6f93fd5d..00000000 --- a/third/sol2/CONTRIBUTORS.md +++ /dev/null @@ -1,27 +0,0 @@ -# 🎉 Donators! ♥ 🎉 - -Thank you to all patrons, donators and contributors who help keep sol2 amazing. - -- Robert Salvet -- Ορφέας Ζαφείρης - 2x Donations! -- Michael Wallar -- Johannes Schultz -- Elias Daler -- BECKMANN & EGLE Industrieelektronik GmbH [bue.de](https://www.bue.de/) - - -# 🎉 Patrons! ♥ 🎉 - -Beyond just a one-time donation, patrons make a continued commitment to help keep sol2 supported and bug-free. Thank you for your patronage! Here are the supporters that wanted to be featured as sol2 contributors. - -- Joel Falcou -- Michael Caisse -- Joshua Fisher -- Ορφέας Ζαφείρης - - -# Company Patrons / Supporters # - -Companies who sign up for a long-term support contract or patronage are listed here! They really push forward what's possible with sol2 (and the newer v3)! Please reach out to phdofthehouse@gmail.com if you are interested in a custom solution or a long-term support contract that goes beyond the current release's needs! - -- Intrepid Control Systems [intrepidcs.com](https://www.intrepidcs.com/) diff --git a/third/sol2/Dockerfile b/third/sol2/Dockerfile deleted file mode 100644 index ef91b51d..00000000 --- a/third/sol2/Dockerfile +++ /dev/null @@ -1,71 +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. - -# Start from the ubuntu:bionic image -FROM ubuntu:bionic -# owner -LABEL author="ThePhD " -LABEL maintainer="ThePhD " -# We want our working directory to be the home directory -WORKDIR /root - -# RUN is how you write to the image you've pulled down -# RUN actions are "committed" to the image, and everything will -# start from the base after all run commands are executed -RUN apt-get update && apt-get install -y \ - zsh - -# Scripts should be added directly to the docker image to get us started -# We can mount the whole sol2 directory later as a volume -ADD scripts/ /root/sol2-scripts - -RUN mkdir -p /root/build-sol2/Debug /root/build-sol2/Release -RUN chmod +x /root/sol2-scripts/preparation.linux.sh - -VOLUME /root/sol2 -#ADD . /root/sol2 - -# # Above this is more or less static parts: the rest is non-static -# # This is ordered like this so making multiple of these -# # containers is more or less identical up to this point -# Command line arguments, with default values -ARG SOL2_PLATFORM=x64 -ARG SOL2_LUA_VERSION=x64 -ARG SOL2_LUA_VERSION=5.4.4 -ARG SOL2_TEST_SINGLE=false -ARG SOL2_TEST_INTEROP=false -ARG SOL2_CI=true -ARG GCC_VERSION -ARG LLVM_VERSION - -# Potential environment variables -ENV SOL2_LUA_VERSION=${SOL2_LUA_VERSION} SOL2_TEST_SINGLE=${SOL2_TEST_SINGLE} SOL2_TEST_INTEROP=${SOL2_TEST_INTEROP} SOL2_CI=${SOL2_CI} SOL2_PLATFORM=${SOL2_PLATFORM} GCC_VERSION=${GCC_VERSION} LLVM_VERSION=${LLVM_VERSION} SOL2_DIR=/root/sol2 - -RUN ["/usr/bin/env", "zsh", "-e", "/root/sol2-scripts/preparation.linux.sh"] - -# CMD/ENTRYPOINT is different from RUN -# these are done on a per-instantiation and essentially describe -# the DEFAULT behavior of this container when its started, not what state it -# gets "saved" in... -# it only runs the last CMD/ENTRYPOINT as the default behavior: -# multiple CMDs will not be respected -ENTRYPOINT ["/usr/bin/env", "zsh", "-e", "/root/sol2/scripts/run.linux.sh"] diff --git a/third/sol2/LICENSE.txt b/third/sol2/LICENSE.txt deleted file mode 100644 index 58134405..00000000 --- a/third/sol2/LICENSE.txt +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013-2022 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. diff --git a/third/sol2/README.md b/third/sol2/README.md deleted file mode 100644 index 05ca9e1d..00000000 --- a/third/sol2/README.md +++ /dev/null @@ -1,161 +0,0 @@ -# sol2 - -[![Documentation Status](https://readthedocs.org/projects/sol2/badge/?version=latest)](http://sol2.readthedocs.io/en/latest/?badge=latest) - - - -sol2 is a C++ library binding to Lua. It currently supports all Lua versions 5.1+ (LuaJIT 2.0+ and MoonJIT included). sol2 aims to be easy to use and easy to add to a project. The library is header-only for easy integration with projects, and a single header can be used for drag-and-drop start up. - - - -## Sneak Peek - -```cpp -#include -#include - -int main() { - sol::state lua; - int x = 0; - lua.set_function("beep", [&x]{ ++x; }); - lua.script("beep()"); - assert(x == 1); -} -``` - -```cpp -#include -#include - -struct vars { - int boop = 0; -}; - -int main() { - sol::state lua; - lua.new_usertype("vars", "boop", &vars::boop); - lua.script("beep = vars.new()\n" - "beep.boop = 1"); - assert(lua.get("beep").boop == 1); -} -``` - -More examples are given in the examples directory [here](https://github.com/ThePhD/sol2/tree/develop/examples). - - -## Documentation - -Find it [here](http://sol2.rtfd.io/). A run-through kind of tutorial is [here](http://sol2.readthedocs.io/en/latest/tutorial/all-the-things.html)! The API documentation goes over most cases (particularly, the "api/usertype" and "api/table_proxy" and "api/function" sections) that should still get you off your feet and going, and there's an examples directory [here](https://github.com/ThePhD/sol2/tree/develop/examples) as well. - - - - -# "I need X Feature or Fix, Right Now™" - -Find the support option that's right for you, [here](https://github.com/ThePhD/.github/blob/main/SUPPORT.md)! If you're happy to wait, you can just file a boring issue and we'll get to it Whenever There Is Time™. - - - -## I want to donate to help! - -You can find [donation and sponorship options here](https://github.com/ThePhD/.github/blob/main/SUPPORT.md#support-in-general) and from the little heart button near the top of this repository that will take you to a bevy of links in which you can donate and show support for this project and others! - - - - -# Features - -- [Fastest in the land](http://sol2.readthedocs.io/en/latest/benchmarks.html) (see: sol2 bar in graph). -- Supports retrieval and setting of multiple types including: - * `std::string`, `std::wstring`, `std::u16string` and `std::u32string` support (and for views). - * understands and works with containers such as `std::map/unordered_map`, c-style arrays, vectors, non-standard custom containers and more. - * user-defined types, with or **without** registering that type - * `std::unique_ptr`, `std::shared_ptr`, and optional support of other pointer types like `boost::shared_ptr`. - * custom `optional` that works with references, and support for the inferior `std::optional`. - * C++17 support for variants and similar new types. -- Lambda, function, and member function bindings are supported. -- Intermediate type for checking if a variable exists. -- Simple API that completely abstracts away the C stack API, including `protected_function` with the ability to use an error-handling function. -- `operator[]`-style manipulation of tables -- C++ type representations in Lua userdata as `usertype`s with guaranteed cleanup. -- Customization points to allow your C++ objects to be pushed and retrieved from Lua as multiple consecutive objects, or anything else you desire! -- Overloaded function calls: `my_function(1); my_function("Hello")` in the same Lua script route to different function calls based on parameters -- Support for tables, nested tables, table iteration with `table.for_each` / `begin()` and `end()` iterators. -- Zero string overhead for usertype function lookup. - - - -## Supported Compilers - -sol2 makes use of C++17 features. GCC 7.x.x and Clang 3.9.x (with `-std=c++1z` and appropriate standard library) or higher should be able to compile without problems. However, the officially supported and CI-tested compilers are: - -- GCC 7.x.x+ (MinGW 7.x.x+) -- Clang 3.9.x+ -- Visual Studio 2017 Community (Visual C++ 15.0)+ - -Please make sure you use the `-std=c++2a`, `-std=c++1z`, `-std=c++17` or better standard flags -(some of these flags are the defaults in later versions of GCC, such as 7+ and better). - -If you would like support for an older compiler (at the cost of some features), use the latest tagged sol2 branch. If you would like support for an even older compiler, feel free to contact me for a Custom Solution. - -sol2 is checked by-hand for other platforms as well, including Android-based builds with GCC and iOS-based builds out of XCode with Apple-clang. It should work on both of these platforms, so long as you have the proper standards flags. If something doesn't work or you need special options, you may need to look into the different ways to support the project to have it done for you! - - - -## Creating a single header - -You can grab a single header (and the single forward header) out of the library [here](https://github.com/ThePhD/sol2/tree/develop/single). For stable version, check the releases tab on GitHub for a provided single header file for maximum ease of use. A script called [`single.py`](https://github.com/ThePhD/sol2/blob/develop/single/single.py) is provided in the repository if there's some bleeding edge change that hasn't been published on the releases page. You can run this script to create a single file version of the library so you can only include that part of it. Check `single.py --help` for more info. - -If you use CMake, you can also configure and generate a project that will generate the `sol2_single_header` for you. You can also include the project using CMake. Run CMake for more details. Thanks @Nava2, @alkino, @mrgreywater and others for help with making the CMake build a reality. - - - - -# Testing - -Testing turns on certain CI-only variables in the CMake to test a myriad of configuration options. You can generate the tests by running CMake and configuring `SOL2_TESTS`, `SOL2_TESTS_SINGLE`, `SOL2_TESTS_EXAMPLES`, and `SOL2_EXAMPLES` to be on. Make sure `SOL2_SINGLE` is also on. - -You will need any flavor of python3 and an available compiler. The testing suite will build its own version of Lua and LuaJIT, so you do not have to provide one (you may provide one with the `LUA_LOCAL_DIR` variable). - - - -# Presentations - -"A Sun For the Moon - A Zero-Overhead Lua Abstraction using C++" -ThePhD -Lua Workshop 2016 - Mashape, San Francisco, CA -[Deck](https://github.com/ThePhD/sol2/blob/develop/docs/presentations/2016.10.14%20-%20ThePhD%20-%20No%20Overhead%20C%20Abstraction.pdf) - -"Wrapping Lua C in C++ - Efficiently, Nicely, and with a Touch of Magic" -ThePhD -Boston C++ Meetup November 2017 - CiC (Milk Street), Boston, MA -[Deck](https://github.com/ThePhD/sol2/blob/develop/docs/presentations/2017.11.08%20-%20ThePhD%20-%20Wrapping%20Lua%20C%20in%20C%2B%2B.pdf) - -"Biting the CMake Bullet" -ThePhD -Boston C++ Meetup February 2018 - CiC (Main Street), Cambridge, MA -[Deck](https://github.com/ThePhD/sol2/blob/develop/docs/presentations/2018.02.06%20-%20ThePhD%20-%20Biting%20the%20CMake%20Bullet.pdf) - -"Compile Fast, Run Faster, Scale Forever: A look into the sol2 Library" -ThePhD -C++Now 2018 - Hudson Commons, Aspen Physics Center, Aspen, Colorado -[Deck](https://github.com/ThePhD/sol2/blob/develop/docs/presentations/2018.05.10%20-%20ThePhD%20-%20Compile%20Fast%2C%20Run%20Faster%2C%20Scale%20Forever.pdf) - -"Scripting at the Speed of Thought: Using Lua in C++ with sol2" -ThePhD -CppCon 2018 - 404 Keystone, Meydenbauer Center, Aspen, Colorado -[Deck](https://github.com/ThePhD/sol2/blob/develop/docs/presentations/2018.09.28%20-%20ThePhD%20-%20Scripting%20at%20the%20Speed%20of%20Thought.pdf) - -"The Plan for Tomorrow: Compile-Time Extension Points in C++" -ThePhD -C++Now 2019 - Flug Auditorium, Aspen Physics Center, Aspen, Colorado -[Deck](https://github.com/ThePhD/sol2/blob/develop/docs/presentations/2019.05.10%20-%20ThePhD%20-%20The%20Plan%20for%20Tomorrow%20-%20Compile-Time%20Extension%20Points%20in%20C%2b%2b.pdf) - - - - -# License - -sol2 is distributed with an MIT License. You can see LICENSE.txt for more info. - -If you need a custom solution, [feel free to reach out](https://soasis.org/contact/opensource/). diff --git a/third/sol2/cmake/Includes/Project.cmake b/third/sol2/cmake/Includes/Project.cmake deleted file mode 100644 index 7a84a2dc..00000000 --- a/third/sol2/cmake/Includes/Project.cmake +++ /dev/null @@ -1,52 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# # # # sol2 - cmake - basic project configuration - -include_guard(DIRECTORY) - -list(PREPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Packages") -list(PREPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules") -list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") -list(APPEND CMAKE_MESSAGE_CONTEXT "${PROJECT_NAME}") - -if (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) - set(sol2-is-top-level-project TRUE) -else() - set(sol2-is-top-level-project FALSE) -endif() - -# # CMake and sol2 Includes -# CMake -include(CheckCXXCompilerFlag) -include(CheckCCompilerFlag) -include(CheckIPOSupported) -include(CMakeDependentOption) -include(CMakePrintHelpers) -include(GNUInstallDirs) -include(FeatureSummary) -include(FetchContent) -include(CTest) -# sol2 -include(CheckCompilerDiagnostic) -include(CheckCompilerFlag) -include(FindVersion) diff --git a/third/sol2/cmake/Modules/CheckCompilerDiagnostic.cmake b/third/sol2/cmake/Modules/CheckCompilerDiagnostic.cmake deleted file mode 100644 index 77daf32f..00000000 --- a/third/sol2/cmake/Modules/CheckCompilerDiagnostic.cmake +++ /dev/null @@ -1,92 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# # # # sol2 - cmake - compiler diagnostic checking - -include_guard(GLOBAL) - -include(CheckCXXCompilerFlag) -include(CheckCCompilerFlag) - -#[[ -Given a diagnostic name and flag, like -check_cxx_compiler_diagnostic(pig MSVC 1312) -or -check_cxx_compiler_diagnostic(pig GCC acab) -we check if the given flag works C++ compiler. If it does, we then generate -a --warn, --allow, --deny, and --forbid prefixed set of variables. Users are -then free to simply apply them to targets at will. -]] -function (check_compiler_diagnostic diagnostic) - cmake_parse_arguments(diagnostic "" "GCC;MSVC;CLANG" "" ${ARGN}) - if (NOT diagnostic_GCC) - set(diagnostic_GCC ${diagnostic}) - endif() - if (NOT diagnostic_MSVC) - set(diagnostic_MSVC ${diagnostic}) - endif() - if (NOT diagnostic_CLANG) - set(diagnostic_CLANG ${diagnostic_GCC}) - endif() - string(MAKE_C_IDENTIFIER "${diagnostic}" suffix) - string(TOUPPER "${suffix}" suffix) - get_property(enabled-languages GLOBAL PROPERTY ENABLED_LANGUAGES) - if (CXX IN_LIST enabled-languages) - if (MSVC) - check_cxx_compiler_flag(-wo${diagnostic_MSVC} CXX_DIAGNOSTIC_${suffix}) - elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) - check_cxx_compiler_flag(-W${diagnostic_CLANG} CXX_DIAGNOSTIC_${suffix}) - else() - check_cxx_compiler_flag(-W${diagnostic_GCC} CXX_DIAGNOSTIC_${suffix}) - endif() - endif() - if (C IN_LIST enabled-languages) - if (MSVC) - check_c_compiler_flag(-wo${diagnostic_MSVC} C_DIAGNOSTIC_${suffix}) - elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) - check_c_compiler_flag(-W${diagnostic_CLANG} C_DIAGNOSTIC_${suffix}) - else() - check_c_compiler_flag(-W${diagnostic_GCC} C_DIAGNOSTIC_${suffix}) - endif() - endif() - string(CONCAT when $,$>, - $,$> - >) - string(CONCAT diagnostic_flag - $<$:${diagnostic_MSVC}> - $<$:${diagnostic_MSVC}> - $<$:${diagnostic_GCC}> - $<$:${diagnostic_GCC}> - $<$:${diagnostic_CLANG}> - $<$:${diagnostic_CLANG}> - ) - set(forbid_prefix $,-we,-Werror=>) - set(allow_prefix $,-wd,-Wno->) - set(warn_prefix $,-w1,-W>) - - set(--forbid-${diagnostic} $<${when}:${forbid_prefix}${diagnostic_flag}> PARENT_SCOPE) - set(--deny-${diagnostic} ${--forbid-${diagnostic}} PARENT_SCOPE) - set(--allow-${diagnostic} $<${when}:${allow_prefix}${diagnostic_flag}> PARENT_SCOPE) - set(--warn-${diagnostic} $<${when}:${warn_prefix}${diagnostic_flag}> PARENT_SCOPE) - -endfunction() diff --git a/third/sol2/cmake/Modules/CheckCompilerFlag.cmake b/third/sol2/cmake/Modules/CheckCompilerFlag.cmake deleted file mode 100644 index d1cfe6de..00000000 --- a/third/sol2/cmake/Modules/CheckCompilerFlag.cmake +++ /dev/null @@ -1,83 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# # # # sol2 - cmake - compiler flag checking - -include_guard(GLOBAL) - -include(CheckCXXCompilerFlag) -include(CheckCCompilerFlag) - -#[[ -Given a flag name and the actual flag, like -check_cxx_compiler_flag(strict-conformance MSVC /permissive- GCC -pedantic) -we check if the given flag works C++ compiler. If it is, then ---strict-conformance will be the provided flag. MSVC and GCC are the 2 different -"style" of flags to be tested for. -]] -function (check_compiler_flag flag_name) - cmake_parse_arguments(PARSE_ARGV 1 flag "" "" "GCC;MSVC;CLANG") - if (NOT flag_MSVC) - set(flag_MSVC /${flag_name}) - endif() - if (NOT flag_GCC) - set(flag_GCC ${flag_name}) - endif() - if (NOT flag_CLANG) - set(flag_CLANG ${flag_GCC}) - endif() - string(MAKE_C_IDENTIFIER "${flag_name}" suffix) - string(TOUPPER "${suffix}" suffix) - get_property(enabled-languages GLOBAL PROPERTY ENABLED_LANGUAGES) - if (CXX IN_LIST enabled-languages) - if (MSVC) - check_cxx_compiler_flag(${flag_MSVC} CXX_CHECK_FLAG_${suffix}) - elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) - check_cxx_compiler_flag(${flag_CLANG} CXX_CHECK_FLAG_${suffix}) - else() - check_cxx_compiler_flag(${flag_GCC} CXX_CHECK_FLAG_${suffix}) - endif() - endif() - if (C IN_LIST enabled-languages) - if (MSVC) - check_c_compiler_flag(${flag_MSVC} C_CHECK_FLAG_${suffix}) - elseif (CMAKE_C_COMPILER_ID MATCHES Clang) - check_c_compiler_flag(${flag_CLANG} C_CHECK_FLAG_${suffix}) - else() - check_c_compiler_flag(${flag_GCC} C_CHECK_FLAG_${suffix}) - endif() - endif() - string(CONCAT when $,$>, - $,$> - >) - string(CONCAT compiler_flag - $<$:${flag_MSVC}> - $<$:${flag_MSVC}> - $<$:${flag_GCC}> - $<$:${flag_GCC}> - $<$:${flag_CLANG}> - $<$:${flag_CLANG}> - ) - - set(--${flag_name} $<${when}:${compiler_flag}> PARENT_SCOPE) -endfunction() diff --git a/third/sol2/cmake/Modules/Common/Core.cmake b/third/sol2/cmake/Modules/Common/Core.cmake deleted file mode 100644 index 4a1d4fef..00000000 --- a/third/sol2/cmake/Modules/Common/Core.cmake +++ /dev/null @@ -1,35 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -if(_common_core_included) - return() -endif(_common_core_included) -set(_common_core_included true) - -# # Prepend function (is there an equivalent in CMake somewhere...?) -function(prepend var prefix) - set(l "") - foreach(f ${ARGN}) - list(APPEND l "${prefix}${f}") - endforeach(f) - SET(${var} "${l}" PARENT_SCOPE) -ENDFUNCTION(prepend) diff --git a/third/sol2/cmake/Modules/FindVersion.cmake b/third/sol2/cmake/Modules/FindVersion.cmake deleted file mode 100644 index 204a7c60..00000000 --- a/third/sol2/cmake/Modules/FindVersion.cmake +++ /dev/null @@ -1,61 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# # # # sol2 - cmake - version matching - -include_guard(GLOBAL) - -#[[ -This is used to create a version variable. How these are used or set is up -to the user. -TODO: Support find_version( SOURCE ) for parsing a version name from a header file -TODO: Support find_version( LIBRARY ) for .dll/.lib/.so/.dylib parsing -]] -function (find_version output) - cmake_parse_arguments(ARG "" "OPTION;REGEX;COMMAND;DOC" "" ${ARGN}) - unset(version-output) - unset(version-check) - if (NOT ARG_OPTION) - set(ARG_OPTION "--version") - endif() - if (NOT ARG_REGEX) - set(ARG_REGEX "[^0-9]*([0-9]+)[.]([0-9]+)?[.]?([0-9]+)?[.]?([0-9]+)?.*") - endif() - if (ARG_COMMAND AND NOT DEFINED ${output}) - execute_process( - COMMAND ${ARG_COMMAND} ${ARG_OPTION} - OUTPUT_VARIABLE version-output - OUTPUT_STRIP_TRAILING_WHITESPACE - ENCODING UTF-8) - if (version-output) - string(REGEX MATCH "${ARG_REGEX}" version-check ${version-output}) - endif() - if (version-check) - string(JOIN "." ${output} - ${CMAKE_MATCH_1} - ${CMAKE_MATCH_2} - ${CMAKE_MATCH_3} - ${CMAKE_MATCH_4}) - set(${output} "${${output}}" CACHE STRING "${ARG_DOC}" FORCE) - endif() - endif() -endfunction() diff --git a/third/sol2/cmake/Packages/FindKaguyaBuild.cmake b/third/sol2/cmake/Packages/FindKaguyaBuild.cmake deleted file mode 100644 index c90c1554..00000000 --- a/third/sol2/cmake/Packages/FindKaguyaBuild.cmake +++ /dev/null @@ -1,76 +0,0 @@ - -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -include(ExternalProject) -include(FindPackageHandleStandardArgs) -include(Common/Core) - -# # Base variables -set(kaguya_version 1.3.2) -set(kaguya_lib kaguya_lib_${kaguya_version}) - -# # Useful locations -set(kaguya_build_toplevel "${CMAKE_BINARY_DIR}/vendor/kaguya_${kaguya_version}") -set(kaguya_include_dirs "${kaguya_build_toplevel}/include") - -# # kaguya library sources -set(kaguya_sources kaguya/kaguya.hpp) -prepend(kaguya_sources "${kaguya_build_toplevel}/include/" ${kaguya_sources}) - -# # External project to get sources -ExternalProject_Add(KAGUYA_BUILD_SOURCE - BUILD_IN_SOURCE TRUE - BUILD_ALWAYS FALSE - # # Use Git to get what we need - GIT_SHALLOW TRUE - GIT_SUBMODULES "" - GIT_REPOSITORY https://github.com/satoren/kaguya.git - PREFIX ${kaguya_build_toplevel} - SOURCE_DIR ${kaguya_build_toplevel} - DOWNLOAD_DIR ${kaguya_build_toplevel} - TMP_DIR "${kaguya_build_toplevel}-tmp" - STAMP_DIR "${kaguya_build_toplevel}-stamp" - INSTALL_DIR "${kaguya_build_toplevel}/local" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" - BUILD_BYPRODUCTS "${kaguya_sources}") - -add_library(${kaguya_lib} INTERFACE) -add_dependencies(${kaguya_lib} KAGUYA_BUILD_SOURCE) -target_include_directories(${kaguya_lib} INTERFACE ${kaguya_include_dirs}) -target_link_libraries(${kaguya_lib} INTERFACE ${LUA_LIBRARIES}) -if (NOT MSVC) - target_compile_options(${kaguya_lib} INTERFACE - -Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter) -endif() - -set(KAGUYABUILD_FOUND TRUE) -set(KAGUYA_LIBRARIES ${kaguya_lib}) -set(KAGUYA_INCLUDE_DIRS ${kaguya_include_dirs}) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(KaguyaBuild - FOUND_VAR KAGUYABUILD_FOUND - REQUIRED_VARS KAGUYA_LIBRARIES KAGUYA_INCLUDE_DIRS - VERSION_VAR kaguya_version) diff --git a/third/sol2/cmake/Packages/FindLua/set_version_vars.cmake b/third/sol2/cmake/Packages/FindLua/set_version_vars.cmake deleted file mode 100644 index 1f64f9f3..00000000 --- a/third/sol2/cmake/Packages/FindLua/set_version_vars.cmake +++ /dev/null @@ -1,77 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# Uses the Lua version and calculates the names of the include directories and library -# name accordingly. -# -# :: -# _prefix - Prefix added to all variables exposed, e.g. "lua" or "luajit" -# _lua_suffix - Name suffix, typically only used for specifiying luajit, which is "jit" - -function(_lua_set_version_vars _prefix _lua_suffix) - set(LUA_VERSIONS5 5.3 5.2 5.1 5.0) - - if (${_prefix}_FIND_VERSION_EXACT) - if (${_prefix}_FIND_VERSION_COUNT GREATER 1) - set(_${_prefix}_append_versions ${${_prefix}_FIND_VERSION_MAJOR}.${${_prefix}_FIND_VERSION_MINOR}) - endif () - elseif (${_prefix}_FIND_VERSION) - # once there is a different major version supported this should become a loop - if (NOT ${_prefix}_FIND_VERSION_MAJOR GREATER 5) - if (${_prefix}_FIND_VERSION_COUNT EQUAL 1) - set(_${_prefix}_append_versions ${${_prefix}_VERSIONS5}) - else () - foreach (subver IN LISTS ${_prefix}_VERSIONS5) - if (NOT subver VERSION_LESS ${${_prefix}_FIND_VERSION}) - list(APPEND _${_prefix}_append_versions ${subver}) - endif () - endforeach () - endif () - endif () - else () - # once there is a different major version supported this should become a loop - set(_${_prefix}_append_versions ${LUA_VERSIONS5}) - endif () - - list(APPEND _${_prefix}_include_subdirs "include/lua" "include") - - foreach (ver IN LISTS _${_prefix}_append_versions) - string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _ver "${ver}") - list(APPEND _${_prefix}_include_subdirs - include/lua${_lua_suffix}${CMAKE_MATCH_1}${CMAKE_MATCH_2} - include/lua${_lua_suffix}${CMAKE_MATCH_1}.${CMAKE_MATCH_2} - include/lua${_lua_suffix}-${CMAKE_MATCH_1}.${CMAKE_MATCH_2} - ) - - # LuaJIT hides itself as Lua lib (maintaining ABI compat) - list(APPEND _${_prefix}_library_names - lua${CMAKE_MATCH_1}${CMAKE_MATCH_2} - lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2} - lua.${CMAKE_MATCH_1}.${CMAKE_MATCH_2} - lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2} - ) - endforeach () - - set(_${_prefix}_include_subdirs "${_${_prefix}_include_subdirs}" PARENT_SCOPE) - set(_${_prefix}_append_versions "${_${_prefix}_append_versions}" PARENT_SCOPE) - set(_${_prefix}_library_names "${_${_prefix}_library_names}" PARENT_SCOPE) -endfunction(_lua_set_version_vars) diff --git a/third/sol2/cmake/Packages/FindLua/version_check.cmake b/third/sol2/cmake/Packages/FindLua/version_check.cmake deleted file mode 100644 index fa62f434..00000000 --- a/third/sol2/cmake/Packages/FindLua/version_check.cmake +++ /dev/null @@ -1,28 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -# Provides a common-mechanic for extracting Lua versions from Lua/LuaJIT headers -macro(_lua_check_header_version _header_file _prefix) - # At least 5.[012] have different ways to express the version - # so all of them need to be tested. Lua 5.2 defines LUA_VERSION - # and LUA_RELEASE as joined by the C preprocessor, so avoid those. - file(STRINGS "${_header_file}" lua_version_strings - REGEX "^#define[ \t]+LUA_(RELEASE[ \t]+\"Lua [0-9]|VERSION([ \t]+\"Lua [0-9]|_[MR])).*") - - string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" ${_prefix}_VERSION_MAJOR ";${lua_version_strings};") - if (${_prefix}_VERSION_MAJOR MATCHES "^[0-9]+$") - string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" "${_prefix}_VERSION_MINOR" ";${lua_version_strings};") - string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" "${_prefix}_VERSION_PATCH" ";${lua_version_strings};") - set(${_prefix}_VERSION_STRING "${${_prefix}_VERSION_MAJOR}.${${_prefix}_VERSION_MINOR}.${${_prefix}_VERSION_PATCH}") - else () - string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" ${_prefix}_VERSION_STRING ";${lua_version_strings};") - if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$") - string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" ${_prefix}_VERSION_STRING ";${lua_version_strings};") - endif () - string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" ${_prefix}_VERSION_MAJOR "${${_prefix}_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" ${_prefix}_VERSION_MINOR "${${_prefix}_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" ${_prefix}_VERSION_PATCH "${${_prefix}_VERSION_STRING}") - endif () - - unset(lua_version_strings) -endmacro(_lua_check_header_version) \ No newline at end of file diff --git a/third/sol2/cmake/Packages/FindLuaBridgeBuild.cmake b/third/sol2/cmake/Packages/FindLuaBridgeBuild.cmake deleted file mode 100644 index 0ff884e8..00000000 --- a/third/sol2/cmake/Packages/FindLuaBridgeBuild.cmake +++ /dev/null @@ -1,74 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -include(ExternalProject) -include(FindPackageHandleStandardArgs) -include(Common/Core) - -# # Base variables -set(luabridge_version 1.0.2) -set(luabridge_lib luabridge_lib_${luabridge_version}) - -# # Useful locations -set(luabridge_build_toplevel "${CMAKE_BINARY_DIR}/vendor/luabridge_${luabridge_version}") -set(luabridge_include_dirs "${luabridge_build_toplevel}/Source") - -# # luabridge library sources -set(luabridge_sources LuaBridge/LuaBridge.h) -prepend(luabridge_sources "${luabridge_build_toplevel}/Source/" ${luabridge_sources}) - -# # External project to get sources -ExternalProject_Add(LUABRIDGE_BUILD_SOURCE - BUILD_IN_SOURCE TRUE - BUILD_ALWAYS FALSE - # # Use Git to get what we need - GIT_SHALLOW TRUE - GIT_SUBMODULES "" - GIT_REPOSITORY https://github.com/ThePhD/LuaBridge.git - PREFIX ${luabridge_build_toplevel} - SOURCE_DIR ${luabridge_build_toplevel} - DOWNLOAD_DIR ${luabridge_build_toplevel} - TMP_DIR "${luabridge_build_toplevel}-tmp" - STAMP_DIR "${luabridge_build_toplevel}-stamp" - INSTALL_DIR "${luabridge_build_toplevel}/local" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" - BUILD_BYPRODUCTS "${luabridge_sources}") - -add_library(${luabridge_lib} INTERFACE) -add_dependencies(${luabridge_lib} LUABRIDGE_BUILD_SOURCE) -target_include_directories(${luabridge_lib} INTERFACE ${luabridge_include_dirs}) -target_link_libraries(${luabridge_lib} INTERFACE ${LUA_LIBRARIES}) -if (NOT MSVC) - target_compile_options(${luabridge_lib} INTERFACE - -Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter) -endif() -set(LUABRIDGEBUILD_FOUND TRUE) -set(LUABRIDGE_LIBRARIES ${luabridge_lib}) -set(LUABRIDGE_INCLUDE_DIRS ${luabridge_include_dirs}) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuabridgeBuild - FOUND_VAR LUABRIDGEBUILD_FOUND - REQUIRED_VARS LUABRIDGE_LIBRARIES LUABRIDGE_INCLUDE_DIRS - VERSION_VAR luabridge_version) diff --git a/third/sol2/cmake/Packages/FindLuaBuild.cmake b/third/sol2/cmake/Packages/FindLuaBuild.cmake deleted file mode 100644 index 9ea38a47..00000000 --- a/third/sol2/cmake/Packages/FindLuaBuild.cmake +++ /dev/null @@ -1,120 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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_INCLUDE_DIRS ${LUA_INCLUDE_DIRS} 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 (LuaBuild_FIND_COMPONENTS) - list(GET LuaBuild_FIND_COMPONENTS 0 LUA_VERSION) -endif() -if (LuaBuild_FIND_VERSION) - if (LUA_VERSION) - set(LUA_VERSION "${LUA_VERSION}-${LuaBuild_FIND_VERSION}") - else() - set(LUA_VERSION "${LuaBuild_VERSION}") - endif() -endif() -if (NOT LUA_VERSION) - set(LUA_VERSION 5.4.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_INCLUDE_DIRS - VERSION_VAR LUA_VERSION_STRING) diff --git a/third/sol2/cmake/Packages/FindLuaBuild/LuaJIT.cmake b/third/sol2/cmake/Packages/FindLuaBuild/LuaJIT.cmake deleted file mode 100644 index 0683d818..00000000 --- a/third/sol2/cmake/Packages/FindLuaBuild/LuaJIT.cmake +++ /dev/null @@ -1,441 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# protect from multiple inclusion -if(lua_jit_build_included) - 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) -set(LUA_JIT_2.1_LATEST_VERSION 2.1.0-beta3) -set(LUA_JIT_${LUA_JIT_2.1_LATEST_VERSION}_COMMIT 80aaaeee99d7f7b06c9e75ed3a457c49d86fc4db) - -# MD5 hashes taken off of LuaJIT's website -# must be updated whenever a new version appears -set(LUA_JIT_MD5_2.1.0-beta3.tar.gz eae40bc29d06ee5e3078f9444fcea39b) -set(LUA_JIT_MD5_2.1.0-beta3.zip 58d0480e1af0811e7ecee45498d62e2d) -set(LUA_JIT_MD5_2.1.0-beta2.tar.gz fa14598d0d775a7ffefb138a606e0d7b) -set(LUA_JIT_MD5_2.1.0-beta2.zip b5d943c0174ca217736e2ddc2d9721c3) -set(LUA_JIT_MD5_2.1.0-beta1.tar.gz 5a5bf71666e77cf6e7a1ae851127b834) -set(LUA_JIT_MD5_2.1.0-beta1.zip 4b5c2c9aef0e7c0b622b09e7c84d566b) -set(LUA_JIT_MD5_2.0.5.tar.gz 48353202cbcacab84ee41a5a70ea0a2c) -set(LUA_JIT_MD5_2.0.5.zip f7cf52a049d74aee4e624bdc1160b80d) -set(LUA_JIT_MD5_2.0.4.tar.gz dd9c38307f2223a504cbfb96e477eca0) -set(LUA_JIT_MD5_2.0.4.zip ed1f0caf3d390171f423f6f1b5c57aac) -set(LUA_JIT_MD5_2.0.3.tar.gz f14e9104be513913810cd59c8c658dc0) -set(LUA_JIT_MD5_2.0.3.zip 6c0f6958d5e1f67734fb1ff514ec4c84) -set(LUA_JIT_MD5_2.0.2.tar.gz 112dfb82548b03377fbefbba2e0e3a5b) -set(LUA_JIT_MD5_2.0.2.zip a57c7d1b8eaf46559303dcfd56404045) -set(LUA_JIT_MD5_2.0.1.tar.gz 85e406e8829602988eb1233a82e29f1f) -set(LUA_JIT_MD5_2.0.1.zip cf4aee0e40b220054ee3cffbe0cd6ed5) -set(LUA_JIT_MD5_2.0.0.tar.gz 97a2b87cc0490784f54b64cfb3b8f5ad) -set(LUA_JIT_MD5_2.0.0.zip 467f4f531f7e08ee252f5030ecada7ed) -set(LUA_JIT_MD5_2.0.0-beta11.tar.gz 824aa2684a11e3cc3abe87350a7b6139) -set(LUA_JIT_MD5_2.0.0-beta11.zip 8629401437048e477c94bd791b0a823a) -set(LUA_JIT_MD5_2.0.0-beta10.tar.gz ed66689b96f7ad7bfeffe0b4ff2d63d4) -set(LUA_JIT_MD5_2.0.0-beta10.zip f6bbd472726b761b29438c4a06b5ab3c) -set(LUA_JIT_MD5_2.0.0-beta9.tar.gz e7e03e67e2550817358bc28b44270c6d) -set(LUA_JIT_MD5_2.0.0-beta9.zip 3f9ca0309f26e789c6c3246c83696f84) -set(LUA_JIT_MD5_2.0.0-beta8.tar.gz f0748a73ae268d49b1d01f56c4fe3e61) -set(LUA_JIT_MD5_2.0.0-beta8.zip fb096a90c9e799c8922f32095ef3d93c) -set(LUA_JIT_MD5_2.0.0-beta7.tar.gz b845dec15dd9eba2fd17d865601a52e5) -set(LUA_JIT_MD5_2.0.0-beta7.zip e10fc2b19de52d8770cdf24f1791dd77) -set(LUA_JIT_MD5_2.0.0-beta6.tar.gz bfcbe2a11162cfa84d5a1693b442c8bf) -set(LUA_JIT_MD5_2.0.0-beta6.zip f64945c5ecaf3ea71a829fdbb5cb196c) -set(LUA_JIT_MD5_2.0.0-beta5.tar.gz 7e0dfa03a140148149a1021d4ffd5c57) -set(LUA_JIT_MD5_2.0.0-beta5.zip be8087fcb576c30ffbb6368ebc284498) -set(LUA_JIT_MD5_2.0.0-beta4.tar.gz 5c5a9305b3e06765e1dae138e1a95c3a) -set(LUA_JIT_MD5_2.0.0-beta4.zip d0b241be6207fa7d97b6afc41368e05f) -set(LUA_JIT_MD5_2.0.0-beta3.tar.gz 313b6f164e93e1bbac7bf87abb58d4a1) -set(LUA_JIT_MD5_2.0.0-beta3.zip bea9c7bcd5084f98830e31956f276ff6) -set(LUA_JIT_MD5_2.0.0-beta2.tar.gz 2ebcc38fa1d9756dc2e341f191701120) -set(LUA_JIT_MD5_2.0.0-beta2.zip 94086f99f647d46a8360adeb11851d66) -set(LUA_JIT_MD5_2.0.0-beta1.tar.gz 9ed7646d03580a1cec4abeb74ca44843) -set(LUA_JIT_MD5_2.0.0-beta1.zip 19d5bac616fa739343c7158d9d99a3f3) -set(LUA_JIT_MD5_1.1.8.tar.gz ad0e319483fa235e3979537a748631e9) -set(LUA_JIT_MD5_1.1.8.zip 92870c80f504c34c9b7547cd6c5562d0) -set(LUA_JIT_MD5_1.1.7.tar.gz 3aed0795f7c8725d3613269cd56f8e5a) -set(LUA_JIT_MD5_1.1.7.zip 40a8dbc214306bb4b9849fcf026c4ee0) -set(LUA_JIT_MD5_1.1.6.tar.gz 1a1320e09d0cd5b793014556fb7d64c9) -set(LUA_JIT_MD5_1.1.6.zip 350d7b9230637056fbd6158b95e8fa11) -set(LUA_JIT_MD5_1.1.5.tar.gz b99d244ba4fc1979946ae1025368fc5c) -set(LUA_JIT_MD5_1.1.5.zip d3ffbae3bfcd5914b02dc00b1118a59d) -set(LUA_JIT_MD5_1.1.4.tar.gz 9fe29cfb8126bc9c4302701c06965f1c) -set(LUA_JIT_MD5_1.1.4.zip 30d318e3287000ecf4c93b29e8783183) -set(LUA_JIT_MD5_1.1.3.tar.gz f5db1a147ed3d34677ad1ef310c56da7) -set(LUA_JIT_MD5_1.1.3.zip 5949e7bce9d97c37c282e1cbe85aa378) -set(LUA_JIT_MD5_1.1.2.tar.gz 4ae25ce7e3f301d1fcf0b713016edab0) -set(LUA_JIT_MD5_1.1.0.tar.gz 16d880a98a1ff6608ac1039c802233db) -set(LUA_JIT_MD5_1.0.3.tar.gz d0a63d5394cca549889bd820a05b32d2) - -# Clean up some variables -string(TOLOWER ${LUA_VERSION} LUA_JIT_NORMALIZED_LUA_VERSION) -if (LUA_JIT_NORMALIZED_LUA_VERSION MATCHES "([0-9]+\\.[0-9]+\\.[0-9]+(-[A-Za-z0-9_-]+)?)") - # 3-digit with optional beta1/beta2/beta3 (or whatever): probably okay? - set(LUA_JIT_VERSION ${CMAKE_MATCH_1}) -elseif (LUA_JIT_NORMALIZED_LUA_VERSION MATCHES "([0-9]+\\.[0-9]+)") - # extend version number with prefix - if (${CMAKE_MATCH_1} EQUAL 2) - if (${CMAKE_MATCH_2} EQUAL 0) - set(LUA_JIT_VERSION ${LUA_JIT_2.0_LATEST_VERSION}) - elseif (${CMAKE_MATCH_2} EQUAL 1) - set(LUA_JIT_VERSION ${LUA_JIT_2.1_LATEST_VERSION}) - endif() - endif() - if (NOT LUA_JIT_VERSION) - # Just pick a default version and roll with it - set(LUA_JIT_VERSION ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.0) - endif() -elseif (LUA_JIT_NORMALIZED_LUA_VERSION MATCHES "latest") - set(LUA_JIT_VERSION ${LUA_JIT_2.1_LATEST_VERSION}) -else() - MESSAGE(FATAL "Cannot deduce LuaJIT version from ${LUA_VERSION}") -endif() - -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 -# set(LUA_JIT_SHA1 ${LUA_JIT_SHA1_${LUA_JIT_VERSION}}) -if (WIN32) - set(LUA_JIT_MD5 ${LUA_JIT_MD5_${LUA_JIT_VERSION}.zip}) - set(LUA_JIT_DOWNLOAD_URI http://luajit.org/download/LuaJIT-${LUA_JIT_VERSION}.zip) -else() - set(LUA_JIT_MD5 ${LUA_JIT_MD5_${LUA_JIT_VERSION}.tar.gz}) - set(LUA_JIT_DOWNLOAD_URI http://luajit.org/download/LuaJIT-${LUA_JIT_VERSION}.tar.gz) -endif() - -if (LUA_JIT_MD5) - set(LUA_JIT_DOWNLOAD_MD5_COMMAND URL_MD5 ${LUA_JIT_MD5}) -else () - set(LUA_JIT_DOWNLOAD_MD5_COMMAND "") -endif() -if (LUA_JIT_SHA1) - set(LUA_JIT_DOWNLOAD_SHA1_COMMAND URL_HASH SHA1=${LUA_JIT_SHA1}) -else () - set(LUA_JIT_DOWNLOAD_SHA1_COMMAND "") -endif() - -set(LUA_JIT_SOURCE_DIR "${LUA_BUILD_TOPLEVEL}/src") -set(LUA_JIT_INSTALL_DIR "${LUA_BUILD_TOPLEVEL}/install") -set(LUA_JIT_INCLUDE_DIRS "${LUA_JIT_SOURCE_DIR}") -file(MAKE_DIRECTORY ${LUA_JIT_SOURCE_DIR}) -file(MAKE_DIRECTORY ${LUA_JIT_INSTALL_DIR}) - -set(LUA_JIT_LIB_FILENAME "${CMAKE_STATIC_LIBRARY_PREFIX}${LUA_BUILD_LIBNAME}${CMAKE_STATIC_LIBRARY_SUFFIX}") -set(LUA_JIT_IMP_LIB_FILENAME "${CMAKE_IMPORT_LIBRARY_PREFIX}${LUA_BUILD_LIBNAME}${CMAKE_IMPORT_LIBRARY_SUFFIX}") -set(LUA_JIT_LIB_EXP_FILENAME "${LUA_BUILD_LIBNAME}.exp") -set(LUA_JIT_DLL_FILENAME "${CMAKE_SHARED_LIBRARY_PREFIX}${LUA_BUILD_LIBNAME}${CMAKE_SHARED_LIBRARY_SUFFIX}") -set(LUA_JIT_EXE_FILENAME "${LUA_BUILD_LIBNAME}${CMAKE_EXECUTABLE_SUFFIX}") - -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) - # Visual C++ is predicated off running msvcbuild.bat - # which requires a Visual Studio Command Prompt - # make sure to find the right one - find_file(VCVARS_ALL_BAT NAMES vcvarsall.bat - HINTS "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build" - "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary" - "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC" - "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Auxiliary/Build" - "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Auxiliary" - "C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC" - "C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Auxiliary/Build" - "C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Auxiliary" - "C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC" - - "C:/Program Files/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build" - "C:/Program Files/Microsoft Visual Studio/2017/Community/VC/Auxiliary" - "C:/Program Files/Microsoft Visual Studio/2017/Community/VC" - "C:/Program Files/Microsoft Visual Studio/2017/Professional/VC/Auxiliary/Build" - "C:/Program Files/Microsoft Visual Studio/2017/Professional/VC/Auxiliary" - "C:/Program Files/Microsoft Visual Studio/2017/Professional/VC" - "C:/Program Files/Microsoft Visual Studio/2017/Enterprise/VC/Auxiliary/Build" - "C:/Program Files/Microsoft Visual Studio/2017/Enterprise/VC/Auxiliary" - "C:/Program Files/Microsoft Visual Studio/2017/Enterprise/VC" - - "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build" - "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary" - "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC" - "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Auxiliary/Build" - "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Auxiliary" - "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC" - "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build" - "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary" - "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC" - - "C:/Program Files/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build" - "C:/Program Files/Microsoft Visual Studio/2019/Community/VC/Auxiliary" - "C:/Program Files/Microsoft Visual Studio/2019/Community/VC" - "C:/Program Files/Microsoft Visual Studio/2019/Professional/VC/Auxiliary/Build" - "C:/Program Files/Microsoft Visual Studio/2019/Professional/VC/Auxiliary" - "C:/Program Files/Microsoft Visual Studio/2019/Professional/VC" - "C:/Program Files/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build" - "C:/Program Files/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary" - "C:/Program Files/Microsoft Visual Studio/2019/Enterprise/VC") - if (VCVARS_ALL_BAT MATCHES "VCVARS_ALL_BAT-NOTFOUND") - MESSAGE(FATAL_ERROR "Cannot find 'vcvarsall.bat' file or similar needed to build LuaJIT ${LUA_VERSION} on Windows") - endif() - if (CMAKE_SIZEOF_VOID_P LESS_EQUAL 4) - set(LUA_JIT_MAKE_COMMAND "${VCVARS_ALL_BAT}" x86) - else() - set(LUA_JIT_MAKE_COMMAND "${VCVARS_ALL_BAT}" x64) - endif() - set(LUA_JIT_MAKE_COMMAND ${LUA_JIT_MAKE_COMMAND} && cd src && msvcbuild.bat) - if (CMAKE_BUILD_TYPE MATCHES "Debug") - set(LUA_JIT_MAKE_COMMAND ${LUA_JIT_MAKE_COMMAND} debug) - endif() - if (NOT BUILD_LUA_AS_DLL) - set(LUA_JIT_MAKE_COMMAND ${LUA_JIT_MAKE_COMMAND} static) - endif() - - set(LUA_JIT_PREBUILT_LIB "lua51.lib") - set(LUA_JIT_PREBUILT_IMP_LIB "lua51.lib") - set(LUA_JIT_PREBUILT_DLL "lua51.dll") - set(LUA_JIT_PREBUILT_EXP "lua51.exp") - set(LUA_JIT_PREBUILT_EXE "luajit.exe") -else () - # get the make command we need for this system - find_program(MAKE_PROGRAM NAMES make mingw32-make mingw64-make) - if (MAKE_PROGRAM MATCHES "MAKE_PROGRAM-NOTFOUND") - MESSAGE(FATAL_ERROR "Cannot find 'make' program or similar needed to build LuaJIT ${LUA_VERSION} (perhaps place it in the PATH environment variable if it is not already?)") - endif() - - # we can simply reuse the makefile here - # so define it as an external project and then just have the proper - # build/install/test commands - # make sure to apply -pagezero_size 10000 -image_base 100000000 (done later for XCode Targets) - set(LUA_JIT_MAKE_BUILD_MODIFICATIONS "LUAJIT_T=${LUA_JIT_EXE_FILENAME}") - list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "LUAJIT_A=${LUA_JIT_LIB_FILENAME}") - set(LUA_JIT_MAKE_CFLAGS_MODIFICATIONS "") - set(LUA_JIT_MAKE_HOST_CFLAGS_MODIFICATIONS "") - set(LUA_JIT_MAKE_TARGET_CFLAGS_MODIFICATIONS "-fPIC") - if (BUILD_LUA_AS_DLL) - list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "LUAJIT_SO=${LUA_JIT_DLL_FILENAME}" "TARGET_SONAME=${LUA_JIT_DLL_FILENAME}" "TARGET_DYLIBNAME=${LUA_JIT_DLL_FILENAME}" "TARGET_DLLNAME=${LUA_JIT_DLL_FILENAME}") - list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "BUILDMODE=dynamic") - else() - list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "BUILDMODE=static") - endif() - if (IS_X86) - list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "CC=${CMAKE_C_COMPILER} -m32") - list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "LDFLAGS=-m32") - #set(LUA_JIT_MAKE_CFLAGS_MODIFICATIONS "${LUA_JIT_MAKE_CFLAGS_MODIFICATIONS} -m32") - #set(LUA_JIT_MAKE_HOST_CFLAGS_MODIFICATIONS "${LUA_JIT_MAKE_HOST_CFLAGS_MODIFICATIONS} -m32") - #set(LUA_JIT_MAKE_TARGET_CFLAGS_MODIFICATIONS "${LUA_JIT_MAKE_TARGET_CFLAGS_MODIFICATIONS} -m32") - endif() - - set(LUA_JIT_PREBUILT_DLL ${LUA_JIT_DLL_FILENAME}) - set(LUA_JIT_PREBUILT_LIB ${LUA_JIT_LIB_FILENAME}) - set(LUA_JIT_PREBUILT_IMP_LIB ${LUA_JIT_IMP_LIB_FILENAME}) - set(LUA_JIT_PREBUILT_EXE ${LUA_JIT_EXE_FILENAME}) - set(LUA_JIT_PREBUILT_EXP ${LUA_JIT_LIB_EXP_FILENAME}) - - if (WIN32) - list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "HOST_SYS=Windows" "TARGET_SYS=Windows" "TARGET_AR=ar rcus") - endif() - list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "CFLAGS=${LUA_JIT_MAKE_CFLAGS_MODIFICATIONS}") - list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "TARGET_CFLAGS=${LUA_JIT_MAKE_TARGET_CFLAGS_MODIFICATIONS}") - list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "HOST_CFLAGS=${LUA_JIT_MAKE_HOST_CFLAGS_MODIFICATIONS}") - set(LUA_JIT_MAKE_COMMAND "${MAKE_PROGRAM}" ${LUA_JIT_MAKE_BUILD_MODIFICATIONS}) -endif() - -set(LUA_JIT_BUILD_COMMAND BUILD_COMMAND ${LUA_JIT_MAKE_COMMAND}) - -set(lualib luajit_lib_${LUA_JIT_VERSION}) -set(luainterpreter luajit_${LUA_JIT_VERSION}) - -file(TO_CMAKE_PATH "${LUA_JIT_SOURCE_DIR}/${LUA_JIT_PREBUILT_LIB}" LUA_JIT_SOURCE_LUA_LIB) -file(TO_CMAKE_PATH "${LUA_JIT_SOURCE_DIR}/${LUA_JIT_PREBUILT_IMP_LIB}" LUA_JIT_SOURCE_LUA_IMP_LIB) -file(TO_CMAKE_PATH "${LUA_JIT_SOURCE_DIR}/${LUA_JIT_PREBUILT_EXE}" LUA_JIT_SOURCE_LUA_INTERPRETER) -file(TO_CMAKE_PATH "${LUA_JIT_SOURCE_DIR}/${LUA_JIT_PREBUILT_DLL}" LUA_JIT_SOURCE_LUA_DLL) -file(TO_CMAKE_PATH "${LUA_JIT_SOURCE_DIR}/${LUA_JIT_PREBUILT_EXP}" LUA_JIT_SOURCE_LUA_LIB_EXP) - -file(TO_CMAKE_PATH "${LUA_JIT_DLL_FILE}" LUA_JIT_DESTINATION_LUA_DLL) -file(TO_CMAKE_PATH "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${LUA_JIT_LIB_EXP_FILENAME}" LUA_JIT_DESTINATION_LUA_LIB_EXP) -file(TO_CMAKE_PATH "${LUA_JIT_IMP_LIB_FILE}" LUA_JIT_DESTINATION_LUA_IMP_LIB) -file(TO_CMAKE_PATH "${LUA_JIT_LIB_FILE}" LUA_JIT_DESTINATION_LUA_LIB) -file(TO_CMAKE_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) - string(COMPARE EQUAL ${LUA_JIT_VERSION} ${LUA_JIT_2.1_LATEST_VERSION} lua_jit_same_version_21) - if (lua_jit_same_version_20 OR lua_jit_same_version_21) - #set (LUA_JIT_GIT_COMMIT ${LUA_JIT_${LUA_JIT_VERSION}_COMMIT}) - #set(LUA_JIT_GIT_TAG GIT_TAG ${LUA_JIT_GIT_COMMIT}) - endif() -elseif(LUA_JIT_NORMALIZED_LUA_VERSION MATCHES "latest") - set(LUA_JIT_PULL_LATEST TRUE) -endif() - -set(LUA_JIT_BYPRODUCTS "${LUA_JIT_SOURCE_LUA_DLL}" "${LUA_JIT_SOURCE_LUA_INTERPRETER}") -set(LUA_JIT_INSTALL_BYPRODUCTS "${LUA_JIT_DESTINATION_LUA_DLL}" "${LUA_JIT_DESTINATION_LUA_INTERPRETER}") - -if (BUILD_LUA_AS_DLL AND MSVC) - set(LUA_JIT_BYPRODUCTS ${LUA_JIT_BYPRODUCTS} "${LUA_JIT_SOURCE_LUA_LIB_EXP}") - set(LUA_JIT_INSTALL_BYPRODUCTS ${LUA_JIT_INSTALL_BYPRODUCTS} "${LUA_JIT_DESTINATION_LUA_LIB_EXP}") -endif() - -if (CMAKE_IMPORT_LIBRARY_SUFFIX AND BUILD_LUA_AS_DLL) - set(LUA_JIT_BYPRODUCTS ${LUA_JIT_BYPRODUCTS} "${LUA_JIT_SOURCE_LUA_IMP_LIB}") - set(LUA_JIT_INSTALL_BYPRODUCTS "${LUA_JIT_INSTALL_BYPRODUCTS}" "${LUA_JIT_DESTINATION_LUA_IMP_LIB}") -else() - set(LUA_JIT_BYPRODUCTS ${LUA_JIT_BYPRODUCTS} "${LUA_JIT_SOURCE_LUA_LIB}") - set(LUA_JIT_INSTALL_BYPRODUCTS ${LUA_JIT_INSTALL_BYPRODUCTS} "${LUA_JIT_DESTINATION_LUA_LIB}") -endif() - -# # Post-Build moving steps for necessary items -# Add post-step to move library afterwards -set(LUA_JIT_POSTBUILD_COMMENTS "Executable - Moving \"${LUA_JIT_SOURCE_LUA_INTERPRETER}\" to \"${LUA_JIT_DESTINATION_LUA_INTERPRETER}\"...") -set(LUA_JIT_POSTBUILD_COMMANDS COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${LUA_JIT_SOURCE_LUA_INTERPRETER}" "${LUA_JIT_DESTINATION_LUA_INTERPRETER}") -if (BUILD_LUA_AS_DLL) - if (MSVC) - set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} Import Library - Moving \"${LUA_JIT_SOURCE_LUA_IMP_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_IMP_LIB}\"...") - set(LUA_JIT_POSTBUILD_COMMANDS ${LUA_JIT_POSTBUILD_COMMANDS} COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${LUA_JIT_SOURCE_LUA_IMP_LIB}" "${LUA_JIT_DESTINATION_LUA_IMP_LIB}") - - set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} Library - Moving \"${LUA_JIT_SOURCE_LUA_LIB_EXP}\" to \"${LUA_JIT_DESTINATION_LUA_LIB_EXP}\"...") - set(LUA_JIT_POSTBUILD_COMMANDS ${LUA_JIT_POSTBUILD_COMMANDS} && "${CMAKE_COMMAND}" -E copy_if_different "${LUA_JIT_SOURCE_LUA_LIB_EXP}" "${LUA_JIT_DESTINATION_LUA_LIB_EXP}") - endif() - set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} Dynamic Library - Moving \"${LUA_JIT_SOURCE_LUA_DLL}\" to \"${LUA_JIT_DESTINATION_LUA_DLL}\"...") - set(LUA_JIT_POSTBUILD_COMMANDS ${LUA_JIT_POSTBUILD_COMMANDS} COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${LUA_JIT_SOURCE_LUA_DLL}" "${LUA_JIT_DESTINATION_LUA_DLL}") -else() - set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS} Library - Moving \"${LUA_JIT_SOURCE_LUA_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_LIB}\"...") - set(LUA_JIT_POSTBUILD_COMMANDS ${LUA_JIT_POSTBUILD_COMMANDS} COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${LUA_JIT_SOURCE_LUA_LIB}" "${LUA_JIT_DESTINATION_LUA_LIB}") -endif() - -if (LUA_LOCAL_DIR) - file(COPY "${LUA_LOCAL_DIR}/" - DESTINATION "${LUA_BUILD_TOPLEVEL}" - FILES_MATCHING REGEX ".*" - ) - add_custom_command(OUTPUT ${LUA_JIT_BYPRODUCTS} - COMMAND ${LUA_JIT_MAKE_COMMAND} - WORKING_DIRECTORY "${LUA_BUILD_TOPLEVEL}" - DEPENDS "${LUA_BUILD_TOPLEVEL}/Makefile" "${LUA_BUILD_TOPLEVEL}/src/msvcbuild.bat" - COMMENT "Building LuaJIT ${LUA_JIT_VERSION}..." - ) - add_custom_target(LUA_JIT-move - ${LUA_JIT_POSTBUILD_COMMANDS} - COMMENT ${LUA_JIT_POSTBUILD_COMMENTS} - BYPRODUCTS ${LUA_JIT_INSTALL_BYPRODUCTS} - DEPENDS ${LUA_JIT_BYPRODUCTS} - ) -elseif (LUA_JIT_GIT_COMMIT OR LUA_JIT_PULL_LATEST) - if (LUA_JIT_PULL_LATEST) - MESSAGE(STATUS "Latest LuaJIT has been requested: pulling from git...") - elseif (LUA_JIT_GIT_COMMIT) - MESSAGE(STATUS "LuaJIT '${LUA_VERSION}' requested has broken static library builds: using git '${LUA_JIT_GIT_COMMIT}'...") - endif() - ExternalProject_Add(LUA_JIT - BUILD_IN_SOURCE TRUE - BUILD_ALWAYS FALSE - 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}" - GIT_REPOSITORY https://github.com/LuaJIT/LuaJIT.git - GIT_REMOTE_NAME origin - ${LUA_JIT_GIT_TAG} - GIT_SHALLOW TRUE - CONFIGURE_COMMAND "" - ${LUA_JIT_BUILD_COMMAND} - INSTALL_COMMAND "" - TEST_COMMAND "" - BUILD_BYPRODUCTS ${LUA_JIT_BYPRODUCTS}) -else() - ExternalProject_Add(LUA_JIT - BUILD_IN_SOURCE TRUE - BUILD_ALWAYS TRUE - # LuaJIT does not offer a TLS/SSL port - TLS_VERIFY FALSE - 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_JIT_DOWNLOAD_URI}" - ${LUA_JIT_DOWNLOAD_MD5_COMMAND} - ${LUA_JIT_DOWNLOAD_SHA1_COMMAND} - CONFIGURE_COMMAND "" - ${LUA_JIT_BUILD_COMMAND} - INSTALL_COMMAND "" - TEST_COMMAND "" - BUILD_BYPRODUCTS ${LUA_JIT_BYPRODUCTS}) -endif() - -if (NOT LUA_LOCAL_DIR) - ExternalProject_Add_Step(LUA_JIT move - ALWAYS TRUE - ${LUA_JIT_POSTBUILD_COMMANDS} - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" - COMMENT ${LUA_JIT_POSTBUILD_COMMENTS} - DEPENDEES build - DEPENDS ${LUA_JIT_BYPRODUCTS} - BYPRODUCTS ${LUA_JIT_INSTALL_BYPRODUCTS}) - ExternalProject_Add_StepTargets(LUA_JIT move) -endif() - -# # Lua Library -add_library(${lualib} INTERFACE) -add_dependencies(${lualib} LUA_JIT-move) -target_include_directories(${lualib} - INTERFACE "${LUA_JIT_SOURCE_DIR}") -target_link_libraries(${lualib} - INTERFACE ${CMAKE_DL_LIBS}) -if (BUILD_LUA_AS_DLL) - if (MSVC) - target_link_libraries(${lualib} - INTERFACE "${LUA_JIT_DESTINATION_LUA_LIB}") - else() - target_link_libraries(${lualib} - INTERFACE "${LUA_JIT_DESTINATION_LUA_DLL}") - endif() -else() - target_link_libraries(${lualib} - INTERFACE "${LUA_JIT_DESTINATION_LUA_LIB}") -endif() - -if (XCODE) - target_compile_options(${lualib} - INTERFACE -pagezero_size 10000 -image_base 100000000) -endif () - -# # set externally-visible target indicator -set(LUA_LIBRARIES ${lualib}) -set(LUA_INTERPRETER "") -set(LUA_INCLUDE_DIRS "${LUA_JIT_INCLUDE_DIRS}") diff --git a/third/sol2/cmake/Packages/FindLuaBuild/LuaVanilla.cmake b/third/sol2/cmake/Packages/FindLuaBuild/LuaVanilla.cmake deleted file mode 100644 index b95e5a67..00000000 --- a/third/sol2/cmake/Packages/FindLuaBuild/LuaVanilla.cmake +++ /dev/null @@ -1,356 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# 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) -# import other modules -include(Common/Core) - -# 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) -set(LUA_VANILLA_5.3_LATEST_VERSION 5.3.6) -set(LUA_VANILLA_5.4_LATEST_VERSION 5.4.4) - -# Clean up some variables -if (LUA_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$") - # probably okay! - set(LUA_VANILLA_VERSION ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}) -elseif (LUA_VERSION MATCHES "([0-9]+)\\.([0-9]+)") - # extend version number with prefix - if (${CMAKE_MATCH_1} EQUAL 5) - if (${CMAKE_MATCH_2} EQUAL 1) - set(LUA_VANILLA_VERSION ${LUA_VANILLA_5.1_LATEST_VERSION}) - elseif (${CMAKE_MATCH_2} EQUAL 2) - set(LUA_VANILLA_VERSION ${LUA_VANILLA_5.2_LATEST_VERSION}) - elseif (${CMAKE_MATCH_2} EQUAL 3) - set(LUA_VANILLA_VERSION ${LUA_VANILLA_5.3_LATEST_VERSION}) - elseif (${CMAKE_MATCH_2} EQUAL 4) - set(LUA_VANILLA_VERSION ${LUA_VANILLA_5.4_LATEST_VERSION}) - else() - # default to whatever the first two - # numbers happen to be, plus build 0 - set(LUA_VANILLA_VERSION ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.0) - endif() - endif() - if(NOT LUA_VANILLA_VERSION) - # default to whatever the first two - # numbers happen to be, plus build 0 - set(LUA_VANILLA_VERSION ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.0) - endif() -else() - message(FATAL_ERROR "Cannot deduce the proper Lua version from ${LUA_VERSION}") -endif() - -if (BUILD_LUA_AS_CXX) - set(LUA_VANILLA_LANGUAGE CXX) - set(LUA_VANILLA_LANGUAGE_STANDARD 98) -else() - set(LUA_VANILLA_LANGUAGE C) - set(LUA_VANILLA_LANGUAGE_STANDARD 99) -endif() - -FIND_PACKAGE_MESSAGE(LUABUILD - "Selecting PUC-RIO Lua ${LUA_VANILLA_VERSION} from '${LUA_VERSION}' and building a ${LUA_BUILD_LIBRARY_TYPE} library with ${LUA_VANILLA_LANGUAGE} linkage..." - "[${LUA_VANILLA_VERSION}][${LUA_VERSION}][${LUA_BUILD_LIBRARY_TYPE}][${LUA_VANILLA_LANGUAGE}]") - -# # # Makefile and self-build configurations - -# # Potential compiler variables -if (MSVC) - if (BUILD_LUA_AS_DLL) - set(LUA_VANILLA_DLL_DEFINE LUA_BUILD_AS_DLL) - else() - set(LUA_VANILLA_DLL_DEFINE "") - endif() -else() - set(LUA_VANILLA_LUALIB_COMPILER_OPTIONS "") - set(LUA_VANILLA_DLL_DEFINE "") -endif() - -# # Source files for natural build, if we have to go that far -# retrieve source files -set(LUA_VANILLA_DOWNLOAD_URL https://www.lua.org/ftp/lua-${LUA_VANILLA_VERSION}.tar.gz) -if (LUA_VANILLA_VERSION MATCHES "^5\\.1") - set(LUA_VANILLA_LIB_SOURCES lapi.c lcode.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 ldblib.c liolib.c lmathlib.c loslib.c ltablib.c - lstrlib.c loadlib.c linit.c) - set(LUA_VANILLA_LUA_SOURCES lua.c ) -if (LUA_BUILD_LUA_COMPILER) - set(LUA_VANILLA_LUAC_SOURCES luac.c print.c ) -endif() - set(LUA_VANILLA_GENERATE_LUA_HPP true) -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 - lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c) - set(LUA_VANILLA_LUA_SOURCES lua.c ) -if (LUA_BUILD_LUA_COMPILER) - set(LUA_VANILLA_LUAC_SOURCES luac.c ) -endif() - set(LUA_VANILLA_GENERATE_LUA_HPP false) -elseif (LUA_VANILLA_VERSION MATCHES "^5\\.3") - 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 lmathlib.c - loslib.c lstrlib.c ltablib.c lutf8lib.c loadlib.c linit.c) - set(LUA_VANILLA_LUA_SOURCES lua.c ) -if (LUA_BUILD_LUA_COMPILER) - set(LUA_VANILLA_LUAC_SOURCES luac.c ) -endif() - set(LUA_VANILLA_GENERATE_LUA_HPP false) -elseif (LUA_VANILLA_VERSION MATCHES "^5\\.4") - if (LUA_VANILLA_VERSION MATCHES "work" OR LUA_VANILLA_VERSION MATCHES "alpha" OR LUA_VANILLA_VERSION MATCHES "beta") - set(LUA_VANILLA_DOWNLOAD_URL https://www.lua.org/work/lua-${LUA_VANILLA_VERSION}.tar.gz) - endif() - 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 - lparser.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c ltm.c lundump.c - lutf8lib.c lvm.c lzio.c) - set(LUA_VANILLA_LUA_SOURCES lua.c ) -if (LUA_BUILD_LUA_COMPILER) - set(LUA_VANILLA_LUAC_SOURCES luac.c ) -endif() - set(LUA_VANILLA_GENERATE_LUA_HPP false) -else() - MESSAGE(WARNING "Using Lua 5.4.1 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 - lparser.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c ltm.c lundump.c - lutf8lib.c lvm.c lzio.c) - set(LUA_VANILLA_LUA_SOURCES lua.c ) -if (LUA_BUILD_LUA_COMPILER) - set(LUA_VANILLA_LUAC_SOURCES luac.c ) -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) - file(COPY "${LUA_LOCAL_DIR}/src" - DESTINATION "${LUA_BUILD_TOPLEVEL}") - file(COPY "${LUA_LOCAL_DIR}/include" - DESTINATION "${LUA_BUILD_TOPLEVEL}") - 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") -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 - if (LUA_VANILLA_GENERATE_LUA_HPP) - set(LUA_VANILLA_LUA_HPP_CONTENT "// lua.hpp -// Lua header files for 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}") - 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}) -endif() - -# # Target names -set(liblua "liblua-${LUA_VANILLA_VERSION}") -set(luainterpreter "lua-${LUA_VANILLA_VERSION}") -set(luacompiler "luac-${LUA_VANILLA_VERSION}") - -# Lua does not out-of-the-box support building -# a shared library: http://lua-users.org/lists/lua-l/2006-10/msg00098.html -# in this case, we essentially need to -# build Lua for our purposes, which is annoying -# the external project is just a dummy to get and extract the file: -# after that, we define actual targets...! - -# 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}") -set_target_properties(${liblua} - PROPERTIES - LANGUAGE ${LUA_VANILLA_LANGUAGE} - LINKER_LANGUAGE ${LUA_VANILLA_LANGUAGE} - ${LUA_VANILLA_LANGUAGE}_STANDARD ${LUA_VANILLA_LANGUAGE_STANDARD} - ${LUA_VANILLA_LANGUAGE}_EXTENSIONS TRUE - POSITION_INDEPENDENT_CODE TRUE - OUTPUT_NAME ${LUA_BUILD_LIBNAME} - RUNTIME_OUTPUT_NAME ${LUA_BUILD_LIBNAME} - LIBRARY_OUTPUT_NAME ${LUA_BUILD_LIBNAME} - ARCHIVE_OUTPUT_NAME ${LUA_BUILD_LIBNAME}) -set_source_files_properties(${LUA_VANILLA_LIB_SOURCES} - PROPERTIES LANGUAGE ${LUA_VANILLA_LANGUAGE}) -target_include_directories(${liblua} - PUBLIC "${LUA_VANILLA_INCLUDE_DIRS}") -target_compile_definitions(${liblua} - PUBLIC LUA_COMPAT_ALL ${LUA_VANILLA_DLL_DEFINE}) -if (MSVC) - target_compile_options(${liblua} - PRIVATE /W1) -else() - target_compile_options(${liblua} - PRIVATE -w) -endif() -if (WIN32) - #target_compile_definitions(${liblua} - # PRIVATE LUA_USE_WINDOWS) -else() - target_compile_definitions(${liblua} - PRIVATE LUA_USE_LINUX) -endif() -target_compile_options(${liblua} - PRIVATE ${LUA_VANILLA_LUALIB_COMPILER_OPTIONS}) -add_dependencies(${liblua} LUA_VANILLA) -target_link_libraries(${liblua} PRIVATE ${CMAKE_DL_LIBS}) -if (UNIX) - target_link_libraries(${liblua} PRIVATE m) -endif() - -# we don't really need this section... -# Lua Interpreter -if (LUA_BUILD_LUA_INTERPRETER) - add_executable(${luainterpreter} ${LUA_VANILLA_LUA_SOURCES}) - set_target_properties(${luainterpreter} - PROPERTIES - LANGUAGE ${LUA_VANILLA_LANGUAGE} - LINKER_LANGUAGE ${LUA_VANILLA_LANGUAGE} - ${LUA_VANILLA_LANGUAGE}_STANDARD ${LUA_VANILLA_LANGUAGE_STANDARD} - ${LUA_VANILLA_LANGUAGE}_EXTENSIONS TRUE - OUTPUT_NAME lua-${LUA_VANILLA_VERSION}) - set_source_files_properties(${LUA_VANILLA_LUA_SOURCES} - PROPERTIES LANGUAGE ${LUA_VANILLA_LANGUAGE}) - target_include_directories(${luainterpreter} - PRIVATE "${LUA_VANILLA_INCLUDE_DIRS}") - target_compile_definitions(${luainterpreter} - PUBLIC LUA_COMPAT_ALL ${LUA_VANILLA_DLL_DEFINE} - PRIVATE LUA_COMPAT_ALL ${LUA_VANILLA_DLL_DEFINE}) - if (MSVC) - target_compile_options(${luainterpreter} - PRIVATE /W1) - else() - target_compile_options(${luainterpreter} - PRIVATE -w) - endif() - if (WIN32) - #target_compile_definitions(${luainterpreter} - # PRIVATE LUA_USE_WINDOWS) - else() - target_compile_definitions(${luainterpreter} - PRIVATE LUA_USE_LINUX) - endif() - target_link_libraries(${luainterpreter} PRIVATE ${liblua} ${CMAKE_DL_LIBS}) - if (UNIX) - target_link_libraries(${luainterpreter} PRIVATE m readline) - endif() -endif() - -# LuaC Compiler -if (LUA_BUILD_LUA_COMPILER) - add_executable(${luainterpreter} ${LUA_VANILLA_LUA_SOURCES}) - set_target_properties(${luacompiler} - PROPERTIES - LANGUAGE ${LUA_VANILLA_LANGUAGE} - LINKER_LANGUAGE ${LUA_VANILLA_LANGUAGE} - OUTPUT_NAME luac-${LUA_VANILLA_VERSION}) - set_source_files_properties(${LUA_VANILLA_LIB_SOURCES} - PROPERTIES LANGUAGE ${LUA_VANILLA_LANGUAGE}) - target_include_directories(${luacompiler} - PRIVATE "${LUA_VANILLA_INCLUDE_DIRS}") - target_compile_definitions(${luacompiler} - PUBLIC LUA_COMPAT_ALL ${LUA_VANILLA_DLL_DEFINE} - PRIVATE LUA_COMPAT_ALL ${LUA_VANILLA_DLL_DEFINE}) - if (MSVC) - target_compile_options(${luacompiler} - PRIVATE /W1) - else() - target_compile_options(${luacompiler} - PRIVATE -w) - endif() - if (WIN32) - #target_compile_definitions(${luacompiler} - # PRIVATE LUA_USE_WINDOWS) - else() - target_compile_definitions(${luacompiler} - PRIVATE LUA_USE_LINUX) - endif() - target_link_libraries(${luacompiler} PRIVATE ${liblua} ${CMAKE_DL_LIBS}) - if (UNIX) - # TODO: make readline optional? - target_link_libraries(${luacompiler} PRIVATE m readline) - endif() -endif() - -# set externally-visible target indicator -set(LUA_LIBRARIES ${liblua}) -set(LUA_INTERPRETER ${luainterpreter}) -if (LUA_BUILD_LUA_COMPILER) - set(LUA_COMPILER ${luacompiler}) -endif() -set(LUA_INCLUDE_DIRS "${LUA_VANILLA_SOURCE_DIR}") diff --git a/third/sol2/cmake/Packages/FindLuwraBuild.cmake b/third/sol2/cmake/Packages/FindLuwraBuild.cmake deleted file mode 100644 index fecc3385..00000000 --- a/third/sol2/cmake/Packages/FindLuwraBuild.cmake +++ /dev/null @@ -1,75 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -include(ExternalProject) -include(FindPackageHandleStandardArgs) -include(Common/Core) - -# # Base variables -set(luwra_version 0.5.0) -set(luwra_lib luwra_lib_${luwra_version}) - -# # Useful locations -set(luwra_build_toplevel "${CMAKE_BINARY_DIR}/vendor/luwra_${luwra_version}") -set(luwra_include_dirs "${luwra_build_toplevel}/lib") - -# # luwra library sources -set(luwra_sources luwra.hpp) -prepend(luwra_sources "${luwra_build_toplevel}/lib/" ${luwra_sources}) - -# # External project to get sources -ExternalProject_Add(LUWRA_BUILD_SOURCE - BUILD_IN_SOURCE TRUE - BUILD_ALWAYS FALSE - # # Use Git to get what we need - GIT_SHALLOW TRUE - #GIT_TAG e513907fc8c2d59ebd91cd5992eddf54f7e23e21 - GIT_REPOSITORY https://github.com/vapourismo/luwra.git - PREFIX ${luwra_build_toplevel} - SOURCE_DIR ${luwra_build_toplevel} - DOWNLOAD_DIR ${luwra_build_toplevel} - TMP_DIR "${luwra_build_toplevel}-tmp" - STAMP_DIR "${luwra_build_toplevel}-stamp" - INSTALL_DIR "${luwra_build_toplevel}/local" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" - BUILD_BYPRODUCTS "${luwra_sources}") - -add_library(${luwra_lib} INTERFACE) -add_dependencies(${luwra_lib} LUWRA_BUILD_SOURCE) -target_include_directories(${luwra_lib} INTERFACE ${luwra_include_dirs}) -target_link_libraries(${luwra_lib} INTERFACE ${LUA_LIBRARIES}) -if (NOT MSVC) - target_compile_options(${luwra_lib} INTERFACE - -Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter) -endif() - -set(LUWRABUILD_FOUND TRUE) -set(LUWRA_LIBRARIES ${luwra_lib}) -set(LUWRA_INCLUDE_DIRS ${luwra_include_dirs}) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuwraBuild - FOUND_VAR LUWRABUILD_FOUND - REQUIRED_VARS LUWRA_LIBRARIES LUWRA_INCLUDE_DIRS - VERSION_VAR luwra_version) diff --git a/third/sol2/cmake/Packages/FindSphinx.cmake b/third/sol2/cmake/Packages/FindSphinx.cmake deleted file mode 100644 index 536d0ec6..00000000 --- a/third/sol2/cmake/Packages/FindSphinx.cmake +++ /dev/null @@ -1,68 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -include(FindPackageHandleStandardArgs) -include(FeatureSummary) - -find_program(Sphinx_Build_EXECUTABLE NAMES sphinx-build DOC "Path to sphinx-build executable") - -if (Sphinx_Build_EXECUTABLE) - set(Sphinx_Build_FOUND YES) -endif() - -if (Sphinx_Build_FOUND) - execute_process( - COMMAND ${Sphinx_Build_EXECUTABLE} --version - OUTPUT_VARIABLE Sphinx_Build_VERSION_OUTPUT - OUTPUT_STRIP_TRAILING_WHITESPACE - ENCODING UTF-8) - if (Sphinx_Build_VERSION_OUTPUT) - string(REGEX - MATCH "[^0-9]*([0-9]+)[.]([0-9]+)?[.]?([0-9]+)?[.]?([0-9]+)?.*" - Sphinx_Build_VERSION_CHECK ${Sphinx_Build_VERSION_OUTPUT}) - endif() - if (Sphinx_Build_VERSION_CHECK) - string(JOIN "." Sphinx_Build_VERSION - ${CMAKE_MATCH_1} - ${CMAKE_MATCH_2} - ${CMAKE_MATCH_3} - ${CMAKE_MATCH_4}) - set(Sphinx_Build_VERSION "${Sphinx_Build_VERSION}" CACHE STRING "sphinx-build version" FORCE) - endif() -endif() - -find_package_handle_standard_args(Sphinx - REQUIRED_VARS Sphinx_Build_EXECUTABLE - VERSION_VAR Sphinx_Build_VERSION - HANDLE_COMPONENTS) - -set_package_properties(Sphinx - PROPERTIES - DESCRIPTION "Sphinx Documentation Generator" - URL "https://sphinx-doc.org") - -if (Sphinx_Build_FOUND AND NOT TARGET Sphinx::Build) - add_executable(Sphinx::Build IMPORTED) - set_property(TARGET Sphinx::Build PROPERTY IMPORTED_LOCATION ${Sphinx_Build_EXECUTABLE}) - set_property(TARGET Sphinx::Build PROPERTY VERSION ${Sphinx_Build_VERSION}) - mark_as_advanced(Sphinx_Build_EXECUTABLE Sphinx_Build_VERSION) -endif() diff --git a/third/sol2/cmake/Packages/FindToLuappBuild.cmake b/third/sol2/cmake/Packages/FindToLuappBuild.cmake deleted file mode 100644 index 0bfcd9b1..00000000 --- a/third/sol2/cmake/Packages/FindToLuappBuild.cmake +++ /dev/null @@ -1,92 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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(ExternalProject) -include(FindPackageHandleStandardArgs) -include(Common/Core) - -# # Base variables -set(toluapp_version 1.0.93) - -# # Useful locations -set(toluapp_build_toplevel "${CMAKE_BINARY_DIR}/vendor/toluapp_${toluapp_version}") -set(toluapp_include_dirs "${toluapp_build_toplevel}/include") - -# # ToLua library sources -set(toluapp_sources tolua_event.c tolua_event.h tolua_is.c tolua_map.c tolua_push.c tolua_to.c tolua_compat.h tolua_compat.c) -prepend(toluapp_sources "${toluapp_build_toplevel}/src/lib/" ${toluapp_sources}) -list(APPEND toluapp_sources "${toluapp_build_toplevel}/include/tolua++.h") - -# # External project to get sources -ExternalProject_Add(TOLUAPP_BUILD_SOURCE - BUILD_IN_SOURCE TRUE - BUILD_ALWAYS FALSE - # # Use Git to get what we need - #GIT_SUBMODULES "" - GIT_SHALLOW TRUE - GIT_REPOSITORY https://github.com/ThePhD/toluapp - PREFIX ${toluapp_build_toplevel} - SOURCE_DIR ${toluapp_build_toplevel} - DOWNLOAD_DIR ${toluapp_build_toplevel} - TMP_DIR "${toluapp_build_toplevel}-tmp" - STAMP_DIR "${toluapp_build_toplevel}-stamp" - INSTALL_DIR "${toluapp_build_toplevel}/local" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" - BUILD_BYPRODUCTS "${toluapp_sources}") - -set(toluapp_lib toluapp_lib_${toluapp_version}) -add_library(${toluapp_lib} SHARED ${toluapp_sources}) -add_dependencies(${toluapp_lib} TOLUAPP_BUILD_SOURCE) -set_target_properties(${toluapp_lib} PROPERTIES - OUTPUT_NAME toluapp-${toluapp_version} - POSITION_INDEPENDENT_CODE TRUE) -target_include_directories(${toluapp_lib} - PUBLIC ${toluapp_include_dirs}) -target_link_libraries(${toluapp_lib} PRIVATE ${LUA_LIBRARIES} ${CMAKE_DL_LIBS}) -if (MSVC) - target_compile_options(${toluapp_lib} - PRIVATE /W1) - target_compile_definitions(${toluapp_lib} - PRIVATE "TOLUA_API=__declspec(dllexport)") -else() - target_compile_options(${toluapp_lib} - PRIVATE -w - INTERFACE -Wno-noexcept-type - PUBLIC -Wno-ignored-qualifiers -Wno-unused-parameter) -endif() -# add compatibility define -target_compile_definitions(${toluapp_lib} - PRIVATE COMPAT53_PREFIX=toluapp_compat53) - -# # Variables required by ToLuaBuild -set(TOLUAPP_LIBRARIES ${toluapp_lib}) -set(TOLUAPP_INCLUDE_DIRS ${toluapp_include_dirs}) -set(TOLUAPPBUILD_FOUND TRUE) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(ToLuappBuild - FOUND_VAR TOLUAPPBUILD_FOUND - REQUIRED_VARS TOLUAPP_LIBRARIES TOLUAPP_INCLUDE_DIRS - VERSION_VAR toluapp_version) diff --git a/third/sol2/cmake/sol2-config.cmake.in b/third/sol2/cmake/sol2-config.cmake.in deleted file mode 100644 index 0c48a993..00000000 --- a/third/sol2/cmake/sol2-config.cmake.in +++ /dev/null @@ -1,32 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -@PACKAGE_INIT@ - -include("${CMAKE_CURRENT_LIST_DIR}/sol2-targets.cmake") - -if (TARGET sol2) - get_target_property(SOL2_INCLUDE_DIRS - sol2 INTERFACE_INCLUDE_DIRECTORIES) - set_and_check(SOL2_INCLUDE_DIRS "${SOL2_INCLUDE_DIRS}") - set(SOL2_LIBRARIES sol2) -endif() diff --git a/third/sol2/examples/.clang-format b/third/sol2/examples/.clang-format deleted file mode 100644 index 9807f392..00000000 --- a/third/sol2/examples/.clang-format +++ /dev/null @@ -1,110 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - ---- -BasedOnStyle: WebKit -IndentWidth: 5 -TabWidth: 5 -ContinuationIndentWidth: 5 -UseTab: ForIndentation - -# Namespaces -NamespaceIndentation: All -CompactNamespaces: true -FixNamespaceComments: true - -# Overall Alignment -ColumnLimit: 65 -AlignAfterOpenBracket: DontAlign # uses ContinuationIndentWidth for this instead -AccessModifierOffset: -5 # do not push public: or private: around -#AlignConsecutiveAssignments: true # affects more than what's expected: do not use -#AlignConsecutiveDeclarations: true # affects more than what's expected: do not use - -# Type Alignment -DerivePointerAlignment: false -PointerAlignment: Left -AlwaysBreakTemplateDeclarations: true -AlwaysBreakBeforeMultilineStrings: true - -# Comments -AlignTrailingComments: true -ReflowComments: true - -# Macros -AlignEscapedNewlines: Left -#IndentPPDirectives: None - -# Functions -AllowShortFunctionsOnASingleLine: None -AlwaysBreakAfterReturnType: None -BreakConstructorInitializers: BeforeComma -ConstructorInitializerIndentWidth: 0 -ConstructorInitializerAllOnOneLineOrOnePerLine: true -BinPackArguments: false -BinPackParameters: true - -# Classes -BreakBeforeInheritanceComma: false - -# Braces -Cpp11BracedListStyle: false -BreakBeforeBraces: Custom -BraceWrapping: - AfterEnum: false - AfterStruct: false - AfterControlStatement: false - AfterClass: false - AfterNamespace: false - AfterStruct: false - AfterUnion: false - BeforeElse: true - BeforeCatch: true - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyRecord: false - SplitEmptyNamespace: true - -# Control Statements -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -IndentCaseLabels: false - -# Spaces -SpaceAfterCStyleCast: false -SpacesInCStyleCastParentheses: false -SpaceAfterTemplateKeyword: true -SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesInAngles: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -MaxEmptyLinesToKeep: 3 - -# OCD -SortUsingDeclarations: true -SortIncludes: false - ---- -Language: Cpp -Standard: Cpp11 diff --git a/third/sol2/examples/CMakeLists.txt b/third/sol2/examples/CMakeLists.txt deleted file mode 100644 index e33c45b4..00000000 --- a/third/sol2/examples/CMakeLists.txt +++ /dev/null @@ -1,118 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# # # sol2 Examples - -function(sol2_add_example_properties target-name) - target_link_libraries(${target-name} - PUBLIC Threads::Threads ${LUA_LIBRARIES} ${CMAKE_DL_LIBS}) - target_compile_definitions(${target-name} - PUBLIC SOL_PRINT_ERRORS=1) - target_compile_options(${target-name} - PRIVATE - ${--template-debugging-mode} - ${--big-obj} - ${--disable-permissive} - ${--pedantic} - ${--warn-all} - ${--warn-pedantic} - ${--warn-extra} - ${--warn-errors} - ${--utf8-literal-encoding} - ${--utf8-source-encoding} - - ${--allow-unknown-warning} - ${--allow-unknown-warning-option} - ${--allow-noexcept-type} - ${--allow-microsoft-cast} - ${--allow-unreachable-code} - ${--allow-padding-from-alignment} - ) - - target_compile_definitions(${target-name} - PRIVATE _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE) - - if (SOL2_CI) - target_compile_definitions(${target-name} - PRIVATE SOL2_CI) - endif() - - if (SOL2_TESTS_EXAMPLES) - add_test(NAME ${target-name} COMMAND ${target-name}) - endif() - if(SOL2_ENABLE_INSTALL) - install(TARGETS ${target-name} RUNTIME DESTINATION bin) - endif() -endfunction() - -if (SOL2_DYNAMIC_LOADING_EXAMPLES OR SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE) - # # require_from_dll example - # just add the subdirectory - add_subdirectory(require_dll_example) -endif() - -if (SOL2_INTEROP_EXAMPLES OR SOL2_INTEROP_EXAMPLES_SINGLE) - # # interop examples - add_subdirectory(interop/kaguya) - add_subdirectory(interop/tolua) - add_subdirectory(interop/LuaBridge) - add_subdirectory(interop/luwra) -endif() - -# # In-depth customization example -add_subdirectory(customization) - -# # single-source compilable examples - -file(GLOB sol2.examples.sources source/*.cpp source/tutorials/*.cpp source/tutorials/quick_n_dirty/*.cpp source/docs/*.cpp) - -function (MAKE_EXAMPLE example_source_file example_prefix target_sol) - get_filename_component(example_name ${example_source_file} NAME_WE) - file(RELATIVE_PATH example_source_file_relative ${CMAKE_SOURCE_DIR} ${example_source_file}) - get_filename_component(example_output_relative_dir ${example_source_file_relative} DIRECTORY) - file(TO_CMAKE_PATH "${example_output_relative_dir}" example_output_relative_dir_name) - STRING(REGEX REPLACE "/" "." example_output_relative_dir_name "${example_output_relative_dir}") - if (example_output_relative_dir_name STREQUAL "") - set(example_output_name ${example_name}) - set(example_name "${example_prefix}.${example_name}") - else() - set(example_output_name ${example_output_relative_dir_name}.${example_name}) - set(example_name "${example_prefix}.${example_output_relative_dir_name}.${example_name}") - endif() - - add_executable(${example_name} ${example_source_file}) - sol2_add_example_properties(${example_name}) - target_link_libraries(${example_name} - PRIVATE ${target_sol}) -endfunction(MAKE_EXAMPLE) - -if (SOL2_EXAMPLES) - foreach(example_source_file ${sol2.examples.sources}) - MAKE_EXAMPLE(${example_source_file} "sol2" sol2::sol2) - endforeach() -endif() - -if (SOL2_EXAMPLES_SINGLE) - foreach(example_source_file ${sol2.examples.sources}) - MAKE_EXAMPLE(${example_source_file} "sol2.single" sol2::sol2::single) - endforeach() -endif() diff --git a/third/sol2/examples/customization/CMakeLists.txt b/third/sol2/examples/customization/CMakeLists.txt deleted file mode 100644 index 40d3967c..00000000 --- a/third/sol2/examples/customization/CMakeLists.txt +++ /dev/null @@ -1,64 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# # # sol2 Customization Examples - -function (MAKE_CUSTOMIZATION_EXAMPLE example_suffix target_sol) - set(customization_example_name customization_to_table${example_suffix}) - - add_executable(${customization_example_name} source/main.cpp source/lua_interop.cpp source/lua_zm_interop.cpp) - set_target_properties(${customization_example_name} - PROPERTIES - OUTPUT_NAME "${customization_example_name}" - EXPORT_NAME sol2::${customization_example_name}) - - if (MSVC) - target_compile_options(${customization_example_name} - PRIVATE /std:c++latest /EHsc "$<$:/MDd>" - "$<$:/MD>" - "$<$:/MD>" - "$<$:/MD>") - target_compile_definitions(${customization_example_name} - PRIVATE UNICODE _UNICODE - _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE) - else() - target_compile_options(${customization_example_name} - PRIVATE -std=c++1z - -ftemplate-backtrace-limit=0 - -Wno-unknown-warning -Wno-unknown-warning-option - -Wall -Wpedantic -Werror -pedantic -pedantic-errors - -Wno-noexcept-type) - endif() - - target_link_libraries(${customization_example_name} - PRIVATE Threads::Threads ${target_sol} ${LUA_LIBRARIES}) - target_include_directories(${customization_example_name} - PRIVATE include) -endfunction() - -if (SOL2_EXAMPLES) - MAKE_CUSTOMIZATION_EXAMPLE("" sol2::sol2) -endif() - -if (SOL2_EXAMPLES_SINGLE) - MAKE_CUSTOMIZATION_EXAMPLE(".single" sol2::sol2::single) -endif() diff --git a/third/sol2/examples/customization/include/entity.hpp b/third/sol2/examples/customization/include/entity.hpp deleted file mode 100644 index 9bf589fd..00000000 --- a/third/sol2/examples/customization/include/entity.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#ifndef PROGRAM_ENTITY_HPP -#define PROGRAM_ENTITY_HPP - -#include - -class entity { -private: - zm::vec3 position_; - -public: - entity() { - this->position_ = { 1, 1, 1 }; - } - - zm::vec3 get_position() const { - return this->position_; - } - void set_position(zm::vec3 v) { - this->position_ = v; - } -}; - -#endif // PROGRAM_ENTITY_HPP diff --git a/third/sol2/examples/customization/include/lua_interop.hpp b/third/sol2/examples/customization/include/lua_interop.hpp deleted file mode 100644 index bd651b7d..00000000 --- a/third/sol2/examples/customization/include/lua_interop.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#ifndef PROGRAM_LUA_INTEROP_HPP -#define PROGRAM_LUA_INTEROP_HPP - -#include - -#define SOL_ALL_SAFETIES_ON 1 -#include - -void register_lua(sol::state& lua); - -#endif // PROGRAM_LUA_INTEROP_HPP diff --git a/third/sol2/examples/customization/include/lua_zm_interop.hpp b/third/sol2/examples/customization/include/lua_zm_interop.hpp deleted file mode 100644 index 89a975b3..00000000 --- a/third/sol2/examples/customization/include/lua_zm_interop.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#ifndef PROGRAM_LUA_ZM_INTEROP_HPP -#define PROGRAM_LUA_ZM_INTEROP_HPP - -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -#include - -bool sol_lua_check(sol::types, lua_State* L, int index, - std::function handler, - sol::stack::record& tracking); - -zm::vec3 sol_lua_get(sol::types, lua_State* L, - int index, sol::stack::record& tracking); - -int sol_lua_push( - sol::types, lua_State* L, const zm::vec3& v); - -#endif // PROGRAM_LUA_ZM_INTEROP_HPP diff --git a/third/sol2/examples/customization/include/zm/vec3.hpp b/third/sol2/examples/customization/include/zm/vec3.hpp deleted file mode 100644 index 6923ef7e..00000000 --- a/third/sol2/examples/customization/include/zm/vec3.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -#ifndef ZM_VEC3_HPP -#define ZM_VEC3_HPP - -#include - -namespace zm { - - struct vec3 { -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wgnu-anonymous-struct" -#pragma clang diagnostic ignored "-Wnested-anon-types" -#elif defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpedantic" -#elif defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable : 4201) // nonstandard extension used : - // nameless struct/union -#pragma warning(disable : 4324) // structure was padded due to - // alignment specifier -#endif - union { - float elements[3]; - struct { - union { - float x, r, s; - }; - union { - float y, g, t; - }; - union { - float z, b, p; - }; - }; - }; - -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#pragma GCC diagnostic pop -#elif defined(_MSC_VER) -#pragma warning(pop) -#endif - - vec3() : x(0), y(0), z(0) { - } - - vec3(float x_, float y_, float z_) - : x(x_), y(y_), z(z_) { - } - - constexpr float* data() { - return elements; - } - - constexpr const float* data() const { - return this->elements; - } - - constexpr float& operator[](std::size_t i) { - return this->elements[i]; - } - - constexpr const float& operator[]( - std::size_t i) const { - return this->elements[i]; - } - }; -} // namespace zm - -#endif // ZM_VEC3_HPP diff --git a/third/sol2/examples/customization/source/lua_interop.cpp b/third/sol2/examples/customization/source/lua_interop.cpp deleted file mode 100644 index 617101ad..00000000 --- a/third/sol2/examples/customization/source/lua_interop.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include - -#define SOL_ALL_SAFETIES_ON 1 -#include - -void register_lua(sol::state& lua) { - lua.new_usertype("entity", - "position", - sol::property( - &entity::get_position, &entity::set_position)); -} diff --git a/third/sol2/examples/customization/source/lua_zm_interop.cpp b/third/sol2/examples/customization/source/lua_zm_interop.cpp deleted file mode 100644 index 318e376f..00000000 --- a/third/sol2/examples/customization/source/lua_zm_interop.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include - -#include - -#define SOL_ALL_SAFETIES_ON 1 -#include - -bool sol_lua_check(sol::types, lua_State* L, int index, - std::function handler, - sol::stack::record& tracking) { - // use sol's method for checking - // specifically for a table - return sol::stack::check( - L, index, handler, tracking); -} - -zm::vec3 sol_lua_get(sol::types, lua_State* L, - int index, sol::stack::record& tracking) { - sol::lua_table vec3table - = sol::stack::get(L, index, tracking); - float x = vec3table["x"]; - float y = vec3table["y"]; - float z = vec3table["z"]; - return zm::vec3 { x, y, z }; -} - -int sol_lua_push( - sol::types, lua_State* L, const zm::vec3& v) { - // create table - sol::state_view lua(L); - sol::table vec3table = sol::table::create_with( - L, "x", v.x, "y", v.y, "z", v.z); - // use base sol method to - // push the table - int amount = sol::stack::push(L, vec3table); - // return # of things pushed onto stack - return amount; -} diff --git a/third/sol2/examples/customization/source/main.cpp b/third/sol2/examples/customization/source/main.cpp deleted file mode 100644 index 9101f03d..00000000 --- a/third/sol2/examples/customization/source/main.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main(int, char*[]) { - std::cout << "=== customization: vec3 as table ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - std::cout << "registering entities into Lua ..." - << std::endl; - register_lua(lua); - std::cout << "running script ..." << std::endl; - - const auto& script = R"lua( -local e = entity.new() -local pos = e.position -print("pos type", type(pos)) -print("pos", pos.x, pos.y, pos.z) -e.position = { x = 52, y = 5.5, z = 47.5 } -local new_pos = e.position -print("pos", pos.x, pos.y, pos.z) -print("new_pos", new_pos.x, new_pos.y, new_pos.z) -)lua"; - - sol::optional result = lua.safe_script(script); - if (result.has_value()) { - std::cerr << "Something went horribly wrong: " - << result.value().what() << std::endl; - } - - std::cout << "finishing ..." << std::endl; - - std::cout << std::endl; - return 0; -} diff --git a/third/sol2/examples/interop/LuaBridge/CMakeLists.txt b/third/sol2/examples/interop/LuaBridge/CMakeLists.txt deleted file mode 100644 index 439e74cb..00000000 --- a/third/sol2/examples/interop/LuaBridge/CMakeLists.txt +++ /dev/null @@ -1,62 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# # # sol2 interop Examples - luabridge - -find_package(LuaBridgeBuild) - -function (make_luabridge_interop_example target_library example_suffix) - set(example_name luabridge_interop_example) - set(example_name "${example_name}${example_suffix}") - - add_executable(${example_name} source/LuaBridge.cpp) - target_link_libraries(${example_name} - PRIVATE ${LUA_LIBRARIES} ${LUABRIDGE_LIBRARIES} - ${target_library} ${CMAKE_DL_LIBS}) - - if (MSVC) - target_compile_options(${example_name} - PRIVATE /std:c++latest /EHsc "$<$:/MDd>" - "$<$:/MD>" - "$<$:/MD>" - "$<$:/MD>") - target_compile_definitions(${example_name} - PRIVATE /W1 - UNICODE _UNICODE - _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE) - else() - target_compile_options(${example_name} - PRIVATE -std=c++1z -w - -Wno-unknown-warning -Wno-unknown-warning-option) - endif() - - if (SOL2_TESTS_INTEROP_EXAMPLES) - add_test(NAME ${example_name} COMMAND ${example_name}) - endif() -endfunction() - -if (SOL2_INTEROP_EXAMPLES) - make_luabridge_interop_example(sol2::sol2 "") -endif() -if (SOL2_INTEROP_EXAMPLES_SINGLE) - make_luabridge_interop_example(sol2::sol2::single ".single") -endif() diff --git a/third/sol2/examples/interop/LuaBridge/source/LuaBridge.cpp b/third/sol2/examples/interop/LuaBridge/source/LuaBridge.cpp deleted file mode 100644 index f9092b3a..00000000 --- a/third/sol2/examples/interop/LuaBridge/source/LuaBridge.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#define SOL_ENABLE_INTEROP \ - 1 // MUST be defined to use interop features -#include - -#include - -#include - -// LuaBridge, -// no longer maintained, by VinnieFalco: -// https://github.com/vinniefalco/LuaBridge - -struct A { - - A(int v) : v_(v) { - } - - void print() { - std::cout << "called A::print" << std::endl; - } - - int value() const { - return v_; - } - -private: - int v_ = 50; -}; - -template -inline bool sol_lua_interop_check(sol::types, lua_State* L, - int relindex, sol::type index_type, Handler&& handler, - sol::stack::record& tracking) { - // just marking unused parameters for no compiler warnings - (void)index_type; - (void)handler; - tracking.use(1); - int index = lua_absindex(L, relindex); - T* corrected = luabridge::Userdata::get(L, index, true); - return corrected != nullptr; -} - -template -inline std::pair sol_lua_interop_get(sol::types t, - lua_State* L, int relindex, void* unadjusted_pointer, - sol::stack::record& tracking) { - (void)unadjusted_pointer; - int index = lua_absindex(L, relindex); - if (!sol_lua_interop_check(t, - L, - index, - sol::type::userdata, - sol::no_panic, - tracking)) { - return { false, nullptr }; - } - T* corrected = luabridge::Userdata::get(L, index, true); - return { true, corrected }; -} - -void register_sol_stuff(lua_State* L) { - // grab raw state and put into state_view - // state_view is cheap to construct - sol::state_view lua(L); - // bind and set up your things: everything is entirely - // self-contained - lua["f"] = sol::overload( - [](A& from_luabridge) { - std::cout << "calling 1-argument version with " - "luabridge-created A { " - << from_luabridge.value() << " }" - << std::endl; - sol_c_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); - }); -} - -void check_with_sol(lua_State* L) { - sol::state_view lua(L); - A& obj = lua["obj"]; - (void)obj; - sol_c_assert(obj.value() == 24); -} - -int main(int, char*[]) { - - std::cout << "=== interop example (LuaBridge) ===" - << std::endl; - std::cout << "code modified from LuaBridge's examples: " - "https://github.com/vinniefalco/LuaBridge" - << std::endl; - - struct closer { - void operator()(lua_State* L) { - lua_close(L); - } - }; - - std::unique_ptr state(luaL_newstate()); - lua_State* L = state.get(); - luaL_openlibs(L); - - luabridge::getGlobalNamespace(L) - .beginNamespace("test") - .beginClass("A") - .addConstructor() - .addFunction("print", &A::print) - .addFunction("value", &A::value) - .endClass() - .endNamespace(); - - register_sol_stuff(L); - - - if (luaL_dostring(L, R"( -obj = test.A(24) -f(obj) -- call 1 argument version -f(obj, 5) -- call 2 argument version -)")) { - lua_error(L); - } - - check_with_sol(L); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/interop/kaguya/CMakeLists.txt b/third/sol2/examples/interop/kaguya/CMakeLists.txt deleted file mode 100644 index 2b20a722..00000000 --- a/third/sol2/examples/interop/kaguya/CMakeLists.txt +++ /dev/null @@ -1,61 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# # # sol2 interop Examples - kaguya - -find_package(KaguyaBuild) - -function (make_kaguya_interop_example target_library example_suffix) - set(example_name kaguya_interop_example) - set(example_name "${example_name}${example_suffix}") - - add_executable(${example_name} source/kaguya.cpp) - target_link_libraries(${example_name} - PRIVATE ${LUA_LIBRARIES} ${KAGUYA_LIBRARIES} - ${target_library} ${CMAKE_DL_LIBS}) - - if (MSVC) - target_compile_options(${example_name} - PRIVATE /W1 /std:c++latest /EHsc "$<$:/MDd>" - "$<$:/MD>" - "$<$:/MD>" - "$<$:/MD>") - target_compile_definitions(${example_name} - PRIVATE UNICODE _UNICODE - _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE) - else() - target_compile_options(${example_name} - PRIVATE -std=c++1z -w - -Wno-unknown-warning -Wno-unknown-warning-option) - endif() - - if (SOL2_TESTS_INTEROP_EXAMPLES) - add_test(NAME ${example_name} COMMAND ${example_name}) - endif() -endfunction() - -if (SOL2_INTEROP_EXAMPLES) - make_kaguya_interop_example(sol2::sol2 "") -endif() -if (SOL2_INTEROP_EXAMPLES_SINGLE) - make_kaguya_interop_example(sol2::sol2::single ".single") -endif() diff --git a/third/sol2/examples/interop/kaguya/source/kaguya.cpp b/third/sol2/examples/interop/kaguya/source/kaguya.cpp deleted file mode 100644 index ff3ffb27..00000000 --- a/third/sol2/examples/interop/kaguya/source/kaguya.cpp +++ /dev/null @@ -1,141 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#define SOL_ENABLE_INTEROP \ - 1 // MUST be defined to use interop features -#include - -#include - -// kaguya code lifted from README.md, -// written by satoren: -// https://github.com/satoren/kaguya -// Copyright satoren -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -struct ABC { - ABC() : v_(0) { - } - ABC(int value) : v_(value) { - } - int value() const { - return v_; - } - void setValue(int v) { - v_ = v; - } - void overload1() { - std::cout << "call overload1" << std::endl; - } - void overload2(int) { - std::cout << "call overload2" << std::endl; - } - -private: - int v_; -}; - -template -inline bool sol_lua_interop_check(sol::types, lua_State* L, - int relindex, sol::type index_type, Handler&& handler, - sol::stack::record& tracking) { - // just marking unused parameters for no compiler warnings - (void)index_type; - (void)handler; - // using 1 element - tracking.use(1); - int index = lua_absindex(L, relindex); - // use kaguya's own detail wrapper check to see if it's - // correct - bool is_correct_type - = kaguya::detail::object_wrapper_type_check(L, index); - return is_correct_type; -} - -template -inline std::pair sol_lua_interop_get(sol::types, - lua_State* L, int relindex, void* unadjusted_pointer, - sol::stack::record& tracking) { - // you may not need to specialize this method every time: - // some libraries are compatible with sol2's layout - - // kaguya's storage of data is incompatible with sol's - // it stores the data directly in the pointer, not a pointer - // inside of the `void*` therefore, leave the raw userdata - // pointer as-is, if it's of the right type - int index = lua_absindex(L, relindex); - if (!kaguya::detail::object_wrapper_type_check(L, index)) { - return { false, nullptr }; - } - // using 1 element - tracking.use(1); - kaguya::ObjectWrapperBase* base - = kaguya::object_wrapper(L, index); - return { true, static_cast(base->get()) }; -} - -void register_sol_stuff(lua_State* L) { - // grab raw state and put into state_view - // state_view is cheap to construct - sol::state_view lua(L); - // bind and set up your things: everything is entirely - // self-contained - lua["f"] = sol::overload( - [](ABC& from_kaguya) { - std::cout << "calling 1-argument version with " - "kaguya-created ABC { " - << from_kaguya.value() << " }" - << std::endl; - sol_c_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); - }); -} - -void check_with_sol(lua_State* L) { - sol::state_view lua(L); - ABC& obj = lua["obj"]; - (void)obj; - sol_c_assert(obj.value() == 24); -} - -int main(int, char*[]) { - - std::cout << "=== interop example (kaguya) ===" - << std::endl; - std::cout << "(code lifted from kaguya's README examples: " - "https://github.com/satoren/kaguya)" - << std::endl; - - kaguya::State state; - - state["ABC"].setClass( - kaguya::UserdataMetatable() - .setConstructors() - .addFunction("get_value", &ABC::value) - .addFunction("set_value", &ABC::setValue) - .addOverloadedFunctions( - "overload", &ABC::overload1, &ABC::overload2) - .addStaticFunction("nonmemberfun", - [](ABC* self, int) { return 1; })); - - - register_sol_stuff(state.state()); - - state.dostring(R"( -obj = ABC.new(24) -f(obj) -- call 1 argument version -f(obj, 5) -- call 2 argument version -)"); - - check_with_sol(state.state()); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/interop/luwra/CMakeLists.txt b/third/sol2/examples/interop/luwra/CMakeLists.txt deleted file mode 100644 index 2ad82c81..00000000 --- a/third/sol2/examples/interop/luwra/CMakeLists.txt +++ /dev/null @@ -1,61 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# # # sol2 interop Examples - luwra - -find_package(LuwraBuild) - -function (make_luwra_interop_example target_library example_suffix) - set(example_name luwra_interop_example) - set(example_name "${example_name}${example_suffix}") - - add_executable(${example_name} source/luwra.cpp) - target_link_libraries(${example_name} - PRIVATE ${LUA_LIBRARIES} ${LUWRA_LIBRARIES} - ${target_library} ${CMAKE_DL_LIBS}) - - if (MSVC) - target_compile_options(${example_name} - PRIVATE /std:c++latest /EHsc "$<$:/MDd>" - "$<$:/MD>" - "$<$:/MD>" - "$<$:/MD>") - target_compile_definitions(${example_name} - PRIVATE /W1 UNICODE _UNICODE - _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE) - else() - target_compile_options(${example_name} - PRIVATE -std=c++1z -w - -Wno-unknown-warning -Wno-unknown-warning-option) - endif() - - if (SOL2_TESTS_INTEROP_EXAMPLES) - add_test(NAME ${example_name} COMMAND ${example_name}) - endif() -endfunction() - -if (SOL2_INTEROP_EXAMPLES) - make_luwra_interop_example(sol2::sol2 "") -endif() -if (SOL2_INTEROP_EXAMPLES_SINGLE) - make_luwra_interop_example(sol2::sol2::single ".single") -endif() diff --git a/third/sol2/examples/interop/luwra/source/luwra.cpp b/third/sol2/examples/interop/luwra/source/luwra.cpp deleted file mode 100644 index de6f6740..00000000 --- a/third/sol2/examples/interop/luwra/source/luwra.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#define SOL_ENABLE_INTEROP \ - 1 // MUST be defined to use interop features -#include - -#include - -#include - -// luwra, -// another C++ wrapper library: -// https://github.com/vapourismo/luwra - -struct ABC { - ABC() : v_(0) { - } - ABC(int value) : v_(value) { - } - int value() const { - return v_; - } - void setValue(int v) { - v_ = v; - } - void overload1() { - std::cout << "call overload1" << std::endl; - } - void overload2(int) { - std::cout << "call overload2" << std::endl; - } - -private: - int v_; -}; - -template -inline bool sol_lua_interop_check(sol::types, lua_State* L, - int relindex, sol::type index_type, Handler&& handler, - sol::stack::record& tracking) { - // just marking unused parameters for no compiler warnings - (void)index_type; - (void)handler; - // using 1 element - tracking.use(1); - int index = lua_absindex(L, relindex); - if (lua_getmetatable(L, index) == 1) { - luaL_getmetatable( - L, luwra::internal::UserTypeReg::name.c_str()); - bool is_correct_type = lua_rawequal(L, -2, -1) == 1; - lua_pop(L, 2); - return is_correct_type; - } - return false; -} - -template -inline std::pair sol_lua_interop_get(sol::types t, - lua_State* L, int relindex, void* unadjusted_pointer, - sol::stack::record& tracking) { - // you may not need to specialize this method every time: - // some libraries are compatible with sol2's layout - int index = lua_absindex(L, relindex); - if (!sol_lua_interop_check(t, - L, - index, - sol::type::userdata, - sol::no_panic, - tracking)) { - return { false, nullptr }; - } - return { true, static_cast(unadjusted_pointer) }; -} - -void register_sol_stuff(lua_State* L) { - // grab raw state and put into state_view - // state_view is cheap to construct - sol::state_view lua(L); - // bind and set up your things: everything is entirely - // self-contained - lua["f"] = sol::overload( - [](ABC& from_luwra) { - std::cout << "calling 1-argument version with " - "luwra-created ABC { " - << from_luwra.value() << " }" - << std::endl; - sol_c_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); - }); -} - -void check_with_sol(lua_State* L) { - sol::state_view lua(L); - ABC& obj = lua["obj"]; - (void)obj; - sol_c_assert(obj.value() == 24); -} - -int main(int, char*[]) { - - std::cout << "=== interop example (luwra) ===" << std::endl; - std::cout << "code modified from luwra's documentation " - "examples: https://github.com/vapourismo/luwra" - << std::endl; - - luwra::StateWrapper state; - - state.registerUserType("ABC", - { LUWRA_MEMBER(ABC, value), - LUWRA_MEMBER(ABC, setValue) }, - {}); - - register_sol_stuff(state); - - state.runString(R"( -obj = ABC(24) -f(obj) -- call 1 argument version -f(obj, 5) -- call 2 argument version -)"); - - check_with_sol(state); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/interop/tolua/CMakeLists.txt b/third/sol2/examples/interop/tolua/CMakeLists.txt deleted file mode 100644 index d92c8ef1..00000000 --- a/third/sol2/examples/interop/tolua/CMakeLists.txt +++ /dev/null @@ -1,63 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# # # sol2 interop Examples - tolua - -find_package(ToLuappBuild REQUIRED) - -function(make_tolua_interop_example target_library example_suffix) - set(example_name tolua_interop_example) - set(example_name "${example_name}${example_suffix}") - - add_executable(${example_name} source/tolua.cpp) - target_link_libraries(${example_name} - PRIVATE - ${LUA_LIBRARIES} ${TOLUAPP_LIBRARIES} ${target_library} ${CMAKE_DL_LIBS}) - - if (MSVC) - target_compile_options(${example_name} - PRIVATE /std:c++latest /EHsc "$<$:/MDd>" - "$<$:/MD>" - "$<$:/MD>" - "$<$:/MD>") - target_compile_definitions(${example_name} - PRIVATE /W1 UNICODE _UNICODE - _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE) - else() - target_compile_options(${example_name} - PRIVATE -std=c++1z -w - -Wno-unknown-warning -Wno-unknown-warning-option) - endif() - - if (SOL2_TESTS_INTEROP_EXAMPLES) - add_test(NAME ${example_name} COMMAND ${example_name}) - endif() -endfunction() - -MESSAGE(STATUS ${SOL2_LUA_VERSION}) - -if (SOL2_INTEROP_EXAMPLES) - make_tolua_interop_example(sol2::sol2 "") -endif() -if (SOL2_INTEROP_EXAMPLES_SINGLE) - make_tolua_interop_example(sol2::sol2::single ".single") -endif() diff --git a/third/sol2/examples/interop/tolua/source/Player.h b/third/sol2/examples/interop/tolua/source/Player.h deleted file mode 100644 index 8d64abcc..00000000 --- a/third/sol2/examples/interop/tolua/source/Player.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef PLAYER_H -#define PLAYER_H - -class Player { -private: - int m_health; - -public: - Player() : m_health(0) { - } - void setHealth(int health) { - m_health = health; - } - int getHealth() const { - return m_health; - } -}; - -#endif // PLAYER_H diff --git a/third/sol2/examples/interop/tolua/source/Player.pkg b/third/sol2/examples/interop/tolua/source/Player.pkg deleted file mode 100644 index e6c3fabf..00000000 --- a/third/sol2/examples/interop/tolua/source/Player.pkg +++ /dev/null @@ -1,8 +0,0 @@ -$#include "Player.h" - -class Player { - Player(); - ~Player(); - void setHealth(int _health); - int getHealth(); -}; diff --git a/third/sol2/examples/interop/tolua/source/tolua.cpp b/third/sol2/examples/interop/tolua/source/tolua.cpp deleted file mode 100644 index bf1d1d85..00000000 --- a/third/sol2/examples/interop/tolua/source/tolua.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#define SOL_ENABLE_INTEROP \ - 1 // MUST be defined to use interop features -#include - -#include "Player.h" -#include -// pick or replace the include -// with whatever generated file you've created -#include "tolua_Player.h" - -#include - -// tolua code lifted from some blog, if the link dies -// I don't know where else you're gonna find the reference, -// http://usefulgamedev.weebly.com/tolua-example.html - - -/* NOTE: there is no sol_lua_interop_get here, - because tolua types are -- thankfully -- memory-compatible - in most cases with sol. - Please check other examples like kaguya or LuaBribe for an - example of how to also write the getter for your type*/ -template -inline bool sol_lua_interop_check(sol::types, lua_State* L, - int relindex, sol::type index_type, Handler&& handler, - sol::stack::record& tracking) { - tracking.use(1); - // just marking unused parameters for no compiler warnings - (void)index_type; - (void)handler; - int index = lua_absindex(L, relindex); - std::string name = sol::detail::short_demangle(); - tolua_Error tolua_err {}; - int r = tolua_isusertype( - L, index, name.c_str(), 0, &tolua_err); - if (r == 0) { - // tolua seems to leave garbage on the stack - // when the check fails - // thanks, tolua - lua_pop(L, 2); - return false; - } - return true; -} - -void register_sol_stuff(lua_State* L) { - // grab raw state and put into state_view - // state_view is cheap to construct - sol::state_view lua(L); - // bind and set up your things: everything is entirely - // self-contained - lua["f"] = sol::overload( - [](Player& from_tolua) { - std::cout << "calling 1-argument version with " - "tolua-created Player { health:" - << from_tolua.getHealth() << " }" - << std::endl; - sol_c_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); - }); -} - -void check_with_sol(lua_State* L) { - sol::state_view lua(L); - Player& obj = lua["obj"]; - (void)obj; - sol_c_assert(obj.getHealth() == 4); -} - -int main(int, char*[]) { - - std::cout << "=== interop example (tolua) ===" << std::endl; - std::cout << "(code lifted from a sol2 user's use case: " - "https://github.com/ThePhD/sol2/issues/" - "511#issuecomment-331729884)" - << std::endl; - - lua_State* L = luaL_newstate(); - - luaL_openlibs( - L); // initalize all lua standard library functions - tolua_open(L); // initalize tolua - tolua_Player_open( - L); // make Player class accessible from LUA - - - register_sol_stuff(L); - - const auto code = R"( -obj = Player:new() -obj:setHealth(4) - -f(obj) -- call 1 argument version -f(obj, 5) -- call 2 argument version -)"; - - if (luaL_dostring(L, code)) { - lua_error(L); // crash on error - } - - check_with_sol(L); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/interop/tolua/source/tolua_Player.h b/third/sol2/examples/interop/tolua/source/tolua_Player.h deleted file mode 100644 index 85f9fe0f..00000000 --- a/third/sol2/examples/interop/tolua/source/tolua_Player.h +++ /dev/null @@ -1,226 +0,0 @@ -/* -** Lua binding: Player -** Generated automatically by tolua++-1.0.93-lua53 on Sat Feb 10 -*08:48:53 2018. -*/ - -#ifndef __cplusplus -#include "stdlib.h" -#endif -#include "string.h" - -#include "tolua++.h" - -/* Exported function */ -TOLUA_API int tolua_Player_open(lua_State* tolua_S); - -#include "Player.h" - -/* function to release collected object via destructor */ -#ifdef __cplusplus - -static int tolua_collect_Player(lua_State* tolua_S) { - Player* self = (Player*)tolua_tousertype(tolua_S, 1, 0); - Mtolua_delete(self); - return 0; -} -#endif - - -/* function to register type */ -static void tolua_reg_types(lua_State* tolua_S) { - tolua_usertype(tolua_S, "Player"); -} - -/* method: new of class Player */ -#ifndef TOLUA_DISABLE_tolua_Player_Player_new00 -static int tolua_Player_Player_new00(lua_State* tolua_S) { -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S, 1, "Player", 0, &tolua_err) - || !tolua_isnoobj(tolua_S, 2, &tolua_err)) - goto tolua_lerror; - else -#endif - { - { - Player* tolua_ret - = (Player*)Mtolua_new((Player)()); - tolua_pushusertype( - tolua_S, (void*)tolua_ret, "Player"); - } - } - return 1; -#ifndef TOLUA_RELEASE -tolua_lerror: - tolua_error( - tolua_S, "#ferror in function 'new'.", &tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - -/* method: new_local of class Player */ -#ifndef TOLUA_DISABLE_tolua_Player_Player_new00_local -static int tolua_Player_Player_new00_local(lua_State* tolua_S) { -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if (!tolua_isusertable(tolua_S, 1, "Player", 0, &tolua_err) - || !tolua_isnoobj(tolua_S, 2, &tolua_err)) - goto tolua_lerror; - else -#endif - { - { - Player* tolua_ret - = (Player*)Mtolua_new((Player)()); - tolua_pushusertype( - tolua_S, (void*)tolua_ret, "Player"); - tolua_register_gc(tolua_S, lua_gettop(tolua_S)); - } - } - return 1; -#ifndef TOLUA_RELEASE -tolua_lerror: - tolua_error( - tolua_S, "#ferror in function 'new'.", &tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - -/* method: delete of class Player */ -#ifndef TOLUA_DISABLE_tolua_Player_Player_delete00 -static int tolua_Player_Player_delete00(lua_State* tolua_S) { -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S, 1, "Player", 0, &tolua_err) - || !tolua_isnoobj(tolua_S, 2, &tolua_err)) - goto tolua_lerror; - else -#endif - { - Player* self - = (Player*)tolua_tousertype(tolua_S, 1, 0); -#ifndef TOLUA_RELEASE - if (!self) - tolua_error(tolua_S, - "invalid 'self' in function 'delete'", - NULL); -#endif - Mtolua_delete(self); - } - return 0; -#ifndef TOLUA_RELEASE -tolua_lerror: - tolua_error( - tolua_S, "#ferror in function 'delete'.", &tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - -/* method: setHealth of class Player */ -#ifndef TOLUA_DISABLE_tolua_Player_Player_setHealth00 -static int tolua_Player_Player_setHealth00(lua_State* tolua_S) { -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S, 1, "Player", 0, &tolua_err) - || !tolua_isnumber(tolua_S, 2, 0, &tolua_err) - || !tolua_isnoobj(tolua_S, 3, &tolua_err)) - goto tolua_lerror; - else -#endif - { - Player* self - = (Player*)tolua_tousertype(tolua_S, 1, 0); - int _health = ((int)tolua_tonumber(tolua_S, 2, 0)); -#ifndef TOLUA_RELEASE - if (!self) - tolua_error(tolua_S, - "invalid 'self' in function 'setHealth'", - NULL); -#endif - { self->setHealth(_health); } - } - return 0; -#ifndef TOLUA_RELEASE -tolua_lerror: - tolua_error(tolua_S, - "#ferror in function 'setHealth'.", - &tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - -/* method: getHealth of class Player */ -#ifndef TOLUA_DISABLE_tolua_Player_Player_getHealth00 -static int tolua_Player_Player_getHealth00(lua_State* tolua_S) { -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if (!tolua_isusertype(tolua_S, 1, "Player", 0, &tolua_err) - || !tolua_isnoobj(tolua_S, 2, &tolua_err)) - goto tolua_lerror; - else -#endif - { - Player* self - = (Player*)tolua_tousertype(tolua_S, 1, 0); -#ifndef TOLUA_RELEASE - if (!self) - tolua_error(tolua_S, - "invalid 'self' in function 'getHealth'", - NULL); -#endif - { - int tolua_ret = (int)self->getHealth(); - tolua_pushnumber(tolua_S, (lua_Number)tolua_ret); - } - } - return 1; -#ifndef TOLUA_RELEASE -tolua_lerror: - tolua_error(tolua_S, - "#ferror in function 'getHealth'.", - &tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - -/* Open function */ -TOLUA_API int tolua_Player_open(lua_State* tolua_S) { - tolua_open(tolua_S); - tolua_reg_types(tolua_S); - tolua_module(tolua_S, NULL, 0); - tolua_beginmodule(tolua_S, NULL); -#ifdef __cplusplus - tolua_cclass( - tolua_S, "Player", "Player", "", tolua_collect_Player); -#else - tolua_cclass(tolua_S, "Player", "Player", "", NULL); -#endif - tolua_beginmodule(tolua_S, "Player"); - tolua_function(tolua_S, "new", tolua_Player_Player_new00); - tolua_function( - tolua_S, "new_local", tolua_Player_Player_new00_local); - tolua_function( - tolua_S, ".call", tolua_Player_Player_new00_local); - tolua_function( - tolua_S, "delete", tolua_Player_Player_delete00); - tolua_function( - tolua_S, "setHealth", tolua_Player_Player_setHealth00); - tolua_function( - tolua_S, "getHealth", tolua_Player_Player_getHealth00); - tolua_endmodule(tolua_S); - tolua_endmodule(tolua_S); - return 1; -} - - -#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501 -TOLUA_API int luaopen_Player(lua_State* tolua_S) { - return tolua_Player_open(tolua_S); -}; -#endif diff --git a/third/sol2/examples/require_dll_example/CMakeLists.txt b/third/sol2/examples/require_dll_example/CMakeLists.txt deleted file mode 100644 index 69b77462..00000000 --- a/third/sol2/examples/require_dll_example/CMakeLists.txt +++ /dev/null @@ -1,134 +0,0 @@ -# # # # sol2 -# The MIT License (MIT) -# -# Copyright (c) 2013-2022 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. - -# # # sol2 Examples - require_from_dll - -# # Reusable function to call for single target -# # Also hides variables from directory/global scope -function(make_require_from_dll_example target_lib example_lib_name_suffix) - # define sources - set(my_object_sources source/my_object.cpp) - set(require_from_dll_sources source/require_from_dll.cpp) - - # define names - set(example_lib_name my_object) - set(example_name require_from_dll) - set(example_lib_name "${example_lib_name}${example_lib_name_suffix}") - set(example_name "${example_name}${example_lib_name_suffix}") - - # add library target my_object for the require_from_dll program - add_library(${example_lib_name} SHARED ${my_object_sources}) - set_target_properties(${example_lib_name} PROPERTIES - PREFIX "") - - target_include_directories(${example_lib_name} - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") - target_compile_definitions(${example_lib_name} - PUBLIC MY_OBJECT_DLL - PRIVATE MY_OBJECT_BUILD) - target_link_libraries(${example_lib_name} - PUBLIC ${target_lib} ${LUA_LIBRARIES} ${CMAKE_DL_LIBS}) - target_include_directories(${example_lib_name} - PUBLIC "${LUA_INCLUDE_DIRS}") - - if (MSVC) - target_compile_options(${example_lib_name} - PRIVATE /std:c++latest /EHsc "$<$:/MDd>" - "$<$:/MD>" - "$<$:/MD>" - "$<$:/MD>") - target_compile_definitions(${example_lib_name} - PRIVATE UNICODE _UNICODE - _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE) - else() - target_compile_options(${example_lib_name} - PRIVATE -std=c++1z - -Wno-unknown-warning -Wno-unknown-warning-option - -Wall -Wextra -Wpedantic -pedantic -pedantic-errors - -Wno-noexcept-type) - - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # For another day, when C++ is not so crap - # and we have time to audit the entire lib - # for all uses of `detail::swallow`... - #target_compile_options(${test_target_name} - # PRIVATE -Wcomma) - endif() - - - if (IS_X86) - target_compile_options(${example_lib_name} BEFORE PRIVATE -m32) - endif() - endif() - - # add executable target that represents require_from_dll program - add_executable(${example_name} ${require_from_dll_sources}) - target_link_libraries(${example_name} - PRIVATE my_object ${LUA_LIBRARIES} ${target_lib} ${CMAKE_DL_LIBS}) - target_include_directories(${example_name} - PRIVATE ${LUA_INCLUDE_DIRS}) - - if (MSVC) - target_compile_options(${example_name} - PRIVATE /std:c++latest /EHsc "$<$:/MDd>" - "$<$:/MD>" - "$<$:/MD>" - "$<$:/MD>") - target_compile_definitions(${example_name} - PRIVATE UNICODE _UNICODE - _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE) - else() - target_compile_options(${example_name} - PRIVATE -std=c++1z - -Wno-unknown-warning -Wno-unknown-warning-option - -Wall -Wextra -Wpedantic -pedantic -pedantic-errors - -Wno-noexcept-type) - - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # For another day, when C++ is not so crap - # and we have time to audit the entire lib - # for all uses of `detail::swallow`... - #target_compile_options(${test_target_name} - # PRIVATE -Wcomma) - endif() - endif() - - if (SOL2_TESTS_DYNAMIC_LOADING_EXAMPLES) - get_target_property(example_working_dir ${example_name} RUNTIME_OUTPUT_DIRECTORY) - add_test(NAME ${example_name} COMMAND ${example_name} WORKING_DIRECTORY "${example_working_dir}") - endif() -endfunction() - -list(GET LUA_LIBRARIES 0 lua_lib_target) -get_target_property(lua_lib_type ${lua_lib_target} TYPE) -if (lua_lib_type MATCHES "STATIC") - # avoid multiply defined references due to linking in the same static library - # twice over, and get "multiple definition" errors during linking - return() -endif() - -if (SOL2_DYNAMIC_LOADING_EXAMPLES) - make_require_from_dll_example(sol2::sol2 "") -endif() -if (SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE) - make_require_from_dll_example(sol2::sol2::single ".single") -endif() diff --git a/third/sol2/examples/require_dll_example/include/my_object/my_object.hpp b/third/sol2/examples/require_dll_example/include/my_object/my_object.hpp deleted file mode 100644 index 19638b26..00000000 --- a/third/sol2/examples/require_dll_example/include/my_object/my_object.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include - -// forward declare as a C struct -// so a pointer to lua_State can be part of a signature -extern "C" { -struct lua_State; -} -// you can replace the above if you're fine with including -// earlier than absolutely necessary - -namespace my_object { - - struct test { - int value; - - test() = default; - test(int val) : value(val) { - } - }; - -} // namespace my_object - -// this function needs to be exported from your -// dll. "extern 'C'" should do the trick, but -// we're including platform-specific stuff here to help -// see my_object_api.hpp for details -extern "C" MY_OBJECT_API int luaopen_my_object(lua_State* L); diff --git a/third/sol2/examples/require_dll_example/include/my_object/my_object_api.hpp b/third/sol2/examples/require_dll_example/include/my_object/my_object_api.hpp deleted file mode 100644 index a31532d9..00000000 --- a/third/sol2/examples/require_dll_example/include/my_object/my_object_api.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -namespace my_object { - -#if defined _MSC_VER -#define MY_OBJECT_VC -#elif defined __GNUC__ -#define MY_OBJECT_GCC -#elif defined __clang__ -#define MY_OBJECT_CLANG -#endif - -#if defined MY_OBJECT_VC -#if defined MY_OBJECT_DLL -#if defined MY_OBJECT_BUILD -#define MY_OBJECT_API __declspec(dllexport) -#else -#define MY_OBJECT_API __declspec(dllexport) -#endif // MY_OBJECT_BUILD - Building the Library vs. Using the - // Library -#else -#define MY_OBJECT_API -#endif // Building a DLL vs. Static Library -#else // g++ / clang++ -#define MY_OBJECT_API __attribute__((visibility("default"))) -#endif // MY_OBJECT_BUILD - -} // namespace my_object diff --git a/third/sol2/examples/require_dll_example/source/my_object.cpp b/third/sol2/examples/require_dll_example/source/my_object.cpp deleted file mode 100644 index 2094c519..00000000 --- a/third/sol2/examples/require_dll_example/source/my_object.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include - -#define SOL_ALL_SAFETIES_ON 1 -#include - -namespace my_object { - - sol::table open_my_object(sol::this_state L) { - sol::state_view lua(L); - sol::table module = lua.create_table(); - module.new_usertype("test", - sol::constructors(), - "value", - &test::value); - - return module; - } - -} // namespace my_object - -extern "C" int luaopen_my_object(lua_State* L) { - // pass the lua_State, - // the index to start grabbing arguments from, - // and the function itself - // optionally, you can pass extra arguments to the function - // if that's necessary, but that's advanced usage and is - // generally reserved for internals only - return sol::stack::call_lua( - L, 1, my_object::open_my_object); -} diff --git a/third/sol2/examples/require_dll_example/source/require_from_dll.cpp b/third/sol2/examples/require_dll_example/source/require_from_dll.cpp deleted file mode 100644 index 1d8f96bb..00000000 --- a/third/sol2/examples/require_dll_example/source/require_from_dll.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -#include - -int main(int, char*[]) { - std::cout << "=== require from DLL ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::package, sol::lib::base); - - const auto& code = R"( -mo = require("my_object") - -obj = mo.test.new(24) -print(obj.value))"; - auto script_result - = lua.safe_script(code, &sol::script_pass_on_error); - if (script_result.valid()) { - std::cout << "The DLL was require'd from successfully!" - << std::endl; - } - else { - sol::error err = script_result; - std::cout << "Something bad happened: " << err.what() - << std::endl; - } - sol_c_assert(script_result.valid()); - my_object::test& obj = lua["obj"]; - sol_c_assert(obj.value == 24); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/allocation_limit.cpp b/third/sol2/examples/source/allocation_limit.cpp deleted file mode 100644 index faaa5b0b..00000000 --- a/third/sol2/examples/source/allocation_limit.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -class memory_tracker { -public: - // 10 MB or something? - // idk whatever - inline static constexpr std::size_t arbitrary_default_limit - = 1024 * 1024 * 10; - - memory_tracker() : memory_tracker(arbitrary_default_limit) { - } - - memory_tracker(std::size_t maximum_memory) - : used(0) - , limit(maximum_memory) - , n_threads(0) - , n_tables(0) - , n_functions(0) - , n_userdata(0) - , n_strings(0) { - } - - std::size_t currently_used() const { - return used; - } - - std::size_t memory_limit() const { - return limit; - } - - static void* allocate(void* memory_tracker_ud, void* ptr, - size_t object_code, size_t nsize) { - memory_tracker& self = (*static_cast( - memory_tracker_ud)); - return self.alloc(ptr, object_code, nsize); - } - -private: - void* alloc(void* ptr, size_t original_block_size_or_code, - size_t new_block_size) { - std::size_t original_block_size - = original_block_size_or_code; - if (ptr == nullptr) { - // object code! - sol::type object_type = static_cast( - original_block_size_or_code); - switch (object_type) { - case sol::type::function: - ++n_functions; - break; - case sol::type::string: - ++n_strings; - break; - case sol::type::userdata: - ++n_userdata; - break; - case sol::type::table: - ++n_tables; - break; - case sol::type::thread: - ++n_threads; - break; - default: - // not a clue, fam - break; - } - // because it is an object code, - // it tells us literally nothing about - // the old block size, - // so set that to 0 - original_block_size = 0; - } - if (new_block_size == 0) { - // Lua expects us to act like a "free" - // when the new block size is 0 - std::free(ptr); - used -= original_block_size; - return nullptr; - } - - // did we hit the limit? - std::size_t memory_differntial - = new_block_size - original_block_size; - std::size_t desired_use = used + memory_differntial; - if (desired_use > limit) { - // tell the Lua Virtual Machine - // to toss off (by returning nullptr) - return nullptr; - } - // alright now we have to expand this shit - // guess we use C's realloc - ptr = std::realloc(ptr, new_block_size); - if (ptr != nullptr) { - // alright, we successfully allocated some space - // track it - used = desired_use; - } - // even if we're null, let Lua crash and burn for us - return ptr; - } - - std::size_t used; - std::size_t limit; - std::size_t n_threads; - std::size_t n_tables; - std::size_t n_functions; - std::size_t n_userdata; - std::size_t n_strings; -}; - -struct my_type { - int a = 24; - bool b = false; - double d = 3.5; -}; - -#include - -int main() { - - std::cout << "=== memory tracker ===" << std::endl; - -#if SOL_LUAJIT_VERSION < 20100 && (UINTPTR_MAX > 0xFFFFFFFF) - std::cout << "LuaJIT in x64 mode on LuaJIT 2.0.X versions " - "does not support using a custom allocator!" - << std::endl; -#else - memory_tracker box; - std::cout << "memory at start: " << box.currently_used() - << " bytes / " << box.memory_limit() << " bytes" - << std::endl; - sol::state lua(&sol::default_at_panic, - &memory_tracker::allocate, - &box); - lua.open_libraries(sol::lib::base); - - std::cout << "memory after state creation: " - << box.currently_used() << " bytes / " - << box.memory_limit() << " bytes" << std::endl; - - // trigger some allocations - lua.new_usertype("my_type", - "a", - &my_type::a, - "b", - &my_type::b, - "d", - &my_type::d); - lua["f"] = [](std::string s) { return s + " woof!"; }; - - std::cout << "memory after function and usertype setup: " - << box.currently_used() << " bytes / " - << box.memory_limit() << " bytes" << std::endl; - - lua.safe_script("print(f('bark'))"); - lua.safe_script( - "local obj = my_type.new() print(obj.a, obj.b, obj.c) " - "obj.b = true print(obj.a, obj.b, obj.c)"); - - std::cout << "memory at end: " << box.currently_used() - << " bytes / " << box.memory_limit() << " bytes" - << std::endl; -#endif - return 0; -} diff --git a/third/sol2/examples/source/any_return.cpp b/third/sol2/examples/source/any_return.cpp deleted file mode 100644 index 7530effb..00000000 --- a/third/sol2/examples/source/any_return.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -// Uses some of the fancier bits of sol2, including the -// "transparent argument", sol::this_state, which gets the -// current state and does not increment function arguments -sol::object fancy_func( - sol::object a, sol::object b, sol::this_state s) { - sol::state_view lua(s); - if (a.is() && b.is()) { - return sol::object( - lua, sol::in_place, a.as() + b.as()); - } - else if (a.is()) { - bool do_triple = a.as(); - return sol::object(lua, - sol::in_place_type, - b.as() * (do_triple ? 3 : 1)); - } - // Can also use make_object - return sol::make_object(lua, sol::lua_nil); -} - -int main() { - sol::state lua; - - lua["f"] = fancy_func; - - int result = lua["f"](1, 2); - // result == 3 - sol_c_assert(result == 3); - double result2 = lua["f"](false, 2.5); - // result2 == 2.5 - sol_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 - sol_c_assert(result3 == 16.5); - - std::cout << "=== any_return ===" << std::endl; - std::cout << "result : " << result << std::endl; - std::cout << "result2: " << result2 << std::endl; - std::cout << "result3: " << result3 << std::endl; - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/args_from_container.cpp b/third/sol2/examples/source/args_from_container.cpp deleted file mode 100644 index 2f6d0e1f..00000000 --- a/third/sol2/examples/source/args_from_container.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include -#include - -int main(int, const char*[]) { - - std::cout << "=== args_from_container ===" << std::endl; - - sol::state lua; - lua.open_libraries(); - - lua.script("function f (a, b, c, d) print(a, b, c, d) end"); - - sol::function f = lua["f"]; - - std::vector v2 { 3, 4 }; - f(1, 2, sol::as_args(v2)); - - std::set v4 { 3, 1, 2, 4 }; - f(sol::as_args(v4)); - - int v3[] = { 2, 3, 4 }; - f(1, sol::as_args(v3)); - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/as_returns.cpp b/third/sol2/examples/source/as_returns.cpp deleted file mode 100644 index 4f18377a..00000000 --- a/third/sol2/examples/source/as_returns.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -#include -#include - -int main() { - sol::state lua; - - lua.set_function("f", []() { - std::set results { - "arf", "bark", "woof" - }; - return sol::as_returns(std::move(results)); - }); - - lua.script("v1, v2, v3 = f()"); - - std::string v1 = lua["v1"]; - 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"); - - return 0; -} diff --git a/third/sol2/examples/source/basic.cpp b/third/sol2/examples/source/basic.cpp deleted file mode 100644 index 592c98da..00000000 --- a/third/sol2/examples/source/basic.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - std::cout << "=== basic ===" << std::endl; - // create an empty lua state - sol::state lua; - - // by default, libraries are not opened - // you can open libraries by using open_libraries - // the libraries reside in the sol::lib enum class - lua.open_libraries(sol::lib::base); - // you can open all libraries by passing no arguments - // lua.open_libraries(); - - // call lua code directly - lua.script("print('hello world')"); - - // call lua code, and check to make sure it has loaded and - // run properly: - auto handler = &sol::script_default_on_error; - lua.script("print('hello again, world')", handler); - - // Use a custom error handler if you need it - // This gets called when the result is bad - auto simple_handler = - [](lua_State*, sol::protected_function_result result) { - // You can just pass it through to let the - // call-site handle it - return result; - }; - // the above lambda is identical to sol::simple_on_error, - // but it's shown here to show you can write whatever you - // like - - // - { - auto result = lua.script( - "print('hello hello again, world') \n return 24", - simple_handler); - if (result.valid()) { - std::cout << "the third script worked, and a " - "double-hello statement should " - "appear above this one!" - << std::endl; - int value = result; - sol_c_assert(value == 24); - } - else { - std::cout << "the third script failed, check the " - "result type for more information!" - << std::endl; - } - } - - { - auto result - = lua.script("does.not.exist", simple_handler); - if (result.valid()) { - std::cout << "the fourth script worked, which it " - "wasn't supposed to! Panic!" - << std::endl; - int value = result; - sol_c_assert(value == 24); - } - else { - sol::error err = result; - std::cout << "the fourth script failed, which " - "was intentional!\t\nError: " - << err.what() << std::endl; - } - } - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/c_array.cpp b/third/sol2/examples/source/c_array.cpp deleted file mode 100644 index beb3ae9b..00000000 --- a/third/sol2/examples/source/c_array.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -#include - -struct something { - int arr[4]; - - something() : arr { 5, 6, 7, 8 } { - } -}; - -int main() { - - std::cout << "=== c arrays (works with Visual C++ too) ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype( - "something", "arr", sol::property([](something& s) { - return std::ref(s.arr); - })); - lua.script(R"(s = something.new() - print(s.arr[3]) - s.arr[3] = 40 - print(s.arr[3]) - )"); - - 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); - - std::string string_array[] = { - "first string", - "second string", - "third string", - }; - lua["str_arr"] = std::ref(string_array); - // or: - // lua["str_array"] = &string_array; - lua.script(R"( - print(str_arr[3]) - str_arr[3] = str_arr[3] .. ': modified' - print(str_arr[3]) - )"); - - sol_c_assert(string_array[2] == "third string: modified"); - - return 0; -} diff --git a/third/sol2/examples/source/c_call.cpp b/third/sol2/examples/source/c_call.cpp deleted file mode 100644 index 17332ed2..00000000 --- a/third/sol2/examples/source/c_call.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -int f1(int) { - return 32; -} - -int f2(int, int) { - return 1; -} - -struct fer { - double f3(int, int) { - return 2.5; - } -}; - -int main() { - - sol::state lua; - // overloaded function f - lua.set("f", - sol::c_call, - sol::wrap, - sol::wrap>); - // singly-wrapped function - lua.set("g", sol::c_call>); - // without the 'sol::wrap' boilerplate - lua.set("h", sol::c_call); - // object used for the 'fer' member function call - lua.set("obj", fer()); - - // call them like any other bound function - lua.script("r1 = f(1)"); - lua.script("r2 = f(1, 2)"); - lua.script("r3 = f(obj, 1, 2)"); - lua.script("r4 = g(1)"); - lua.script("r5 = h(1, 2)"); - - // get the results and see - // if it worked out - int r1 = lua["r1"]; - sol_c_assert(r1 == 32); - int r2 = lua["r2"]; - sol_c_assert(r2 == 1); - double r3 = lua["r3"]; - sol_c_assert(r3 == 2.5); - int r4 = lua["r4"]; - sol_c_assert(r4 == 32); - int r5 = lua["r5"]; - sol_c_assert(r5 == 1); - - return 0; -} diff --git a/third/sol2/examples/source/calling_lua_functions.cpp b/third/sol2/examples/source/calling_lua_functions.cpp deleted file mode 100644 index 21a6b4da..00000000 --- a/third/sol2/examples/source/calling_lua_functions.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int func_1(int value) { - return 20 + value; -} - -std::string func_2(std::string text) { - return "received: " + text; -} - -sol::variadic_results fallback( - sol::this_state ts, sol::variadic_args args) { - sol::variadic_results r; - if (args.size() == 2) { - r.push_back({ ts, - sol::in_place, - args.get(0) + args.get(1) }); - } - else { - r.push_back({ ts, sol::in_place, 52 }); - } - return r; -} - -int main(int, char*[]) { - std::cout << "=== calling lua functions ===" << std::endl; - - sol::state lua; - lua.open_libraries(); - - sol::table mLuaPackets - = lua.create_named_table("mLuaPackets"); - mLuaPackets[1] = lua.create_table_with("timestamp", 0LL); - mLuaPackets[2] = lua.create_table_with("timestamp", 3LL); - mLuaPackets[3] = lua.create_table_with("timestamp", 1LL); - - lua.script("print('--- pre sort ---')"); - lua.script( - "for i=1,#mLuaPackets do print(i, " - "mLuaPackets[i].timestamp) end"); - - lua["table"]["sort"](mLuaPackets, - sol::as_function([](sol::table l, sol::table r) { - std::uint64_t tl = l["timestamp"]; - std::uint64_t tr = r["timestamp"]; - return tl < tr; - })); - - lua.script("print('--- post sort ---')"); - lua.script( - "for i=1,#mLuaPackets do print(i, " - "mLuaPackets[i].timestamp) end"); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/config.cpp b/third/sol2/examples/source/config.cpp deleted file mode 100644 index 1a586ad2..00000000 --- a/third/sol2/examples/source/config.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -// shows how to load basic data to a struct - -struct config { - std::string name; - int width; - int height; - - void print() { - std::cout << "Name: " << name << '\n' - << "Width: " << width << '\n' - << "Height: " << height << '\n'; - } -}; - -int main() { - sol::state lua; - config screen; - // To use the file, uncomment here and make sure it is in - // local dir lua.script_file("config.lua"); - lua.script(R"( -name = "Asus" -width = 1920 -height = 1080 -)"); - screen.name = lua.get("name"); - screen.width = lua.get("width"); - screen.height = lua.get("height"); - sol_c_assert(screen.name == "Asus"); - sol_c_assert(screen.width == 1920); - sol_c_assert(screen.height == 1080); - - std::cout << "=== config ===" << std::endl; - screen.print(); - std::cout << std::endl; -} diff --git a/third/sol2/examples/source/config.lua b/third/sol2/examples/source/config.lua deleted file mode 100644 index 0144f989..00000000 --- a/third/sol2/examples/source/config.lua +++ /dev/null @@ -1,3 +0,0 @@ -name = "Asus" -width = 1920 -height = 1080 diff --git a/third/sol2/examples/source/container_usertype_as_container.cpp b/third/sol2/examples/source/container_usertype_as_container.cpp deleted file mode 100644 index 6f55b40e..00000000 --- a/third/sol2/examples/source/container_usertype_as_container.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -#include - -class number_storage { -private: - std::vector data; - -public: - number_storage(int i) { - data.push_back(i); - } - - int accumulate() const { - return std::accumulate(data.begin(), data.end(), 0); - } - -public: - using value_type = decltype(data)::value_type; - using iterator = decltype(data)::iterator; - using size_type = decltype(data)::size_type; - iterator begin() { - return iterator(data.begin()); - } - iterator end() { - return iterator(data.end()); - } - size_type size() const noexcept { - return data.size(); - } - size_type max_size() const noexcept { - return data.max_size(); - } - void push_back(int value) { - data.push_back(value); - } - bool empty() const noexcept { - return data.empty(); - } -}; - -namespace sol { - template <> - struct is_container : std::false_type { }; -} // namespace sol - -int main(int, char*[]) { - std::cout << "=== container as container ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("number_storage", - sol::constructors(), - "accumulate", - &number_storage::accumulate, - "iterable", - [](number_storage& ns) { - return sol::as_container( - ns); // treat like a container, despite - // is_container specialization - }); - - lua.script(R"( -ns = number_storage.new(23) -print("accumulate before:", ns:accumulate()) - --- reference original usertype like a container -ns_container = ns:iterable() -ns_container:add(24) -ns_container:add(25) - --- now print to show effect -print("accumulate after :", ns:accumulate()) - )"); - - number_storage& ns = lua["ns"]; - number_storage& ns_container = lua["ns_container"]; - sol_c_assert(&ns == &ns_container); - sol_c_assert(ns.size() == 3); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/container_with_pairs.cpp b/third/sol2/examples/source/container_with_pairs.cpp deleted file mode 100644 index 14e5955d..00000000 --- a/third/sol2/examples/source/container_with_pairs.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -#include -#include - -int main() { - struct hasher { - typedef std::pair - argument_type; - typedef std::size_t result_type; - - result_type operator()(const argument_type& p) const { - return std::hash()(p.first); - } - }; - - using my_set = std::unordered_set< - std::pair, - hasher>; - - std::cout << "=== containers with std::pair<> ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.set_function("f", []() { - return my_set { { "key1", "value1" }, - { "key2", "value2" }, - { "key3", "value3" } }; - }); - - lua.safe_script("v = f()"); - lua.safe_script("print('v:', v)"); - lua.safe_script("print('#v:', #v)"); - // note that using my_obj:pairs() is a - // way around pairs(my_obj) not working in Lua 5.1/LuaJIT: - // try it! - lua.safe_script( - "for k,v1,v2 in v:pairs() do print(k, v1, v2) end"); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/containers.cpp b/third/sol2/examples/source/containers.cpp deleted file mode 100644 index 105e91f8..00000000 --- a/third/sol2/examples/source/containers.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -int main(int, char**) { - std::cout << "=== containers ===" << std::endl; - - sol::state lua; - lua.open_libraries(); - - lua.script(R"( -function f (x) - print("container has:") - for k=1,#x do - v = x[k] - print("\t", k, v) - end - print() -end - )"); - - // Have the function we - // just defined in Lua - sol::function f = lua["f"]; - - // Set a global variable called - // "arr" to be a vector of 5 lements - lua["arr"] = std::vector { 2, 4, 6, 8, 10 }; - - // Call it, see 5 elements - // printed out - f(lua["arr"]); - - // Mess with it in C++ - // Containers are stored as userdata, unless you - // use `sol::as_table()` and `sol::as_table_t`. - std::vector& reference_to_arr = lua["arr"]; - reference_to_arr.push_back(12); - - // Call it, see *6* elements - // printed out - f(lua["arr"]); - - lua.script(R"( -arr:add(28) - )"); - - // Call it, see *7* elements - // printed out - f(lua["arr"]); - - lua.script(R"( -arr:clear() - )"); - - // Now it's empty - f(lua["arr"]); - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/containers_as_table.cpp b/third/sol2/examples/source/containers_as_table.cpp deleted file mode 100644 index 1a8c9063..00000000 --- a/third/sol2/examples/source/containers_as_table.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include -#include - - -// nested allows serialization of maps with vectors inside, and -// vice-versa all from a nested structure of Lua tables it has -// less control over which pieces are considered tables in Lua, -// and which ones are considered userdata, but it covers a good -// 90% of cases where someone wants to handle a nested table -void demo( - sol::nested>> - src) { - std::cout << "demo, sol::nested<...>" << std::endl; - const auto& listmap = src.value(); - sol_c_assert(listmap.size() == 2); - for (const auto& kvp : listmap) { - const std::vector& strings = kvp.second; - sol_c_assert(strings.size() == 3); - std::cout << "\t" << kvp.first << " = "; - for (const auto& s : strings) { - std::cout << "'" << s << "'" - << " "; - } - std::cout << std::endl; - } - std::cout << std::endl; -} - -// This second demo is equivalent to the first -// Nota bene the signature here -// Every container-type that's meant to be -// a table must be wrapped in `sol::as_table_t` -// it's verbose, so feel free to use typedefs to make it easy on -// you you can mix which parts are considered tables from Lua, -// and which parts are considered other kinds of types, such as -// userdata and the like -void demo_explicit(sol::as_table_t>>> - src) { - std::cout << "demo, explicit sol::as_table_t<...>" - << std::endl; - // Have to access the "source" member variable for - // as_table_t - const auto& listmap = src.value(); - sol_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.value(); - sol_c_assert(strings.size() == 3); - std::cout << "\t" << kvp.first << " = "; - for (const auto& s : strings) { - std::cout << "'" << s << "'" - << " "; - } - std::cout << std::endl; - } - std::cout << std::endl; -} - -int main(int, char**) { - std::cout << "=== containers retrieved from lua tables ===" - << std::endl; - - sol::state lua; - // bind the function - lua.set_function("f", &demo); - lua.set_function("g", &demo_explicit); - // Call it with a table that has string sequences set to - // distinct keys - lua.script(R"( -t = { - key1 = {'hello', 'there', 'world'}, - key2 = {'bark', 'borf', 'woof'} -} -f(t) -g(t) - )"); - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/coroutine.cpp b/third/sol2/examples/source/coroutine.cpp deleted file mode 100644 index 81994787..00000000 --- a/third/sol2/examples/source/coroutine.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -int main() { - std::cout << "=== coroutine ===" << std::endl; - - sol::state lua; - std::vector tasks; - - lua.open_libraries(sol::lib::base, sol::lib::coroutine); - - sol::thread runner_thread = sol::thread::create(lua); - - lua.set_function("start_task", - [&runner_thread, &tasks]( - sol::function f, sol::variadic_args va) { - // You must ALWAYS get the current state - sol::state_view runner_thread_state - = runner_thread.state(); - // Put the task in our task list to keep it alive - // and track it - std::size_t task_index = tasks.size(); - tasks.emplace_back(runner_thread_state, f); - sol::coroutine& f_on_runner_thread - = tasks[task_index]; - // call coroutine with arguments that came - // from main thread / other thread - // pusher for `variadic_args` and other sol types - // will transfer the arguments from the calling - // thread to the runner thread automatically for - // you using `lua_xmove` internally - int wait = f_on_runner_thread(va); - std::cout << "First return: " << wait - << std::endl; - // When you call it again, you don't need new - // arguments (they remain the same from the first - // call) - f_on_runner_thread(); - std::cout << "Second run complete: " << wait - << std::endl; - }); - - lua.script( - R"( -function main(x, y, z) - -- do something - coroutine.yield(20) - -- do something else - -- do ... - print(x, y, z) -end - -function main2(x, y) - coroutine.yield(10) - print(x, y) -end - - start_task(main, 10, 12, 8) - start_task(main2, 1, 2) -)"); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/coroutine_multiple_stacks.cpp b/third/sol2/examples/source/coroutine_multiple_stacks.cpp deleted file mode 100644 index 2b6a36cb..00000000 --- a/third/sol2/examples/source/coroutine_multiple_stacks.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -int main() { - std::cout << "=== coroutine - multple threads ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base, - sol::lib::package, - sol::lib::coroutine); - - lua["print"] = [](sol::object v) { - std::cout << v.as() << std::endl; - }; - lua["cyield"] = sol::yielding( - []() { std::cout << "YIELDING" << std::endl; }); - - // notice the new threads! - sol::thread thread1 = sol::thread::create(lua); - sol::thread thread2 = sol::thread::create(lua); - - // notice we load it FROM the new "execution stack" - // we need it to have thread1's stack perspective - sol::coroutine co1 = thread1.state().load(R"( - print("AA : Step 1") - cyield() - print("AA : Step 2") - )"); - // call first coroutine here - co1(); - - // notice we load it FROM the new "execution stack" - // we need it to have thread2's stack and perspective - sol::coroutine co2 = thread2.state().load(R"( - print("BB : Step 1") - cyield() - print("BB : Step 2") - )"); - - // run the other coroutine - co2(); - co1(); - // tada! they run on - // independent stacks - - return 0; -} diff --git a/third/sol2/examples/source/coroutine_state.cpp b/third/sol2/examples/source/coroutine_state.cpp deleted file mode 100644 index 0845470e..00000000 --- a/third/sol2/examples/source/coroutine_state.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main(int, char*[]) { - std::cout << "=== coroutine state transfer ===" - << std::endl; - - sol::state lua; - lua.open_libraries(); - sol::function transferred_into; - lua["f"] = [&lua, &transferred_into]( - sol::object t, sol::this_state this_L) { - std::cout << "state of main : " - << (void*)lua.lua_state() << std::endl; - std::cout << "state of function : " - << (void*)this_L.lua_state() << std::endl; - // pass original lua_State* (or - // sol::state/sol::state_view) transfers ownership from - // the state of "t", to the "lua" sol::state - transferred_into = sol::function(lua, t); - }; - - lua.script(R"( - i = 0 - function test() - co = coroutine.create( - function() - local g = function() i = i + 1 end - f(g) - g = nil - collectgarbage() - end - ) - coroutine.resume(co) - co = nil - collectgarbage() - end - )"); - - // give it a try - lua.safe_script("test()"); - // should call 'g' from main thread, increment i by 1 - transferred_into(); - // check - int i = lua["i"]; - sol_c_assert(i == 1); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/custom_reader.cpp b/third/sol2/examples/source/custom_reader.cpp deleted file mode 100644 index fbe8083e..00000000 --- a/third/sol2/examples/source/custom_reader.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -#include -#include -#include - -struct custom_reader { - FILE* f; - // We use 2 here to demonstrate - // multiple calls to the function to - // parse whole file. - // Please don't use 2. - // PLEASE DO NOT USE A BUFFER - // OF SIZE 2! - char buffer[2]; - std::size_t current_size; - std::size_t read_count; - - custom_reader(FILE* f_) - : f(f_), buffer(), current_size(0), read_count(0) { - } - - bool read() { - std::cout << "custom read: read #" << ++read_count - << std::endl; - current_size = fread(buffer, 1, 2, f); - return current_size > 0 && ferror(f) == 0; - } - - ~custom_reader() { - std::fclose(f); - } -}; - -// function must match signature found in type lua_Reader: -// const char* ( lua_State*, void*, size_t* ) -const char* custom_reader_function( - lua_State*, void* pointer_to_my_object, size_t* data_size) { - custom_reader& cr - = *(static_cast(pointer_to_my_object)); - if (cr.read()) { - *data_size = cr.current_size; - return cr.buffer; - } - else { - *data_size = 0; - return nullptr; - } -} - -int main() { - std::cout << "=== custom reader ===" << std::endl; - - // make a file to use for the custom reader - { - std::ofstream bjork("bjork.lua", std::ios::binary); - bjork << "print('hello!')\n"; - } - struct on_scope_exit { - ~on_scope_exit() { - // remove file when done - std::remove("bjork.lua"); - } - } remove_on_exit; - - - sol::state lua; - lua.open_libraries(sol::lib::base); - - FILE* bjork_fp; -#ifdef _MSC_VER - if (fopen_s(&bjork_fp, "bjork.lua", "r") != 0) { - std::cerr << "failed to open bjork.lua -- exiting" - << std::endl; - return -1; - } -#else - bjork_fp = fopen("bjork.lua", "r"); -#endif - if (bjork_fp == nullptr) { - std::cerr << "failed to open bjork.lua -- exiting" - << std::endl; - return -1; - } - custom_reader reader(bjork_fp); - - // load the code using our custom reader, then run it - auto result = lua.safe_script(custom_reader_function, - &reader, - sol::script_pass_on_error); - // make sure we ran loaded and ran the code successfully - sol_c_assert(result.valid()); - - // note there are lua.load( ... ) variants that take a - // custom reader than JUST run the code, too! - - std::cout << std::endl; - return 0; -} diff --git a/third/sol2/examples/source/customization_base_object_catch.cpp b/third/sol2/examples/source/customization_base_object_catch.cpp deleted file mode 100644 index 13a35b82..00000000 --- a/third/sol2/examples/source/customization_base_object_catch.cpp +++ /dev/null @@ -1,214 +0,0 @@ -#include -#include - -// We capture the base objects -// lifetime style -// You can add more here, -// e.g. "Unique" for a unique pointer kind of lifestyle, -// but you would need to think about how to handle -// copying / moving in that case -enum class BaseObjectLifetime { Value, Pointer, Shared }; - -// The base object -// that we do inheritance and other work -// on -class BaseObject { -public: - BaseObject() { - objectType = 0; - } - - unsigned int getObjectType() const { - return objectType; - } - - bool doArmorThing() const { - return false; - } - bool doWeaponThing() const { - return false; - } - - // helper function defined later after we define all the - // base classes we care about - sol::object getAsRetyped( - lua_State* L, BaseObjectLifetime Lifetime) const; - - // For convenience with the customization points below - int pushAsRetyped( - lua_State* L, BaseObjectLifetime Lifetime) const { - return getAsRetyped(L, Lifetime).push(L); - } - -protected: - unsigned int objectType; -}; - -class Armor : public BaseObject { -public: - Armor() { - objectType = 1; - } - - bool doArmorThing() const { - return true; - } -}; - -class Weapon : public BaseObject { -public: - Weapon() { - objectType = 2; - } - - bool doWeaponThing() const { - return true; - } -}; - -// Get the most-derived type -// that we care about from the base object, -// obeying the lifetime type -sol::object BaseObject::getAsRetyped( - lua_State* L, BaseObjectLifetime Lifetime) const { - switch (objectType) { - case 1: - std::cout << "Retyping as armor." << std::endl; - switch (Lifetime) { - case BaseObjectLifetime::Pointer: - return sol::make_object( - L, static_cast(this)); - case BaseObjectLifetime::Shared: - return sol::make_object(L, - std::make_shared( - *static_cast(this))); - case BaseObjectLifetime::Value: - default: - return sol::make_object( - L, *static_cast(this)); - } - case 2: - std::cout << "Retyping as weapon." << std::endl; - switch (Lifetime) { - case BaseObjectLifetime::Pointer: - return sol::make_object( - L, static_cast(this)); - case BaseObjectLifetime::Shared: - return sol::make_object(L, - std::make_shared( - *static_cast(this))); - case BaseObjectLifetime::Value: - default: - return sol::make_object( - L, *static_cast(this)); - } - default: - std::cout - << "Unknown type: falling back to base object." - << std::endl; - // we have a normal type here, so that means we - // must bypass typical customization points by using - // sol::make_object_userdata/sol::make_reference_userdata - // WARNING: IF THIS TYPE IS IN FACT NOT A BASE OBJECT, - // BUT SOME DERIVED OBJECT, THEN RUNNING THIS CODE FOR - // VALUE TYPES AND SHARED TYPES WILL "SLICE" - // THE DERIVED BITS OFF THE BASE BITS PERMANENTLY - // NEVER FORGET TO UPDATE THE SWITCH IF YOU ADD - // NEW TYPES!! - switch (Lifetime) { - case BaseObjectLifetime::Value: - return sol::make_object_userdata(L, *this); - case BaseObjectLifetime::Shared: - return sol::make_object_userdata( - L, std::make_shared(*this)); - case BaseObjectLifetime::Pointer: - default: - return sol::make_object_userdata(L, this); - } - } -} - -// -// sol customization points -// - -// Defining a customization point that lets us put the correct -// object type on the stack. -int sol_lua_push(sol::types, lua_State* L, - const BaseObject& obj) { - return obj.pushAsRetyped(L, BaseObjectLifetime::Value); -} -int sol_lua_push(sol::types, lua_State* L, - const BaseObject* obj) { - return obj->pushAsRetyped(L, BaseObjectLifetime::Pointer); -} -int sol_lua_push(sol::types>, - lua_State* L, const std::shared_ptr& obj) { - return obj->pushAsRetyped(L, BaseObjectLifetime::Shared); -} - -int main() { - // test our customization points out - std::cout << "=== Base object customization points ===" - << std::endl; - - sol::state lua; - lua.open_libraries( - sol::lib::base, sol::lib::string, sol::lib::table); - - lua["objectCache"] = lua.create_table(); - - // Do basic type binding. - auto luaBaseObject - = lua.new_usertype("tes3baseObject"); - luaBaseObject["objectType"] - = sol::readonly_property(&BaseObject::getObjectType); - luaBaseObject["doArmorThing"] = &BaseObject::doArmorThing; - luaBaseObject["doWeaponThing"] = &BaseObject::doWeaponThing; - auto luaArmorObject = lua.new_usertype("tes3armor"); - luaArmorObject[sol::base_classes] - = sol::bases(); - luaArmorObject["doArmorThing"] = &Armor::doArmorThing; - auto luaWeaponObject - = lua.new_usertype("tes3weapon"); - luaWeaponObject[sol::base_classes] - = sol::bases(); - luaWeaponObject["doWeaponThing"] = &Weapon::doWeaponThing; - - // Objects we'll play with. - BaseObject base; - Armor armor; - Weapon weapon; - - // Push some objects to lua. - std::cout << "Normal pointers..." << std::endl; - lua["ptrBase"] = &base; - lua["ptrArmor"] = &armor; - lua["ptrWeapon"] = &weapon; - std::cout << std::endl; - - // Same objects but as base objects to test mapping. - std::cout << "Base-cast pointers..." << std::endl; - lua["ptrBaseAsBase"] = static_cast(&base); - lua["ptrArmorAsBase"] = static_cast(&armor); - lua["ptrWeaponAsBase"] = static_cast(&weapon); - std::cout << std::endl; - - std::cout << "Smart direct pointers..." << std::endl; - lua["sharedBase"] = std::make_shared(); - lua["sharedArmor"] = std::make_shared(); - lua["sharedArmor"] = std::make_shared(); - std::cout << std::endl; - - std::cout << "Smart pointers put as the base class..." - << std::endl; - lua["sharedBaseAsBase"] = (std::shared_ptr) - std::make_shared(); - lua["sharedArmorAsBase"] = (std::shared_ptr) - std::make_shared(); - lua["sharedArmorAsBase"] = (std::shared_ptr) - std::make_shared(); - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/customization_convert_on_get.cpp b/third/sol2/examples/source/customization_convert_on_get.cpp deleted file mode 100644 index d7b0ed96..00000000 --- a/third/sol2/examples/source/customization_convert_on_get.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -struct number_shim { - double num = 0; -}; - -template -bool sol_lua_check(sol::types, lua_State* L, - int index, Handler&& handler, - sol::stack::record& tracking) { - // check_usertype is a backdoor for directly checking sol2 - // usertypes - if (!sol::stack::check_usertype(L, index) - && !sol::stack::check(L, index)) { - handler(L, - index, - sol::type_of(L, index), - sol::type::userdata, - "expected a number_shim or a number"); - return false; - } - tracking.use(1); - return true; -} - -number_shim sol_lua_get(sol::types, lua_State* L, - int index, sol::stack::record& tracking) { - if (sol::stack::check_usertype(L, index)) { - number_shim& ns - = sol::stack::get_usertype( - L, index, tracking); - return ns; - } - number_shim ns {}; - ns.num = sol::stack::get(L, index, tracking); - return ns; -} - -int main() { - sol::state lua; - - // Create a pass-through style of function - lua.safe_script("function f ( a ) return a end"); - lua.set_function("g", [](double a) { - number_shim ns; - ns.num = a; - return ns; - }); - - lua.script("vf = f(25) vg = g(35)"); - - number_shim thingsf = lua["vf"]; - number_shim thingsg = lua["vg"]; - - sol_c_assert(thingsf.num == 25); - sol_c_assert(thingsg.num == 35); - - return 0; -} diff --git a/third/sol2/examples/source/customization_global_transparent_argument.cpp b/third/sol2/examples/source/customization_global_transparent_argument.cpp deleted file mode 100644 index 33cb7110..00000000 --- a/third/sol2/examples/source/customization_global_transparent_argument.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -// Something that can't be collided with -static const auto& script_key - = "GlobalResource.MySpecialIdentifier123"; - -struct GlobalResource { - int value = 2; -}; - -template -bool sol_lua_check(sol::types, lua_State* L, - int /*index*/, Handler&& handler, - sol::stack::record& tracking) { - // not actually taking anything off the stack - tracking.use(0); - // get the field from global storage - sol::stack::get_field(L, script_key); - // verify type - sol::type t = static_cast(lua_type(L, -1)); - lua_pop(L, 1); - if (t != sol::type::lightuserdata) { - handler(L, - 0, - sol::type::lightuserdata, - t, - "global resource is not present as a light " - "userdata"); - return false; - } - return true; -} - -GlobalResource* sol_lua_get(sol::types, - lua_State* L, int /*index*/, sol::stack::record& tracking) { - // retrieve the (light) userdata for this type - - // not actually pulling anything off the stack - tracking.use(0); - sol::stack::get_field(L, script_key); - GlobalResource* ls - = static_cast(lua_touserdata(L, -1)); - - // clean up stack value returned by `get_field` - lua_pop(L, 1); - return ls; -} - -int sol_lua_push(sol::types, lua_State* L, - GlobalResource* ls) { - // push light userdata - return sol::stack::push(L, static_cast(ls)); -} - -int main() { - - sol::state lua; - lua.open_libraries(sol::lib::base); - - GlobalResource instance; - - // get GlobalResource - lua.set_function("f", [](GlobalResource* l, int value) { - return l->value + value; - }); - lua.set(script_key, &instance); - - // note only 1 argument, - // despite f having 2 arguments to recieve - lua.script("assert(f(1) == 3)"); - - return 0; -} diff --git a/third/sol2/examples/source/customization_multiple.cpp b/third/sol2/examples/source/customization_multiple.cpp deleted file mode 100644 index 193ea8c4..00000000 --- a/third/sol2/examples/source/customization_multiple.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct two_things { - int a; - bool b; -}; - -template -bool sol_lua_check(sol::types, lua_State* L, - int index, Handler&& handler, - sol::stack::record& tracking) { - // indices can be negative to count backwards from the top - // of the stack, rather than the bottom up to deal with - // this, we adjust the index to its absolute position using - // the lua_absindex function - int absolute_index = lua_absindex(L, index); - // Check first and second second index for being the proper - // types - bool success - = sol::stack::check(L, absolute_index, handler) - && sol::stack::check( - L, absolute_index + 1, handler); - tracking.use(2); - return success; -} - -two_things sol_lua_get(sol::types, lua_State* L, - int index, sol::stack::record& tracking) { - int absolute_index = lua_absindex(L, index); - // Get the first element - int a = sol::stack::get(L, absolute_index); - // Get the second element, - // in the +1 position from the first - bool b = sol::stack::get(L, absolute_index + 1); - // we use 2 slots, each of the previous takes 1 - tracking.use(2); - return two_things { a, b }; -} - -int sol_lua_push(lua_State* L, const two_things& things) { - int amount = sol::stack::push(L, things.a); - // amount will be 1: int pushes 1 item - amount += sol::stack::push(L, things.b); - // amount 2 now, since bool pushes a single item - // Return 2 things - return amount; -} - -int main() { - std::cout << "=== customization ===" << std::endl; - std::cout << std::boolalpha; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // Create a pass-through style of function - lua.script( - "function f ( a, b ) print(a, b) return a, b end"); - - // get the function out of Lua - sol::function f = lua["f"]; - - two_things things = f(two_things { 24, false }); - sol_c_assert(things.a == 24); - sol_c_assert(things.b == false); - // things.a == 24 - // things.b == true - - std::cout << "things.a: " << things.a << std::endl; - std::cout << "things.b: " << things.b << std::endl; - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/docs/as_function.cpp b/third/sol2/examples/source/docs/as_function.cpp deleted file mode 100644 index b86c05cf..00000000 --- a/third/sol2/examples/source/docs/as_function.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -int main() { - struct callable { - int operator()(int a, bool b) { - return a + (b ? 10 : 20); - } - }; - - - sol::state lua; - // Binds struct as userdata - // can still be callable, but beware - // caveats - lua.set("not_func", callable()); - // Binds struct as function - lua.set("func", sol::as_function(callable())); - // equivalent: lua.set_function( "func", callable() ); - // equivalent: lua["func"] = callable(); -} diff --git a/third/sol2/examples/source/docs/as_function_usertype_member_variable.cpp b/third/sol2/examples/source/docs/as_function_usertype_member_variable.cpp deleted file mode 100644 index d7c2ac58..00000000 --- a/third/sol2/examples/source/docs/as_function_usertype_member_variable.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -int main() { - class B { - public: - int bvar = 24; - }; - - sol::state lua; - lua.open_libraries(sol::lib::base); - lua.new_usertype("B", - // bind as variable - "b", - &B::bvar, - // bind as function - "f", - sol::as_function(&B::bvar)); - - B b; - lua.set("b", &b); - lua.script(R"(x = b:f() - y = b.b - assert(x == 24) - assert(y == 24) - )"); - - return 0; -} diff --git a/third/sol2/examples/source/docs/as_table_ipairs.cpp b/third/sol2/examples/source/docs/as_table_ipairs.cpp deleted file mode 100644 index 972216b6..00000000 --- a/third/sol2/examples/source/docs/as_table_ipairs.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main(int, char*[]) { - - sol::state lua; - lua.open_libraries(); - lua.set("my_table", - sol::as_table(std::vector { 1, 2, 3, 4, 5 })); - lua.script( - "for k, v in ipairs(my_table) do print(k, v) assert(k " - "== v) end"); - - return 0; -} diff --git a/third/sol2/examples/source/docs/coroutine_main.cpp b/third/sol2/examples/source/docs/coroutine_main.cpp deleted file mode 100644 index dfb68511..00000000 --- a/third/sol2/examples/source/docs/coroutine_main.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#define SOL_ALL_SAFTIES_ON 1 -#include - -#include - -int main() { - const auto& co_lua_script = R"( -function loop() - while counter ~= 30 - do - coroutine.yield(counter); - counter = counter + 1; - end - return counter -end -)"; - - sol::state lua; - lua.open_libraries(sol::lib::base, sol::lib::coroutine); - /* - lua.script_file("co.lua"); - we load string directly rather than use a file - */ - lua.script(co_lua_script); - sol::coroutine loop_coroutine = lua["loop"]; - // set counter variable in C++ - // (can set it to something else to - // have loop_coroutine() yield different values) - lua["counter"] = 20; - - // example of using and re-using coroutine - // you do not have to use coroutines in a loop, - // this is just the example - - // we start from 0; - // we want 10 values, and we only want to - // run if the coroutine "loop_coroutine" is valid - for (int counter = 0; counter < 10 && loop_coroutine; - ++counter) { - // Alternative: counter < 10 && cr.valid() - - // Call the coroutine, does the computation and then - // suspends once it returns, we get the value back from - // the return and then can use it we can either leave - // the coroutine like that can come to it later, or - // loop back around - int value = loop_coroutine(); - std::cout << "In C++: " << value << std::endl; - } - - return 0; -} diff --git a/third/sol2/examples/source/docs/coroutine_thread.cpp b/third/sol2/examples/source/docs/coroutine_thread.cpp deleted file mode 100644 index 1f2b3b6b..00000000 --- a/third/sol2/examples/source/docs/coroutine_thread.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#define SOL_ALL_SAFTIES_ON 1 -#include - -#include - -int main() { - const auto& co_lua_script = R"( -function loop() - while counter ~= 30 - do - coroutine.yield(counter); - counter = counter + 1; - end - return counter -end -)"; - - sol::state lua; - lua.open_libraries(sol::lib::base, sol::lib::coroutine); - /* - lua.script_file("co.lua"); - we load string directly rather than use a file - */ - lua.script(co_lua_script); - sol::thread runner = sol::thread::create(lua.lua_state()); - sol::state_view runnerstate = runner.state(); - sol::coroutine loop_coroutine = runnerstate["loop"]; - lua["counter"] = 20; - - for (int counter = 0; counter < 10 && loop_coroutine; - ++counter) { - // Call the coroutine, does the computation and then - // suspends - int value = loop_coroutine(); - std::cout << "value is " << value << std::endl; - } - - return 0; -} diff --git a/third/sol2/examples/source/docs/inheritance.cpp b/third/sol2/examples/source/docs/inheritance.cpp deleted file mode 100644 index a4d12692..00000000 --- a/third/sol2/examples/source/docs/inheritance.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -struct A { - int a = 10; - virtual int call() { - return 0; - } - virtual ~A() { - } -}; -struct B : A { - int b = 11; - virtual int call() override { - return 20; - } -}; - -int main(int, char*[]) { - - sol::state lua; - - lua.new_usertype("A", "call", &A::call); - - lua.new_usertype("B", - "call", - &B::call, - sol::base_classes, - sol::bases()); - - return 0; -} diff --git a/third/sol2/examples/source/docs/my_panic.cpp b/third/sol2/examples/source/docs/my_panic.cpp deleted file mode 100644 index 443a7b77..00000000 --- a/third/sol2/examples/source/docs/my_panic.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include -#include - -inline void my_panic(sol::optional maybe_msg) { - std::cerr << "Lua is in a panic state and will now abort() " - "the application" - << std::endl; - if (maybe_msg) { - const std::string& msg = maybe_msg.value(); - std::cerr << "\terror message: " << msg << std::endl; - } - // When this function exits, Lua will exhibit default - // behavior and abort() -} - -int main(int, char*[]) { - sol::state lua(sol::c_call); - // or, if you already have a lua_State* L - // lua_atpanic( L, sol::c_call ); or, with state/state_view: sol::state_view - // lua(L); lua.set_panic( sol::c_call ); - - // uncomment the below to see - // lua.script("boom_goes.the_dynamite"); - - return 0; -} diff --git a/third/sol2/examples/source/docs/preparing_environments.cpp b/third/sol2/examples/source/docs/preparing_environments.cpp deleted file mode 100644 index fa19bc69..00000000 --- a/third/sol2/examples/source/docs/preparing_environments.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -int main(int, char*[]) { - sol::state lua; - lua.open_libraries(); - sol::environment my_env(lua, sol::create); - // set value, and we need to explicitly allow for - // access to "print", since a new environment hides - // everything that's not defined inside of it - // NOTE: hiding also hides library functions (!!) - // BE WARNED - my_env["var"] = 50; - my_env["print"] = lua["print"]; - - sol::environment my_other_env( - lua, sol::create, lua.globals()); - // do not need to explicitly allow access to "print", - // since we used the "Set a fallback" version - // of the sol::environment constructor - my_other_env["var"] = 443; - - // output: 50 - lua.script("print(var)", my_env); - - // output: 443 - lua.script("print(var)", my_other_env); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/docs/references_in_lambdas.cpp b/third/sol2/examples/source/docs/references_in_lambdas.cpp deleted file mode 100644 index 82101449..00000000 --- a/third/sol2/examples/source/docs/references_in_lambdas.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - - struct test { - int blah = 0; - }; - - test t; - sol::state lua; - lua.set_function("f", [&t]() { return t; }); - lua.set_function("g", [&t]() -> test& { return t; }); - - lua.script("t1 = f()"); - lua.script("t2 = g()"); - - test& from_lua_t1 = lua["t1"]; - test& from_lua_t2 = lua["t2"]; - - // not the same: 'f' lambda copied - sol_c_assert(&from_lua_t1 != &t); - // the same: 'g' lambda returned reference - sol_c_assert(&from_lua_t2 == &t); - - return 0; -} diff --git a/third/sol2/examples/source/docs/runtime_extension.cpp b/third/sol2/examples/source/docs/runtime_extension.cpp deleted file mode 100644 index ae9be8f7..00000000 --- a/third/sol2/examples/source/docs/runtime_extension.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct object { - int value = 0; -}; - -int main(int, char*[]) { - - std::cout << "==== runtime_extension =====" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("object"); - - // runtime additions: through the sol API - lua["object"]["func"] = [](object& o) { return o.value; }; - // runtime additions: through a lua script - lua.script( - "function object:print () print(self:func()) end"); - - // see it work - lua.script("local obj = object.new() \n obj:print()"); - - return 0; -} diff --git a/third/sol2/examples/source/docs/simple_functions.cpp b/third/sol2/examples/source/docs/simple_functions.cpp deleted file mode 100644 index d9921f2a..00000000 --- a/third/sol2/examples/source/docs/simple_functions.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 - -#include - -int main() { - sol::state lua; - int x = 0; - lua.set_function("beep", [&x] { ++x; }); - lua.script("beep()"); - sol_c_assert(x == 1); - - sol::function beep = lua["beep"]; - beep(); - sol_c_assert(x == 2); - - return 0; -} diff --git a/third/sol2/examples/source/docs/simple_structs.cpp b/third/sol2/examples/source/docs/simple_structs.cpp deleted file mode 100644 index 8ba4adb5..00000000 --- a/third/sol2/examples/source/docs/simple_structs.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 - -#include - -struct vars { - int boop = 0; - - int bop() const { - return boop + 1; - } -}; - -int main() { - sol::state lua; - lua.new_usertype( - "vars", "boop", &vars::boop, "bop", &vars::bop); - lua.script( - "beep = vars.new()\n" - "beep.boop = 1\n" - "bopvalue = beep:bop()"); - - vars& beep = lua["beep"]; - int bopvalue = lua["bopvalue"]; - - sol_c_assert(beep.boop == 1); - sol_c_assert(lua.get("beep").boop == 1); - sol_c_assert(beep.bop() == 2); - sol_c_assert(bopvalue == 2); - - return 0; -} diff --git a/third/sol2/examples/source/docs/state_script_safe.cpp b/third/sol2/examples/source/docs/state_script_safe.cpp deleted file mode 100644 index 34f2e9a8..00000000 --- a/third/sol2/examples/source/docs/state_script_safe.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - - std::cout << "=== safe_script usage ===" << std::endl; - - sol::state lua; - // uses sol::script_default_on_error, which either panics or - // throws, depending on your configuration and compiler - // settings - try { - auto result1 = lua.safe_script("bad.code"); - } - catch (const sol::error& e) { - std::cout << "an expected error has occurred: " - << e.what() << std::endl; - } - - // a custom handler that you write yourself - // is only called when an error happens with loading or - // running the script - auto result2 = lua.safe_script("123 bad.code", - [](lua_State*, sol::protected_function_result pfr) { - // pfr will contain things that went wrong, for - // either loading or executing the script the user - // can do whatever they like here, including - // throw. Otherwise... - sol::error err = pfr; - std::cout - << "An error (an expected one) occurred: " - << err.what() << std::endl; - - // ... they need to return the - // protected_function_result - return pfr; - }); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/docs/state_transfer.cpp b/third/sol2/examples/source/docs/state_transfer.cpp deleted file mode 100644 index af114daa..00000000 --- a/third/sol2/examples/source/docs/state_transfer.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 - -#include - -#include - -int main(int, char*[]) { - - sol::state lua; - lua.open_libraries(); - sol::function transferred_into; - lua["f"] = [&lua, &transferred_into]( - sol::object t, sol::this_state this_L) { - std::cout << "state of main : " - << (void*)lua.lua_state() << std::endl; - std::cout << "state of function : " - << (void*)this_L.lua_state() << std::endl; - // pass original lua_State* (or - // sol::state/sol::state_view) transfers ownership from - // the state of "t", to the "lua" sol::state - transferred_into = sol::function(lua, t); - }; - - lua.script(R"( - i = 0 - function test() - co = coroutine.create( - function() - local g = function() i = i + 1 end - f(g) - g = nil - collectgarbage() - end - ) - coroutine.resume(co) - co = nil - collectgarbage() - end - )"); - - // give it a try - lua.safe_script("test()"); - // should call 'g' from main thread, increment i by 1 - transferred_into(); - // check - int i = lua["i"]; - sol_c_assert(i == 1); - - return 0; -} diff --git a/third/sol2/examples/source/docs/std_thread.cpp b/third/sol2/examples/source/docs/std_thread.cpp deleted file mode 100644 index 3c767289..00000000 --- a/third/sol2/examples/source/docs/std_thread.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include -#include -#include -#include -#include - -struct worker_data { - std::mutex until_ready_mutex; - std::condition_variable until_ready_condition; - bool is_ready = false; - bool is_processed = false; - sol::state worker_lua; - sol::bytecode payload; - std::variant> return_payload; - - worker_data() { - worker_lua.open_libraries(sol::lib::base); - } -}; - -void worker_thread(worker_data& data) { - for (std::uint64_t loops = 0; true; ++loops) { - // Wait until main() sends data - std::unique_lock data_lock( - data.until_ready_mutex); - data.until_ready_condition.wait( - data_lock, [&data] { return data.is_ready; }); - - if (data.payload.size() == 0) { - // signaling we are done - return; - } - - // just for easier typing - sol::state& lua = data.worker_lua; - - // we own the lock now, do the work - std::variant> result - = lua.safe_script(data.payload.as_string_view()); - - // store returning payload, - // clear current payload - data.return_payload = std::move(result); - data.payload.clear(); - - // Send result back to main - std::cout << "worker_thread data processing is " - "completed: signaling & unlocking\n"; - data.is_processed = true; - data.is_ready = false; - data_lock.unlock(); - data.until_ready_condition.notify_one(); - } -} - -int main() { - - // main lua state - sol::state lua; - lua.open_libraries(sol::lib::base); - - // set up functions, etc. etc. - lua.script("function f () return 4.5 end"); - lua.script("function g () return { 1.1, 2.2, 3.3 } end"); - - // kick off worker - worker_data data; - std::thread worker(worker_thread, std::ref(data)); - - // main Lua state - bool done_working = false; - for (std::uint64_t loops = 0; !done_working; ++loops) { - // finished working? send nothing - // even loop? use f - // otherwise, use g - if (loops >= 3) { - data.payload.clear(); - done_working = true; - } - else if ((loops % 2) == 0) { - sol::function target = lua["f"]; - data.payload = target.dump(); - } - else { - sol::function target = lua["g"]; - data.payload = target.dump(); - } - - // send data to the worker thread - { - std::lock_guard lk( - data.until_ready_mutex); - data.is_ready = true; - std::cout - << "function serialized: sending to worker " - "thread to execute on Lua state...\n"; - } - data.until_ready_condition.notify_one(); - - if (done_working) { - break; - } - // wait for the worker - { - std::unique_lock - lock_waiting_for_worker( - data.until_ready_mutex); - data.until_ready_condition.wait( - lock_waiting_for_worker, - [&data] { return data.is_processed; }); - data.is_processed = false; - } - auto data_processor = [](auto& returned_data) { - using option_type - = std::remove_cv_t>; - if constexpr (std::is_same_v) { - std::cout << "received a double: " - << returned_data << "\n"; - } - else if constexpr (std::is_same_v>) { - std::cout - << "received a std::vector: { "; - for (std::size_t i = 0; - i < returned_data.size(); - ++i) { - std::cout << returned_data[i]; - if (i - != static_cast( - returned_data.size() - 1)) { - std::cout << ", "; - } - } - std::cout << " }\n"; - } - else { - std::cerr << "OH MY GOD YOU FORGOT TO " - "HANDLE A TYPE OF DATA FROM A " - "WORKER ABORT ABORT ABORT\n"; - std::abort(); - } - }; - std::visit(data_processor, data.return_payload); - } - - // join and wait for workers to come back - worker.join(); - - // workers are back, exit program - return 0; -} diff --git a/third/sol2/examples/source/dump.cpp b/third/sol2/examples/source/dump.cpp deleted file mode 100644 index b80b99cf..00000000 --- a/third/sol2/examples/source/dump.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - - -int main() { - std::cout << "=== dump (serialize between states) ===" - << std::endl; - - // 2 states, transferring function from 1 to another - sol::state lua; - sol::state lua2; - - // we're not going to run the code on the first - // state, so we only actually need - // the base lib on the second state - // (where we will run the serialized bytecode) - lua2.open_libraries(sol::lib::base); - - // load this code (but do not run) - sol::load_result lr - = lua.load("a = function (v) print(v) return v end"); - // check if it's sucessfully loaded - sol_c_assert(lr.valid()); - - // turn it into a function, then dump the bytecode - sol::protected_function target - = lr.get(); - sol::bytecode target_bc = target.dump(); - - // reload the byte code - // in the SECOND state - auto result2 = lua2.safe_script( - target_bc.as_string_view(), sol::script_pass_on_error); - // check if it was done properly - sol_c_assert(result2.valid()); - - // check in the second state if it was valid - sol::protected_function pf = lua2["a"]; - int v = pf(25557); - sol_c_assert(v == 25557); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/dynamic_object.cpp b/third/sol2/examples/source/dynamic_object.cpp deleted file mode 100644 index a2a60ae6..00000000 --- a/third/sol2/examples/source/dynamic_object.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -// use as-is, -// add as a member of your class, -// or derive from it and bind it appropriately -struct dynamic_object { - std::unordered_map entries; - - void dynamic_set(std::string key, sol::stack_object value) { - auto it = entries.find(key); - if (it == entries.cend()) { - entries.insert( - it, { std::move(key), std::move(value) }); - } - else { - std::pair& kvp - = *it; - sol::object& entry = kvp.second; - entry = sol::object(std::move(value)); - } - } - - sol::object dynamic_get(std::string key) { - auto it = entries.find(key); - if (it == entries.cend()) { - return sol::lua_nil; - } - return it->second; - } -}; - - -int main() { - std::cout << "=== dynamic_object ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("dynamic_object", - sol::meta_function::index, - &dynamic_object::dynamic_get, - sol::meta_function::new_index, - &dynamic_object::dynamic_set, - sol::meta_function::length, - [](dynamic_object& d) { return d.entries.size(); }); - - lua.safe_script(R"( -d1 = dynamic_object.new() -d2 = dynamic_object.new() - -print(#d1) -- length operator -print(#d2) - -function d2:run(lim) - local r = 0 - for i=0,lim do - r = r + i - end - if (r % 2) == 1 then - print("odd") - end - return r -end - --- only added an entry to d2 -print(#d1) -print(#d2) - --- only works on d2 -local value = d2:run(5) -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); - sol_c_assert(!script_result.valid()); - sol::error err = script_result; - std::cout << "received expected error: " << err.what() - << std::endl; - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/environment_snooping.cpp b/third/sol2/examples/source/environment_snooping.cpp deleted file mode 100644 index b5591025..00000000 --- a/third/sol2/examples/source/environment_snooping.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -// Simple sol2 version of the below -void simple(sol::this_state ts, sol::this_environment te) { - sol::state_view lua = ts; - if (te) { - sol::environment& env = te; - sol::environment freshenv = lua["freshenv"]; - bool is_same_env = freshenv == env; - std::cout << "this_environment -- env == freshenv : " - << is_same_env << std::endl; - } - std::cout << "this_environment -- no environment present" - << std::endl; -} - -// NOTE: -// THIS IS A LOW-LEVEL EXAMPLE, using pieces of sol2 -// to facilitate better usage -// It is recommended you just do the simple version, as it is -// basically this code but it is sometimes useful to show the -// hoops you need to jump through to use the Lua C API -void complicated(sol::this_state ts) { - lua_State* L = ts; - - lua_Debug info; - // Level 0 means current function (this C function, which is - // useless for our purposes) Level 1 means next call frame - // up the stack. This is probably the environment we're - // looking for? - int level = 1; - int pre_stack_size = lua_gettop(L); - if (lua_getstack(L, level, &info) != 1) { - // failure: call it quits - std::cout << "error: unable to traverse the stack" - << std::endl; - lua_settop(L, pre_stack_size); - return; - } - // the "f" identifier is the most important here - // it pushes the function running at `level` onto the stack: - // we can get the environment from this - // the rest is for printing / debugging purposes - if (lua_getinfo(L, "fnluS", &info) == 0) { - // failure? - std::cout << "manually -- error: unable to get stack " - "information" - << std::endl; - lua_settop(L, pre_stack_size); - return; - } - - // Okay, so all the calls worked. - // Print out some information about this "level" - std::cout << "manually -- [" << level << "] " - << info.short_src << ":" << info.currentline - << " -- " << (info.name ? info.name : "") - << "[" << info.what << "]" << std::endl; - - // Grab the function off the top of the stack - // remember: -1 means top, -2 means 1 below the top, and so - // on... 1 means the very bottom of the stack, 2 means 1 - // more up, and so on to the top value... - sol::function f(L, -1); - // The environment can now be ripped out of the function - sol::environment env(sol::env_key, f); - if (!env.valid()) { - std::cout << "manually -- error: no environment to get" - << std::endl; - lua_settop(L, pre_stack_size); - return; - } - sol::state_view lua(L); - sol::environment freshenv = lua["freshenv"]; - bool is_same_env = freshenv == env; - std::cout << "manually -- env == freshenv : " << is_same_env - << std::endl; -} - -int main() { - std::cout << "=== environment snooping ===" << std::endl; - sol::state lua; - - sol::environment freshenv(lua, sol::create, lua.globals()); - lua["freshenv"] = freshenv; - lua.set_function("f", simple); - lua.set_function("g", complicated); - - lua.script("f()", freshenv); - lua.script("g()", freshenv); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/environment_state.cpp b/third/sol2/examples/source/environment_state.cpp deleted file mode 100644 index c5554fe6..00000000 --- a/third/sol2/examples/source/environment_state.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main(int, char*[]) { - std::cout << "=== environment state ===" << std::endl; - - sol::state lua; - lua.open_libraries(); - sol::environment my_env(lua, sol::create); - // set value, and we need to explicitly allow for - // access to "print", since a new environment hides - // everything that's not defined inside of it - // NOTE: hiding also hides library functions (!!) - // BE WARNED - my_env["var"] = 50; - my_env["print"] = lua["print"]; - - sol::environment my_other_env( - lua, sol::create, lua.globals()); - // do not need to explicitly allow access to "print", - // since we used the "Set a fallback" version - // of the sol::environment constructor - my_other_env["var"] = 443; - - // output: 50 - lua.script("print(var)", my_env); - - // output: 443 - lua.script("print(var)", my_other_env); - - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/environment_state_2.cpp b/third/sol2/examples/source/environment_state_2.cpp deleted file mode 100644 index 76be04b7..00000000 --- a/third/sol2/examples/source/environment_state_2.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main(int, char*[]) { - std::cout << "=== environment state 2 ===" << std::endl; - - sol::state lua; - lua.open_libraries(); - - sol::environment env(lua, sol::create, lua.globals()); - env["func"] = []() { return 42; }; - - sol::environment env2(lua, sol::create, lua.globals()); - env2["func"] = []() { return 24; }; - - lua.script("function foo() print(func()) end", env); - lua.script("function foo() print(func()) end", env2); - - env["foo"](); // prints 42 - env2["foo"](); // prints 24 - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/environments.cpp b/third/sol2/examples/source/environments.cpp deleted file mode 100644 index 2afa28ea..00000000 --- a/third/sol2/examples/source/environments.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -void test_environment(std::string key, - const sol::environment& env, const sol::state_view& lua) { - sol::optional maybe_env_a = env[key]; - sol::optional maybe_global_a = lua[key]; - if (maybe_global_a) { - std::cout << "\t'" << key << "' is " - << maybe_global_a.value() - << " in the global environment" << std::endl; - } - else { - std::cout - << "\t'" << key - << "' does not exist in the global environment" - << std::endl; - } - if (maybe_env_a) { - std::cout << "\t'" << key << "' is " - << maybe_env_a.value() - << " in target environment" << std::endl; - } - else { - std::cout << "\t'" << key - << "' does not exist in target environment" - << std::endl; - } -} - -int main(int, char**) { - std::cout << "=== environments ===" << std::endl; - - sol::state lua; - // A global variable to see if we can "fallback" into it - lua["b"] = 2142; - - // Create a new environment - sol::environment plain_env(lua, sol::create); - // Use it - lua.script("a = 24", plain_env); - std::cout << "-- target: plain_env" << std::endl; - test_environment("a", plain_env, lua); - test_environment("b", plain_env, lua); - std::cout << std::endl; - - // Create an environment with a fallback - sol::environment env_with_fallback( - lua, sol::create, lua.globals()); - // Use it - lua.script("a = 56", env_with_fallback); - std::cout << "-- target: env_with_fallback (fallback is " - "global table)" - << std::endl; - test_environment("a", env_with_fallback, lua); - test_environment("b", env_with_fallback, lua); - std::cout << std::endl; - - - return 0; -} diff --git a/third/sol2/examples/source/environments_on_functions.cpp b/third/sol2/examples/source/environments_on_functions.cpp deleted file mode 100644 index f434f54a..00000000 --- a/third/sol2/examples/source/environments_on_functions.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main(int, char**) { - sol::state lua; - lua.open_libraries(sol::lib::base); - - // Environments can set on functions (scripts), userdata and - // threads let's look at functions - - lua.script("f = function() return test end"); - sol::function f = lua["f"]; - - sol::environment env_f(lua, sol::create); - env_f["test"] = 31; - bool env_f_set_success = sol::set_environment(env_f, f); - sol_c_assert(env_f_set_success); - - // the function returns the value from the environment table - int result = f(); - sol_c_assert(result == 31); - - - // You can also protect from variables - // being set without the 'local' specifier - lua.script("g = function() test = 5 end"); - sol::function g = lua["g"]; - sol::environment env_g(lua, sol::create); - bool env_g_set_success - = env_g.set_on(g); // same as set_environment - sol_c_assert(env_g_set_success); - - g(); - // the value can be retrieved from the env table - int test = env_g["test"]; - sol_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"]; - sol_c_assert(!global_test.valid()); - - - // You can retrieve environments in C++ - // and check the environment of functions - // gotten from Lua - - // get the environment from any sol::reference-styled type, - // including sol::object, sol::function, sol::table, - // sol::userdata ... - lua.set_function("check_f_env", - // capture necessary variable in C++ lambda - [&env_f](sol::object target) { - // pull out the environment from func using - // sol::env_key constructor - sol::environment target_env(sol::env_key, target); - int test_env_f = env_f["test"]; - int test_target_env = target_env["test"]; - // the environment for f the one gotten from - // `target` are the same - sol_c_assert(test_env_f == test_target_env); - sol_c_assert(test_env_f == 31); - sol_c_assert(env_f == target_env); - }); - lua.set_function( - "check_g_env", [&env_g](sol::function target) { - // equivalent: - sol::environment target_env - = sol::get_environment(target); - int test_env_g = env_g["test"]; - int test_target_env = target_env["test"]; - sol_c_assert(test_env_g == test_target_env); - sol_c_assert(test_env_g == 5); - sol_c_assert(env_g == target_env); - }); - - lua.script("check_f_env(f)"); - lua.script("check_g_env(g)"); - - return 0; -} diff --git a/third/sol2/examples/source/error_handler.cpp b/third/sol2/examples/source/error_handler.cpp deleted file mode 100644 index 7e9f86f0..00000000 --- a/third/sol2/examples/source/error_handler.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - - const auto& code = R"( - bark_power = 11; - - function got_problems( error_msg ) - return "got_problems handler: " .. error_msg - end - - function woof ( bark_energy ) - if bark_energy < 20 then - error("*whine*") - end - return (bark_energy * (bark_power / 4)) - end - - function woofers ( bark_energy ) - if bark_energy < 10 then - error("*whine*") - end - return (bark_energy * (bark_power / 4)) - end - )"; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.script(code); - - sol::protected_function problematic_woof = lua["woof"]; - problematic_woof.set_error_handler(lua["got_problems"]); - - auto firstwoof = problematic_woof(20); - if (firstwoof.valid()) { - // Can work with contents - double numwoof = firstwoof; - std::cout << "Got value: " << numwoof << std::endl; - } - else { - // An error has occured - sol::error err = firstwoof; - std::string what = err.what(); - std::cout << what << std::endl; - } - - // errors, calls handler and then returns a string error - // from Lua at the top of the stack - auto secondwoof = problematic_woof(19); - if (secondwoof.valid()) { - // Call succeeded - double numwoof = secondwoof; - std::cout << "Got value: " << numwoof << std::endl; - } - else { - // Call failed - // Note that if the handler was successfully called, - // this will include the additional appended error - // message information of "got_problems handler: " ... - sol::error err = secondwoof; - std::string what = err.what(); - std::cout << what << std::endl; - } - - // can also use optional to tell things - sol::optional maybevalue = problematic_woof(19); - if (maybevalue) { - // Have a value, use it - double numwoof = maybevalue.value(); - std::cout << "Got value: " << numwoof << std::endl; - } - else { - std::cout << "No value!" << std::endl; - } - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/exception_handler.cpp b/third/sol2/examples/source/exception_handler.cpp deleted file mode 100644 index 78c3f67f..00000000 --- a/third/sol2/examples/source/exception_handler.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -#include - -int my_exception_handler(lua_State* L, - sol::optional maybe_exception, - sol::string_view description) { - // L is the lua state, which you can wrap in a state_view if - // necessary maybe_exception will contain exception, if it - // exists description will either be the what() of the - // exception or a description saying that we hit the - // general-case catch(...) - std::cout << "An exception occurred in a function, here's " - "what it says "; - if (maybe_exception) { - std::cout << "(straight from the exception): "; - const std::exception& ex = *maybe_exception; - std::cout << ex.what() << std::endl; - } - else { - std::cout << "(from the description parameter): "; - std::cout.write(description.data(), - static_cast(description.size())); - std::cout << std::endl; - } - - // you must push 1 element onto the stack to be - // transported through as the error object in Lua - // note that Lua -- and 99.5% of all Lua users and libraries - // -- expects a string so we push a single string (in our - // case, the description of the error) - return sol::stack::push(L, description); -} - -void will_throw() { - throw std::runtime_error("oh no not an exception!!!"); -} - -int main() { - std::cout << "=== exception_handler ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - lua.set_exception_handler(&my_exception_handler); - - lua.set_function("will_throw", &will_throw); - - sol::protected_function_result pfr = lua.safe_script( - "will_throw()", &sol::script_pass_on_error); - - sol_c_assert(!pfr.valid()); - - sol::error err = pfr; - std::cout << err.what() << std::endl; - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/functions.cpp b/third/sol2/examples/source/functions.cpp deleted file mode 100644 index 23037eee..00000000 --- a/third/sol2/examples/source/functions.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -inline int my_add(int x, int y) { - return x + y; -} - -struct multiplier { - int operator()(int x) { - return x * 10; - } - - static int by_five(int x) { - return x * 5; - } -}; - -int main() { - std::cout << "=== functions ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // setting a function is simple - lua.set_function("my_add", my_add); - - // you could even use a lambda - lua.set_function( - "my_mul", [](double x, double y) { return x * y; }); - - // member function pointers and functors as well - lua.set_function("mult_by_ten", multiplier {}); - 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)"); - - // using lambdas, functions can have state. - int x = 0; - lua.set_function("inc", [&x]() { x += 10; }); - - // calling a stateful lambda modifies the value - lua.script("inc()"); - sol_c_assert(x == 10); - if (x == 10) { - // Do something based on this information - std::cout << "Yahoo! x is " << x << std::endl; - } - - // this can be done as many times as you want - lua.script(R"( -inc() -inc() -inc() -)"); - sol_c_assert(x == 40); - if (x == 40) { - // Do something based on this information - std::cout << "Yahoo! x is " << x << std::endl; - } - - // retrieval of a function is done similarly - // to other variables, using sol::function - sol::function add = lua["my_add"]; - int value = add(10, 11); - // second way to call the function - int value2 = add.call(10, 11); - sol_c_assert(value == 21); - sol_c_assert(value2 == 21); - if (value == 21 && value2 == 21) { - std::cout << "Woo, value is 21!" << std::endl; - } - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/functions_empty_arguments.cpp b/third/sol2/examples/source/functions_empty_arguments.cpp deleted file mode 100644 index c68634ff..00000000 --- a/third/sol2/examples/source/functions_empty_arguments.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main(int, char*[]) { - std::cout << "=== functions empty args ===" << std::endl; - - // sol::reference, sol::Stack_reference, - // sol::object (and main_* types) can all be - // used to capture "nil", or "none" when a function - // leaves it off - auto my_defaulting_function - = [](sol::object maybe_defaulted) -> int { - // if it's nil, it's "unused" or "inactive" - bool inactive = maybe_defaulted == sol::lua_nil; - if (inactive) { - return 0; - } - if (maybe_defaulted.is()) { - int value = maybe_defaulted.as(); - return value; - } - return 1; - }; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // copy function in (use std::ref to change this behavior) - lua.set_function( - "defaulting_function", my_defaulting_function); - - sol::string_view code = R"( - result = defaulting_function(24) - result_nothing = defaulting_function() - result_nil = defaulting_function(nil) - result_string = defaulting_function('meow') - print('defaulting_function(24), returned:', result) - print('defaulting_function(), returned:', result_nothing) - print('defaulting_function(nil), returned:', result_nil) - print('defaulting_function(\'meow\'), returned:', result_string) - assert(result == 24) - assert(result_nothing == 0) - assert(result_nil == 0) - assert(result_string == 1) - )"; - - lua.safe_script(code); - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/index_and_newindex_usertype.cpp b/third/sol2/examples/source/index_and_newindex_usertype.cpp deleted file mode 100644 index 486c7e49..00000000 --- a/third/sol2/examples/source/index_and_newindex_usertype.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -class vector { -public: - double data[3]; - - vector() : data { 0, 0, 0 } { - } - - double& operator[](int i) { - return data[i]; - } - - - static double my_index(vector& v, int i) { - return v[i]; - } - - static void my_new_index(vector& v, int i, double x) { - v[i] = x; - } -}; - -int main() { - sol::state lua; - lua.open_libraries(sol::lib::base); - lua.new_usertype("vector", - sol::constructors>(), - sol::meta_function::index, - &vector::my_index, - sol::meta_function::new_index, - &vector::my_new_index); - lua.script( - "v = vector.new()\n" - "print(v[1])\n" - "v[2] = 3\n" - "print(v[2])\n"); - - vector& v = lua["v"]; - sol_c_assert(v[0] == 0.0); - sol_c_assert(v[1] == 0.0); - sol_c_assert(v[2] == 3.0); - - return 0; -} diff --git a/third/sol2/examples/source/indirect_function_calls.cpp b/third/sol2/examples/source/indirect_function_calls.cpp deleted file mode 100644 index 3e25baa9..00000000 --- a/third/sol2/examples/source/indirect_function_calls.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -sol::variadic_results call_it(sol::object function_name, - sol::variadic_args args, sol::this_environment env, - sol::this_state L) { - sol::state_view lua = L; - // default to global table as environment - sol::environment function_environment = lua.globals(); - if (env) { - // if we have an environment, use that instead - function_environment = env; - } - - // get and call the function - sol::protected_function pf - = function_environment[function_name]; - sol::protected_function_result res = pf(args); - - // - sol::variadic_results results; - if (!res.valid()) { - // something went wrong: log/crash/whatever - return results; - } - int returncount = res.return_count(); - for (int i = 0; i < returncount; i++) { - // pass offset to get the object that was returned - sol::object obj = res.get(i); - results.push_back(obj); - } - // return the results - return results; -} - -int main(int, char*[]) { - std::cout << "=== indirect function calls ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua["call_it"] = call_it; - - // some functions to call - lua.script(R"( -function add (a, b) - return a + b; -end - -function subtract (a, b) - return a - b; -end - -function log (x) - print(x) -end -)"); - - // call the functions indirectly, using a name - lua.script(R"( - call_it("log", "hiyo") - call_it("log", 24) - subtract_result = call_it("subtract", 5, 1) - add_result = call_it("add", 5, 1) - )"); - - int subtract_result = lua["subtract_result"]; - int add_result = lua["add_result"]; - - sol_c_assert(add_result == 6); - sol_c_assert(subtract_result == 4); - - std::cout << std::endl; - return 0; -} diff --git a/third/sol2/examples/source/lua_stream.cpp b/third/sol2/examples/source/lua_stream.cpp deleted file mode 100644 index 5f804aba..00000000 --- a/third/sol2/examples/source/lua_stream.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#define SOL_CHECK_ARGUMENTS 1 -#include - -#include - -bool is_file_std_out(sol::table data) { - sol::object maybe_file = data["file"]; - if (maybe_file.is()) { - luaL_Stream& filestream = data["file"]; - return filestream.f == stdout; - } - return false; -} - -int main() { - sol::state lua; - lua.open_libraries(sol::lib::base, sol::lib::io); - - lua["is_std_out"] = &is_file_std_out; - lua.script("assert(is_std_out{ file = io.stdout })"); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/lua_value.cpp b/third/sol2/examples/source/lua_value.cpp deleted file mode 100644 index 7b69f2f3..00000000 --- a/third/sol2/examples/source/lua_value.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -struct int_entry { - int value; - - int_entry() : value(0) { - } - - int_entry(int v) : value(v) { - } - - std::string to_string() const { - return "int_entry(" + std::to_string(value) + ")"; - } - - bool operator==(const int_entry& e) const { - return value == e.value; - } -}; - -int main(int, char*[]) { - - std::cout << "=== sol::lua_value/sol::array_value ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base, sol::lib::io); - - sol::lua_value lv_int(lua, 56); - sol::lua_value lv_int_table(lua, { 1, 2, 3, 4, 5 }); - sol::lua_value lv_map(lua, - { { "bark bark", "meow hiss!" }, - { 3, 4 }, - { ":D", 6 } }); - sol::lua_value lv_mixed_table(lua, - sol::array_value { - 1, int_entry(2), 3, int_entry(4), 5 }); - sol::lua_value lv_mixed_nested_table(lua, - sol::array_value { 1, - int_entry(2), - 3, - int_entry(4), - sol::array_value { 5, 6, int_entry(7), "8" } }); - - const auto& code = R"( - function real_print_recursive (e, level) - local et = type(e) - if et == 'table' then - io.write("{ ") - local iters = 0 - for k, v in pairs(e) do - if iters ~= 0 then - io.write(", ") - end - real_print_recursive(k, level + 1) - io.write(": ") - real_print_recursive(v, level + 1) - iters = iters + 1 - end - io.write(" }") - elseif et == 'string' then - io.write('"') - io.write(e) - io.write('"') - else - io.write(tostring(e)) - end - if level == 0 then - io.write("\n") - end - end - - function print_recursive (e) - real_print_recursive(e, 0) - end - )"; - - sol::optional maybe_error - = lua.safe_script(code, sol::script_pass_on_error); - if (maybe_error) { - std::cerr << maybe_error->what() << std::endl; - return 1; - } - sol::function print_recursive = lua["print_recursive"]; - - // show it printed out - std::cout << "lv_int: " << std::endl; - print_recursive(lv_int); - std::cout << std::endl; - - std::cout << "lv_int_table: " << std::endl; - print_recursive(lv_int_table); - std::cout << std::endl; - - std::cout << "lv_map: " << std::endl; - print_recursive(lv_map); - std::cout << std::endl; - - std::cout << "lv_mixed_table: " << std::endl; - print_recursive(lv_mixed_table); - std::cout << std::endl; - - std::cout << "lv_mixed_nested_table: " << std::endl; - print_recursive(lv_mixed_nested_table); - std::cout << std::endl; - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/metatable_customization.cpp b/third/sol2/examples/source/metatable_customization.cpp deleted file mode 100644 index 39c4e8cb..00000000 --- a/third/sol2/examples/source/metatable_customization.cpp +++ /dev/null @@ -1,195 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -struct thing { - int member_variable = 5; - - double member_function() const { - return member_variable / 2.0; - } -}; - -#define TEMPLATE_AUTO(x) decltype(x), x - -// cheap storage: in reality, you'd need to find a -// better way of handling this. -// or not! It's up to you. -static std::unordered_map - thing_function_associations; -static std::unordered_map - thing_variable_associations; - -void register_thing_type(sol::state& lua) { - thing_variable_associations.emplace_hint( - thing_variable_associations.cend(), - "member_variable", - sol::object(lua.lua_state(), - sol::in_place, - &sol::c_call)); - thing_function_associations.emplace_hint( - thing_function_associations.cend(), - "member_function", - sol::object(lua.lua_state(), - sol::in_place, - &sol::c_call)); - - struct call_handler { - static int lookup_function(lua_State* L) { - sol::stack_object source(L, 1); - sol::stack_object key(L, 2); - if (!source.is()) { - return luaL_error(L, - "given an incorrect object for this " - "call"); - } - sol::optional maybe_svkey - = key.as>(); - if (maybe_svkey) { - { - // functions are different from - // variables functions, when obtain with - // the syntax obj.f, obj.f(), and - // obj:f() must return the function - // itself so we just push it realy into - // our target - auto it - = thing_function_associations.find( - *maybe_svkey); - if (it - != thing_function_associations - .cend()) { - return it->second.push(L); - } - } - { - // variables are different than funtions - // when someone does `obj.a`, they - // expect this __index call (this lookup - // function) to return to them the value - // itself they're seeing so we call out - // lua_CFunction that we serialized - // earlier - auto it - = thing_variable_associations.find( - *maybe_svkey); - if (it - != thing_variable_associations - .cend()) { - // note that calls generated by - // sol2 for member variables expect - // the stack ordering to be 2(, 3, - // ..., n) -- value(s) 1 -- source - // so we destroy the key on the - // stack - sol::stack::remove(L, 2, 1); - lua_CFunction cf - = it->second - .as(); - return cf(L); - } - } - } - return sol::stack::push(L, sol::lua_nil); - } - - static int insertion_function(lua_State* L) { - sol::stack_object source(L, 1); - sol::stack_object key(L, 2); - sol::stack_object value(L, 3); - if (!source.is()) { - return luaL_error(L, - "given an incorrect object for this " - "call"); - } - // write to member variables, etc. etc... - sol::optional maybe_svkey - = key.as>(); - if (maybe_svkey) { - { - // variables are different than funtions - // when someone does `obj.a`, they - // expect this __index call (this lookup - // function) to return to them the value - // itself they're seeing so we call out - // lua_CFunction that we serialized - // earlier - auto it - = thing_variable_associations.find( - *maybe_svkey); - if (it - != thing_variable_associations - .cend()) { - // note that calls generated by - // sol2 for member variables expect - // the stack ordering to be 2(, 3, - // ..., n) -- value(s) 1 -- source - // so we remove the key value - sol::stack::remove(L, 2, 1); - lua_CFunction cf - = it->second - .as(); - return cf(L); - } - else { - // write to member variable, maybe - // override function if your class - // allows for it? - (void)value; - } - } - // exercise for reader: - // how do you override functions on the - // metatable with proper syntax, but error - // when the type is an "instance" object? - } - return 0; - } - }; - - lua.new_usertype("thing"); - sol::table metatable = lua["thing"]; - - metatable[sol::meta_method::index] - = &call_handler::lookup_function; - metatable[sol::meta_method::new_index] - = &call_handler::insertion_function; -} - -void unregister_thing_type(sol::state&) { - thing_function_associations.clear(); - thing_variable_associations.clear(); -} - -int main() { - - std::cout << "=== metatable with custom-built (static) " - "handling ===" - << std::endl; - - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // register custom type + storage - register_thing_type(lua); - - lua.script(R"(t = thing.new() - print(t.member_variable) - print(t:member_function()) - t.member_variable = 24 - print(t.member_variable) - print(t:member_function()) - )"); - - // clear storage - unregister_thing_type(lua); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/metatable_key_low_level.cpp b/third/sol2/examples/source/metatable_key_low_level.cpp deleted file mode 100644 index 772a536e..00000000 --- a/third/sol2/examples/source/metatable_key_low_level.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - - struct bark { - int operator()(int x) { - return x; - } - }; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("bark", - sol::meta_function::call_function, - &bark::operator()); - - bark b; - lua.set("b", &b); - - sol::table b_as_table = lua["b"]; - sol::table b_metatable = b_as_table[sol::metatable_key]; - sol::function b_call = b_metatable["__call"]; - sol::function b_as_function = lua["b"]; - - int result1 = b_as_function(1); - // pass 'self' directly to argument - int result2 = b_call(b, 1); - sol_c_assert(result1 == result2); - sol_c_assert(result1 == 1); - sol_c_assert(result2 == 1); -} diff --git a/third/sol2/examples/source/multi_results.cpp b/third/sol2/examples/source/multi_results.cpp deleted file mode 100644 index 12241bee..00000000 --- a/third/sol2/examples/source/multi_results.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -int main() { - std::cout << "=== multi results ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // multi-return functions are supported using - // std::tuple as the transfer type, - // sol::as_returns for containers, - // and sol::variadic_results for more special things - lua.set_function("multi_tuple", - [] { return std::make_tuple(10, "goodbye"); }); - 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')"); - - auto multi = lua.get("multi_tuple"); - int first; - std::string second; - // tie the values - sol::tie(first, second) = multi(); - - // use the values - sol_c_assert(first == 10); - sol_c_assert(second == "goodbye"); - - // sol::as_returns - // works with any iterable, - // but we show off std::vector here - lua.set_function("multi_containers", [](bool add_extra) { - std::vector values { 55, 66 }; - if (add_extra) { - values.push_back(77); - } - return sol::as_returns(std::move(values)); - }); - lua.script("print('calling multi_containers')"); - lua.script("print(multi_containers(false))"); - lua.script("a, b, c = multi_containers(true)"); - int a = lua["a"]; - int b = lua["b"]; - int c = lua["c"]; - - sol_c_assert(a == 55); - sol_c_assert(b == 66); - sol_c_assert(c == 77); - - // sol::variadic_results - // you can push objects of different types - // note that sol::this_state is a transparent - // argument: you don't need to pass - // that state through Lua - lua.set_function( - "multi_vars", [](int a, bool b, sol::this_state L) { - sol::variadic_results values; - values.push_back( - { L, sol::in_place_type, a }); - values.push_back( - { L, sol::in_place_type, b }); - values.push_back({ L, sol::in_place, "awoo" }); - return values; - }); - lua.script("print('calling multi_vars')"); - lua.script("print(multi_vars(2, false))"); - lua.script("t, u, v = multi_vars(42, true)"); - int t = lua["t"]; - bool u = lua["u"]; - std::string v = lua["v"]; - - sol_c_assert(t == 42); - sol_c_assert(u); - sol_c_assert(v == "awoo"); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/optional_with_iteration.cpp b/third/sol2/examples/source/optional_with_iteration.cpp deleted file mode 100644 index aa11af90..00000000 --- a/third/sol2/examples/source/optional_with_iteration.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include -#include - -struct thing { - int a = 20; - - thing() = default; - thing(int a) : a(a) { - } -}; - -struct super_thing : thing { - int b = 40; -}; - -struct unrelated { }; - -int main(int, char*[]) { - std::cout << "=== optional with iteration ===" << std::endl; - - sol::state lua; - - // Comment out the new_usertype call - // to prevent derived class "super_thing" - // from being picked up and cast to its base - // class - lua.new_usertype( - "super_thing", sol::base_classes, sol::bases()); - - // Make a few things - lua["t1"] = thing {}; - lua["t2"] = super_thing {}; - lua["t3"] = unrelated {}; - // And a table - lua["container"] = lua.create_table_with( - 0, thing { 50 }, 1, unrelated {}, 4, super_thing {}); - - - std::vector> things; - // Our recursive function - // We use some lambda techniques and pass the function - // itself itself so we can recurse, but a regular function - // would work too! - auto fx = [&things](auto& f, auto& tbl) -> void { - // You can iterate through a table: it has - // begin() and end() - // like standard containers - for (auto key_value_pair : tbl) { - // Note that iterators are extremely frail - // and should not be used outside of - // well-constructed for loops - // that use pre-increment ++, - // or C++ ranged-for loops - const sol::object& key = key_value_pair.first; - const sol::object& value = key_value_pair.second; - sol::type t = value.get_type(); - switch (t) { - case sol::type::table: { - sol::table inner = value.as(); - f(f, inner); - } break; - case sol::type::userdata: { - // This allows us to check if a userdata is - // a specific class type - sol::optional maybe_thing - = value.as>(); - if (maybe_thing) { - thing& the_thing = maybe_thing.value(); - if (key.is()) { - std::cout << "key " - << key.as() - << " is a thing -- "; - } - else if (key.is()) { - std::cout << "key " - << key.as() - << " is a thing -- "; - } - std::cout << "thing.a ==" << the_thing.a - << std::endl; - things.push_back(the_thing); - } - } break; - default: - break; - } - } - }; - fx(fx, lua); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/overloading.cpp b/third/sol2/examples/source/overloading.cpp deleted file mode 100644 index 666a494c..00000000 --- a/third/sol2/examples/source/overloading.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -inline int my_add(int x, int y) { - return x + y; -} - -inline std::string make_string(std::string input) { - return "string: " + input; -} - -int main() { - std::cout << "=== overloading ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // you can overload functions - // just pass in the different functions - // you want to pack into a single name: - // make SURE they take different types! - - lua.set_function("func", sol::overload([](int x) { return x; }, make_string, my_add)); - - // All these functions are now overloaded through "func" - lua.script(R"( -print(func(1)) -print(func("bark")) -print(func(1,2)) -)"); - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/overloading_with_fallback.cpp b/third/sol2/examples/source/overloading_with_fallback.cpp deleted file mode 100644 index 7ea1487d..00000000 --- a/third/sol2/examples/source/overloading_with_fallback.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int func_1(int value) { - return 20 + value; -} - -std::string func_2(std::string text) { - return "received: " + text; -} - -sol::variadic_results fallback( - sol::this_state ts, sol::variadic_args args) { - sol::variadic_results r; - if (args.size() == 2) { - r.push_back({ ts, - sol::in_place, - args.get(0) + args.get(1) }); - } - else { - r.push_back({ ts, sol::in_place, 52 }); - } - return r; -} - -int main(int, char*[]) { - std::cout << "=== overloading with fallback ===" - << std::endl; - - sol::state lua; - lua.open_libraries(); - - lua.set_function( - "f", sol::overload(func_1, func_2, fallback)); - - lua.script("print(f(1))"); // func_1 - lua.script("print(f('hi'))"); // func_2 - lua.script("print(f(22, 11))"); // fallback - lua.script("print(f({}))"); // fallback - - return 0; -} diff --git a/third/sol2/examples/source/overloading_with_members.cpp b/third/sol2/examples/source/overloading_with_members.cpp deleted file mode 100644 index a9cd0b60..00000000 --- a/third/sol2/examples/source/overloading_with_members.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -#include - -struct pup { - int barks = 0; - - void bark() { - ++barks; // bark! - } - - bool is_cute() const { - return true; - } -}; - -void ultra_bark(pup& p, int barks) { - for (; barks-- > 0;) - p.bark(); -} - -void picky_bark(pup& p, std::string s) { - if (s == "bark") - p.bark(); -} - -int main() { - std::cout << "=== overloading with members ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.set_function("bark", sol::overload(ultra_bark, []() { - return "the bark from nowhere"; - })); - - lua.new_usertype("pup", - // regular function - "is_cute", - &pup::is_cute, - // overloaded function - "bark", - sol::overload(&pup::bark, &picky_bark)); - - const auto& code = R"( - barker = pup.new() - print(barker:is_cute()) - barker:bark() -- calls member function pup::bark - barker:bark("meow") -- picky_bark, no bark - barker:bark("bark") -- picky_bark, bark - - bark(barker, 20) -- calls ultra_bark - print(bark()) -- calls lambda which returns that string - )"; - - lua.script(code); - - pup& barker = lua["barker"]; - std::cout << barker.barks << std::endl; - sol_c_assert(barker.barks == 22); - - std::cout << std::endl; - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/overridable_function_members.cpp b/third/sol2/examples/source/overridable_function_members.cpp deleted file mode 100644 index b0a52cb4..00000000 --- a/third/sol2/examples/source/overridable_function_members.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - std::cout << "=== override-able member functions ===" - << std::endl; - - struct thingy { - sol::function paint; - - thingy(sol::this_state L) - : paint(sol::make_reference( - L.lua_state(), &thingy::default_paint)) { - } - - void default_paint() { - std::cout << "p" << std::endl; - } - }; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("thingy", - sol::constructors(), - "paint", - &thingy::paint); - - sol::string_view code = R"( -obj = thingy.new() -obj:paint() -obj.paint = function (self) print("g") end -obj:paint() -function obj:paint () print("s") end -obj:paint() -)"; - - lua.safe_script(code); - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/pairs.cpp b/third/sol2/examples/source/pairs.cpp deleted file mode 100644 index 0d33c652..00000000 --- a/third/sol2/examples/source/pairs.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -struct my_thing { - std::map m { - { "bark", 20 }, - { "woof", 60 }, - { "borf", 30 }, - { "awoo", 5 }, - }; - - my_thing() { - } -}; - -struct lua_iterator_state { - typedef std::map::iterator it_t; - it_t it; - it_t last; - - lua_iterator_state(my_thing& mt) - : it(mt.m.begin()), last(mt.m.end()) { - } -}; - -std::tuple my_next( - sol::user user_it_state, - sol::this_state l) { - // this gets called - // to start the first iteration, and every - // iteration there after - - // the state you passed in my_pairs is argument 1 - // the key value is argument 2, but we do not - // care about the key value here - lua_iterator_state& it_state = user_it_state; - auto& it = it_state.it; - if (it == it_state.last) { - // return nil to signify that - // there's nothing more to work with. - return std::make_tuple(sol::object(sol::lua_nil), - sol::object(sol::lua_nil)); - } - auto itderef = *it; - // 2 values are returned (pushed onto the stack): - // the key and the value - // the state is left alone - auto r = std::make_tuple( - sol::object(l, sol::in_place, it->first), - sol::object(l, sol::in_place, it->second)); - // the iterator must be moved forward one before we return - std::advance(it, 1); - return r; -} - -auto my_pairs(my_thing& mt) { - // pairs expects 3 returns: - // the "next" function on how to advance, - // the "table" itself or some state, - // and an initial key value (can be nil) - - // prepare our state - lua_iterator_state it_state(mt); - // sol::user is a space/time optimization over regular - // usertypes, it's incompatible with regular usertypes and - // stores the type T directly in lua without any pretty - // setup saves space allocation and a single dereference - return std::make_tuple(&my_next, - sol::user(std::move(it_state)), - sol::lua_nil); -} - -int main(int, char*[]) { - std::cout << "===== pairs (advanced) =====" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype( - "my_thing", sol::meta_function::pairs, my_pairs); - -#if SOL_LUA_VERSION_I_ > 501 - lua.safe_script(R"( -local mt = my_thing.new() -for k, v in pairs(mt) do - print(k, v) -end -)"); -#endif // Does not work on Lua 5.1 - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/pairs_with_raw_functions.cpp b/third/sol2/examples/source/pairs_with_raw_functions.cpp deleted file mode 100644 index 1aeaab9b..00000000 --- a/third/sol2/examples/source/pairs_with_raw_functions.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -struct my_thing { - std::map m { - { "bark", 20 }, - { "woof", 60 }, - { "borf", 30 }, - { "awoo", 5 }, - }; - - my_thing() { - } -}; - -struct lua_iterator_state { - typedef std::map::iterator it_t; - it_t it; - it_t last; - - lua_iterator_state(my_thing& mt) - : it(mt.m.begin()), last(mt.m.end()) { - } -}; - -int my_next(lua_State* L) { - // this gets called - // to start the first iteration, and every - // iteration there after - // the state you passed in pairs is argument 1 - // the key value is argument 2 - // we do not care about the key value here - lua_iterator_state& it_state - = sol::stack::get>(L, 1); - auto& it = it_state.it; - if (it == it_state.last) { - return sol::stack::push(L, sol::lua_nil); - } - auto itderef = *it; - // 2 values are returned (pushed onto the stack): - // the key and the value - // the state is left alone - int pushed = sol::stack::push(L, itderef.first); - pushed += sol::stack::push_reference(L, itderef.second); - std::advance(it, 1); - return pushed; -} - -int my_pairs(lua_State* L) { - my_thing& mt = sol::stack::get(L, 1); - lua_iterator_state it_state(mt); - // pairs expects 3 returns: - // the "next" function on how to advance, - // the "table" itself or some state, - // and an initial key value (can be nil) - - // next function controls iteration - int pushed = sol::stack::push(L, my_next); - pushed += sol::stack::push>( - L, std::move(it_state)); - pushed += sol::stack::push(L, sol::lua_nil); - return pushed; -} - -int main(int, char*[]) { - std::cout << "===== pairs (using raw Lua C functions) " - "(advanced) =====" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype( - "my_thing", sol::meta_function::pairs, &my_pairs); - -#if SOL_LUA_VERSION_I_ > 501 - lua.safe_script(R"( -local mt = my_thing.new() -for k, v in pairs(mt) do - print(k, v) -end -)"); -#endif // Does not work on Lua 5.1 and below - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/player_script.lua b/third/sol2/examples/source/player_script.lua deleted file mode 100644 index c53a8d10..00000000 --- a/third/sol2/examples/source/player_script.lua +++ /dev/null @@ -1,29 +0,0 @@ --- call single argument integer constructor -p1 = player.new(2) - --- p2 is still here from being --- set with lua["p2"] = player(0); below -local p2shoots = p2:shoot() -assert(not p2shoots) --- had 0 ammo - --- set variable property setter -p1.hp = 545; --- get variable through property getter -print(p1.hp); - -local did_shoot_1 = p1:shoot() -print(did_shoot_1) -print(p1.bullets) -local did_shoot_2 = p1:shoot() -print(did_shoot_2) -print(p1.bullets) -local did_shoot_3 = p1:shoot() -print(did_shoot_3) - --- can read -print(p1.bullets) --- would error: is a readonly variable, cannot write --- p1.bullets = 20 - -p1:boost() diff --git a/third/sol2/examples/source/property.cpp b/third/sol2/examples/source/property.cpp deleted file mode 100644 index 2715bfc6..00000000 --- a/third/sol2/examples/source/property.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -#include - -class Player { -public: - int get_hp() const { - return hp; - } - - void set_hp(int value) { - hp = value; - } - - int get_max_hp() const { - return hp; - } - - void set_max_hp(int value) { - maxhp = value; - } - -private: - int hp = 50; - int maxhp = 50; -}; - -int main(int, char*[]) { - - std::cout << "=== properties from C++ functions ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.set("theplayer", Player()); - - // Yes, you can register after you set a value and it will - // connect up the usertype automatically - lua.new_usertype("Player", - "hp", - sol::property(&Player::get_hp, &Player::set_hp), - "maxHp", - sol::property( - &Player::get_max_hp, &Player::set_max_hp)); - - const auto& code = R"( - -- variable syntax, calls functions - theplayer.hp = 20 - print('hp:', theplayer.hp) - print('max hp:', theplayer.maxHp) - )"; - - lua.script(code); - - return 0; -} diff --git a/third/sol2/examples/source/protect.cpp b/third/sol2/examples/source/protect.cpp deleted file mode 100644 index f4267b1c..00000000 --- a/third/sol2/examples/source/protect.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - - struct protect_me { - int gen(int x) { - return x; - } - }; - - sol::state lua; - lua.open_libraries(sol::lib::base); - lua.new_usertype( - "protect_me", "gen", sol::protect(&protect_me::gen)); - - lua.script(R"__( - pm = protect_me.new() - value = pcall(pm.gen,"wrong argument") - )__"); - bool value = lua["value"]; - sol_c_assert(!value); - - return 0; -} diff --git a/third/sol2/examples/source/protected_functions.cpp b/third/sol2/examples/source/protected_functions.cpp deleted file mode 100644 index ae85bd6a..00000000 --- a/third/sol2/examples/source/protected_functions.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - std::cout << "=== protected_functions ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // A complicated function which can error out - // We define both in terms of Lua code - - lua.script(R"( - function handler (message) - return "Handled this message: " .. message - end - - function f (a) - if a < 0 then - error("negative number detected") - end - return a + 5 - end - )"); - - // Get a protected function out of Lua - sol::protected_function f(lua["f"], lua["handler"]); - - sol::protected_function_result result = f(-500); - if (result.valid()) { - // Call succeeded - int x = result; - std::cout << "call succeeded, result is " << x - << std::endl; - } - else { - // Call failed - sol::error err = result; - std::string what = err.what(); - std::cout << "call failed, sol::error::what() is " - << what << std::endl; - // 'what' Should read - // "Handled this message: negative number detected" - } - - std::cout << std::endl; -} diff --git a/third/sol2/examples/source/read_only.cpp b/third/sol2/examples/source/read_only.cpp deleted file mode 100644 index 8c6aa100..00000000 --- a/third/sol2/examples/source/read_only.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct object { - void my_func() { - std::cout << "hello\n"; - } -}; - -int deny(lua_State* L) { - return luaL_error(L, "HAH! Deniiiiied!"); -} - -int main(int, char*[]) { - - sol::state lua; - lua.open_libraries(sol::lib::base); - - object my_obj; - - sol::table obj_table = lua.create_named_table("object"); - - sol::table obj_metatable = lua.create_table_with(); - obj_metatable.set_function( - "my_func", &object::my_func, &my_obj); - // Set whatever else you need to - // on the obj_metatable, - // not on the obj_table itself! - - // Properly self-index metatable to block things - obj_metatable[sol::meta_function::new_index] = deny; - obj_metatable[sol::meta_function::index] = obj_metatable; - - // Set it on the actual table - obj_table[sol::metatable_key] = obj_metatable; - - try { - lua.script(R"( -print(object.my_func) -object["my_func"] = 24 -print(object.my_func) - )"); - } - catch (const std::exception& e) { - std::cout << "an expected error occurred: " << e.what() - << std::endl; - } - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/require.cpp b/third/sol2/examples/source/require.cpp deleted file mode 100644 index a661ae3a..00000000 --- a/third/sol2/examples/source/require.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct some_class { - int bark = 2012; -}; - -sol::table open_mylib(sol::this_state s) { - sol::state_view lua(s); - - sol::table module = lua.create_table(); - module["func"] = []() { - /* super cool function here */ - return 2; - }; - // register a class too - module.new_usertype( - "some_class", "bark", &some_class::bark); - - return module; -} - -int main() { - std::cout << "=== require ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::package, sol::lib::base); - // sol::c_call takes functions at the template level - // and turns it into a lua_CFunction - // alternatively, one can use - // sol::c_call> to make the call if it's a constexpr - // struct - lua.require("my_lib", - sol::c_call); - - // run some code against your require'd library - lua.safe_script(R"( -s = my_lib.some_class.new() -assert(my_lib.func() == 2) -s.bark = 20 -)"); - - some_class& s = lua["s"]; - sol_c_assert(s.bark == 20); - std::cout << "s.bark = " << s.bark << std::endl; - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/require_override_behavior.cpp b/third/sol2/examples/source/require_override_behavior.cpp deleted file mode 100644 index a7797c46..00000000 --- a/third/sol2/examples/source/require_override_behavior.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Thanks to OrfeasZ for their answer to -// an issue for this example! -#define SOL_ALL_SAFETIES_ON 1 -#include - - -#include -#include - -// Use raw function of form "int(lua_State*)" -// -- this is called a "raw C function", -// and matches the type for lua_CFunction -int LoadFileRequire(lua_State* L) { - // use sol2 stack API to pull - // "first argument" - std::string path = sol::stack::get(L, 1); - - if (path == "a") { - std::string script = R"( - print("Hello from module land!") - test = 123 - return "bananas" - )"; - // load "module", but don't run it - luaL_loadbuffer( - L, script.data(), script.size(), path.c_str()); - // returning 1 object left on Lua stack: - // a function that, when called, executes the script - // (this is what lua_loadX/luaL_loadX functions return - return 1; - } - - sol::stack::push( - L, "This is not the module you're looking for!"); - return 1; -} - -int main() { - std::cout << "=== require override behavior ===" - << std::endl; - - sol::state lua; - // need base for print, - // need package for package/searchers/require - lua.open_libraries(sol::lib::base, sol::lib::package); - - lua.clear_package_loaders(); - lua.add_package_loader(LoadFileRequire); - - // this will call our function for - // the searcher and it will succeed - auto a_result = lua.safe_script(R"( - local a = require("a") - print(a) - print(test) - )", - sol::script_pass_on_error); - sol_c_assert(a_result.valid()); - try { - // this will always fail - auto b_result = lua.safe_script(R"( - local b = require("b") - print(b) - )", - sol::script_throw_on_error); - // this will not be executed because of the throw, - // but it better be true regardless! - sol_c_assert(!b_result.valid()); - } - catch (const std::exception& ex) { - // Whenever sol2 throws an exception from panic, - // catch - std::cout << "Something went wrong, as expected:\n" - << ex.what() << std::endl; - // and CRASH / exit the application - return 0; - } - - // If we get here something went wrong...! - return -1; -} diff --git a/third/sol2/examples/source/runtime_additions.cpp b/third/sol2/examples/source/runtime_additions.cpp deleted file mode 100644 index 8fc322e3..00000000 --- a/third/sol2/examples/source/runtime_additions.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct object { - int value = 0; -}; - -int main(int, char*[]) { - std::cout << "=== runtime_additions ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("object"); - - // runtime additions: through the sol API - lua["object"]["func"] = [](object& o) { - ++o.value; - return o.value; - }; - // runtime additions: through a lua script - lua.script(R"( -function object:print () - print(self:func()) -end - )"); - - // see it work - lua.script(R"( -obj = object.new() -obj:print() - )"); - - object& obj = lua["obj"]; - sol_c_assert(obj.value == 1); - - return 0; -} diff --git a/third/sol2/examples/source/script_error_handling.cpp b/third/sol2/examples/source/script_error_handling.cpp deleted file mode 100644 index a06c64c9..00000000 --- a/third/sol2/examples/source/script_error_handling.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main(int, char**) { - std::cout << "=== script error handling ===" << std::endl; - - sol::state lua; - - std::string code = R"( -bad&$#*$syntax -bad.code = 2 -return 24 -)"; - - /* OPTION 1 */ - // Handling code like this can be robust - // If you disable exceptions, then obviously you would - // remove the try-catch branches, and then rely on the - // `lua_atpanic` function being called and trapping errors - // there before exiting the application - { - // script_default_on_error throws / panics when the - // code is bad: trap the error - try { - int value = lua.script( - code, sol::script_default_on_error); - // This will never be reached - std::cout << value << std::endl; - sol_c_assert(value == 24); - } - catch (const sol::error& err) { - std::cout << "Something went horribly wrong: " - "thrown error" - << "\n\t" << err.what() << std::endl; - } - } - - /* OPTION 2 */ - // Use the script_pass_on_error handler - // this simply passes through the protected_function_result, - // rather than throwing it or calling panic - // 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); - sol_c_assert(!result.valid()); - if (!result.valid()) { - sol::error err = result; - sol::call_status status = result.status(); - std::cout << "Something went horribly wrong: " - << sol::to_string(status) << " error" - << "\n\t" << err.what() << std::endl; - } - } - - /* OPTION 3 */ - // This is a lower-level, more explicit way to load code - // This explicitly loads the code, giving you access to any - // errors plus the load status then, it turns the loaded - // code into a sol::protected_function which is then called - // so that the code can run you can then check that too, for - // any errors The two previous approaches are recommended - { - sol::load_result loaded_chunk = lua.load(code); - sol_c_assert(!loaded_chunk.valid()); - if (!loaded_chunk.valid()) { - sol::error err = loaded_chunk; - sol::load_status status = loaded_chunk.status(); - std::cout << "Something went horribly wrong " - "loading the code: " - << sol::to_string(status) << " error" - << "\n\t" << err.what() << std::endl; - } - else { - // Because the syntax is bad, this will never be - // reached - sol_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 - .get(); - sol::protected_function_result result - = script_func(); - if (!result.valid()) { - sol::error err = result; - sol::call_status status = result.status(); - std::cout - << "Something went horribly wrong " - "running the code: " - << sol::to_string(status) << " error" - << "\n\t" << err.what() << std::endl; - } - } - } - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/self_from_lua.cpp b/third/sol2/examples/source/self_from_lua.cpp deleted file mode 100644 index ff95d831..00000000 --- a/third/sol2/examples/source/self_from_lua.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -// NOTE: -// There are TWO ways to retrieve the "this" -// object from calls, when it comes to constructors and regular -// member functions please pay attention to both: this is a -// low-level operation! - -int main() { - struct thing { - - thing(sol::this_state ts) { - lua_State* L = ts; - // references the object that called this function - // in constructors: - sol::stack_object selfobj(L, 1); - - // definitely the same - thing& self = selfobj.as(); - sol_c_assert(&self == this); - } - - void func(sol::this_state ts) const { - lua_State* L = ts; - // references the object that called this function - // in regular member functions: - sol::stack_object selfobj(L, 1); - // "1" is the bottom of the Lua stack - // 2 is one up, so on and so forth... - thing& self = selfobj.as(); - - // definitely the same - sol_c_assert(&self == this); - } - }; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("thing", - sol::constructors(), - "func", - &thing::func); - - lua.script(R"( -obj = thing.new() -obj:func() - )"); - - return 0; -} diff --git a/third/sol2/examples/source/shared_ptr.cpp b/third/sol2/examples/source/shared_ptr.cpp deleted file mode 100644 index da4bdec1..00000000 --- a/third/sol2/examples/source/shared_ptr.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -#include - -struct my_type { - int value = 10; - - my_type() { - std::cout << "my_type at " << static_cast(this) - << " being default constructed!" - << std::endl; - } - - my_type(const my_type& other) : value(other.value) { - std::cout << "my_type at " << static_cast(this) - << " being copy constructed!" << std::endl; - } - - my_type(my_type&& other) : value(other.value) { - std::cout << "my_type at " << static_cast(this) - << " being move-constructed!" << std::endl; - } - - my_type& operator=(const my_type& other) { - value = other.value; - std::cout << "my_type at " << static_cast(this) - << " being copy-assigned to!" << std::endl; - return *this; - } - - my_type& operator=(my_type&& other) { - value = other.value; - std::cout << "my_type at " << static_cast(this) - << " being move-assigned to!" << std::endl; - return *this; - } - - ~my_type() { - std::cout << "my_type at " << static_cast(this) - << " being destructed!" << std::endl; - } -}; - -int main() { - - std::cout << "=== shared_ptr support ===" << std::endl; - - sol::state lua; - lua.new_usertype( - "my_type", "value", &my_type::value); - { - std::shared_ptr shared - = std::make_shared(); - lua["shared"] = std::move(shared); - } - { - std::cout << "getting reference to shared_ptr..." - << std::endl; - std::shared_ptr& ref_to_shared_ptr - = lua["shared"]; - std::cout << "\tshared.use_count(): " - << ref_to_shared_ptr.use_count() - << std::endl; - my_type& ref_to_my_type = lua["shared"]; - std::cout << "\tafter getting reference to my_type: " - << ref_to_shared_ptr.use_count() - << std::endl; - my_type* ptr_to_my_type = lua["shared"]; - std::cout << "\tafter getting pointer to my_type: " - << ref_to_shared_ptr.use_count() - << std::endl; - - sol_c_assert( - ptr_to_my_type == ref_to_shared_ptr.get()); - sol_c_assert( - &ref_to_my_type == ref_to_shared_ptr.get()); - sol_c_assert(ref_to_shared_ptr->value == 10); - - // script affects all of them equally - lua.script("shared.value = 20"); - - sol_c_assert(ptr_to_my_type->value == 20); - sol_c_assert(ref_to_my_type.value == 20); - sol_c_assert(ref_to_shared_ptr->value == 20); - } - { - std::cout << "getting copy of shared_ptr..." - << std::endl; - std::shared_ptr copy_of_shared_ptr - = lua["shared"]; - std::cout << "\tshared.use_count(): " - << copy_of_shared_ptr.use_count() - << std::endl; - my_type copy_of_value = lua["shared"]; - std::cout << "\tafter getting value copy of my_type: " - << copy_of_shared_ptr.use_count() - << std::endl; - - sol_c_assert(copy_of_shared_ptr->value == 20); - sol_c_assert(copy_of_value.value == 20); - - // script still affects pointer, but does not affect - // copy of `my_type` - lua.script("shared.value = 30"); - - sol_c_assert(copy_of_shared_ptr->value == 30); - sol_c_assert(copy_of_value.value == 20); - } - // set to nil and collect garbage to destroy it - lua.script("shared = nil"); - lua.collect_garbage(); - lua.collect_garbage(); - - std::cout << "garbage has been collected" << std::endl; - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/shared_ptr_inheritance.cpp b/third/sol2/examples/source/shared_ptr_inheritance.cpp deleted file mode 100644 index fe55c386..00000000 --- a/third/sol2/examples/source/shared_ptr_inheritance.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -struct Shape { - virtual ~Shape() = default; -}; - -struct Box : Shape { }; - -SOL_BASE_CLASSES(Box, Shape); -SOL_DERIVED_CLASSES(Shape, Box); - -int main() { - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("Shape", sol::no_constructor); - - lua.new_usertype("Box", sol::factories([&]() { - auto b = std::make_shared(); - std::cout << "create Box@" << std::hex << b.get() - << '\n'; - return b; - })); - - lua.set_function( - "inspect_shape_table", [](const sol::table& args) { - std::shared_ptr defbox = nullptr; - // check if there's a field with the name "shape" - auto s = args.get< - sol::optional>>( - "shape"); - std::cout << "has : " << std::boolalpha - << s.has_value() << '\n'; - - // get the field named "shape" or use the default - // value - std::cout << "get_or: " << std::hex - << args.get_or>( - "shape", defbox) - .get() - << '\n'; - - // this works but I can't test for existence - // beforehand... - std::cout - << "get : " << std::hex - << args.get>("shape") - .get() - << '\n'; - }); - - sol::protected_function_result result = lua.safe_script( - "inspect_shape_table({shape=Box.new()})"); - sol_c_assert(result.valid()); - - return 0; -} diff --git a/third/sol2/examples/source/shared_ptr_modify_in_place.cpp b/third/sol2/examples/source/shared_ptr_modify_in_place.cpp deleted file mode 100644 index 5f3ae37d..00000000 --- a/third/sol2/examples/source/shared_ptr_modify_in_place.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct ree { - int value = 1; - ree() { - } - ree(int v) : value(v) { - } -}; - -int main() { - - std::cout << "=== special pointers -- modify in place ===" - << std::endl; - - sol::state lua; - - auto new_shared_ptr = [](sol::stack_reference obj) { - // works just fine - sol::stack::modify_unique_usertype( - obj, [](std::shared_ptr& sptr) { - sptr = std::make_shared( - sptr->value + 1); - }); - }; - - auto reset_shared_ptr = [](sol::stack_reference obj) { - sol::stack::modify_unique_usertype( - obj, [](std::shared_ptr& sptr) { - // THIS IS SUCH A BAD IDEA AAAGH - sptr.reset(); - // DO NOT reset to nullptr: - // change it to an actual NEW value... - // otherwise you will inject a nullptr into - // the userdata representation... which will - // NOT compare == to Lua's nil - }); - }; - - lua.set_function("f", new_shared_ptr); - lua.set_function("f2", reset_shared_ptr); - lua.set_function("g", - [](ree* r) { std::cout << r->value << std::endl; }); - - lua["p"] = std::make_shared(); - lua.script("g(p) -- okay"); - lua.script("f(p)"); - lua.script("g(p) -- okay"); - // uncomment the below for - // segfault/read-access violation - lua.script("f2(p)"); - // lua.script("g(p) -- kaboom"); - - return 0; -} diff --git a/third/sol2/examples/source/singleton.cpp b/third/sol2/examples/source/singleton.cpp deleted file mode 100644 index edc2acfd..00000000 --- a/third/sol2/examples/source/singleton.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -#include -#include - -struct SomeLib { -private: - SomeLib() { - } - -public: - static std::shared_ptr getInstance(); - - int doSomething() const { - return 20; - } - - // destructor must be public to work with - // std::shared_ptr and friends - // if you need it to be private, you must implement - // a custom deleter with access to the private members - // (e.g., a deleter struct defined in this class) - ~SomeLib() { - } -}; - -std::shared_ptr SomeLib::getInstance() { - static std::weak_ptr instance; - static std::mutex m; - - m.lock(); - auto ret = instance.lock(); - if (!ret) { - ret.reset(new SomeLib()); - instance = ret; - } - m.unlock(); - - return ret; -} - -int main(int, char*[]) { - std::cout << "=== singleton ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("SomeLib", - "new", - sol::no_constructor, - "getInstance", - &SomeLib::getInstance, - "doSomething", - &SomeLib::doSomething); - - lua.script(R"( - --- note we use the `.` here, not `:` (there's no self to access) -local sli = SomeLib.getInstance() - --- we use the `:` here because there is something to access -local value = sli:doSomething() - --- check -print('sli:doSomething() returned:', value) -assert(value == 20) -)"); - - std::cout << std::endl; - return 0; -} diff --git a/third/sol2/examples/source/stack_aligned_function.cpp b/third/sol2/examples/source/stack_aligned_function.cpp deleted file mode 100644 index 423a77ff..00000000 --- a/third/sol2/examples/source/stack_aligned_function.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - sol::state lua; - lua.script("function func (a, b) return (a + b) * 2 end"); - - sol::reference func_ref = lua["func"]; - - // for some reason, you need to use the low-level API - func_ref.push(); // function on stack now - - // maybe this is in a lua_CFunction you bind, - // or maybe you're trying to work with a pre-existing system - // maybe you've used a custom lua_load call, or you're - // working with state_view's load(lua_Reader, ...) call... - // here's a little bit of how you can work with the stack - lua_State* L = lua.lua_state(); - sol::stack_aligned_unsafe_function func(L, -1); - lua_pushinteger(L, 5); // argument 1, using plain API - lua_pushinteger(L, 6); // argument 2 - - // take 2 arguments from the top, - // and use "stack_aligned_function" to call - int result = func(sol::stack_count(2)); - - // make sure everything is clean - sol_c_assert(result == 22); - sol_c_assert( - lua.stack_top() == 0); // stack is empty/balanced - - return 0; -} diff --git a/third/sol2/examples/source/stack_aligned_stack_handler_function.cpp b/third/sol2/examples/source/stack_aligned_stack_handler_function.cpp deleted file mode 100644 index 8a907bd3..00000000 --- a/third/sol2/examples/source/stack_aligned_stack_handler_function.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - sol::state lua; - lua.script("function func (a, b) return (a + b) * 2 end"); - - sol::reference func_ref = lua["func"]; - - // maybe this is in a lua_CFunction you bind, - // or maybe you're trying to work with a pre-existing system - // maybe you've used a custom lua_load call, or you're - // working with state_view's load(lua_Reader, ...) call... - // here's a little bit of how you can work with the stack - lua_State* L = lua.lua_state(); - - // this is a handler: - // stack_aligned_stack_handler, - // as its type name explains so verbosely, - // expects the handler on the stack - sol::stack_reference traceback_handler(L, - -sol::stack::push( - L, sol::default_traceback_error_handler)); - // then, you need the function - // to be on the stack - func_ref.push(); - sol::stack_aligned_stack_handler_function func( - L, -1, traceback_handler); - lua_pushinteger(L, 5); // argument 1, using plain API - lua_pushinteger(L, 6); // argument 2 - - // take 2 arguments from the top, - // and use "stack_aligned_function" to call - int result = func(sol::stack_count(2)); - // function call pops function and arguments, - // leaves result on the stack for us - // but we must manually clean the traceback handler - // manually pop traceback handler - traceback_handler.pop(); - - // make sure everything is clean - sol_c_assert(result == 22); - sol_c_assert( - lua.stack_top() == 0); // stack is empty/balanced - - return 0; -} diff --git a/third/sol2/examples/source/static_variables.cpp b/third/sol2/examples/source/static_variables.cpp deleted file mode 100644 index 3cfcfef4..00000000 --- a/third/sol2/examples/source/static_variables.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct test { - static int muh_variable; -}; -int test::muh_variable = 25; - - -int main() { - std::cout << "=== static_variables ===" << std::endl; - - sol::state lua; - lua.open_libraries(); - lua.new_usertype("test", - "direct", - sol::var(2), - "global", - sol::var(test::muh_variable), - "ref_global", - sol::var(std::ref(test::muh_variable))); - - int direct_value = lua["test"]["direct"]; - // direct_value == 2 - sol_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 - sol_c_assert(global == 25); - sol_c_assert(global2 == 25); - - std::cout << "First round of values --" << std::endl; - std::cout << global << std::endl; - std::cout << global2 << std::endl; - - test::muh_variable = 542; - - global = lua["test"]["global"]; - // global == 25 - // global is its own memory: was passed by value - - global2 = lua["test"]["ref_global"]; - // global2 == 542 - // global2 was passed through std::ref - // global2 holds a reference to muh_variable - // if muh_variable goes out of scope or is deleted - // problems could arise, so be careful! - - sol_c_assert(global == 25); - sol_c_assert(global2 == 542); - - std::cout << "Second round of values --" << std::endl; - std::cout << "global : " << global << std::endl; - std::cout << "global2: " << global2 << std::endl; - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/table_as_container.cpp b/third/sol2/examples/source/table_as_container.cpp deleted file mode 100644 index 444714a0..00000000 --- a/third/sol2/examples/source/table_as_container.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -struct Vector { - int x; - int y; - - Vector() = default; - - Vector(int _x, int _y) : x { _x }, y { _y } { - } -}; - -int main() { - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("Vector", - sol::constructors(), - "x", - sol::property(&Vector::x, &Vector::x), - "y", - sol::property(&Vector::y, &Vector::y)); - - lua.script( - "vectors = { Vector.new(3, 6), Vector.new(6, 3) }"); - auto vectors = lua["vectors"].get>(); - - sol_c_assert(vectors[0].x == 3); - sol_c_assert(vectors[0].y == 6); - - sol_c_assert(vectors[1].x == 6); - sol_c_assert(vectors[1].y == 3); - - return 0; -} diff --git a/third/sol2/examples/source/table_create_if_nil.cpp b/third/sol2/examples/source/table_create_if_nil.cpp deleted file mode 100644 index 1afab3a6..00000000 --- a/third/sol2/examples/source/table_create_if_nil.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -void create_namespace_sf(sol::state& lua) { - // this would explode - // lua["sf"]["value"] = 256; - lua[sol::create_if_nil]["sf"]["value"] = 256; -} - -int main(int, char*[]) { - - std::cout << "=== sol::lua_value/sol::array_value ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - const auto& code = R"( - print(sf) - print(sf.value) - assert(sf.value == 256) - )"; - - auto result - = lua.safe_script(code, sol::script_pass_on_error); - // did not work - sol_c_assert(!result.valid()); - - // create values - create_namespace_sf(lua); - - auto result2 - = lua.safe_script(code, sol::script_pass_on_error); - // it worked properly - sol_c_assert(result2.valid()); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/table_proxy.cpp b/third/sol2/examples/source/table_proxy.cpp deleted file mode 100644 index 8039b527..00000000 --- a/third/sol2/examples/source/table_proxy.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main() { - - const auto& code = R"( - bark = { - woof = { - [2] = "arf!" - } - } - )"; - - sol::state lua; - lua.open_libraries(sol::lib::base); - lua.script(code); - - // produces table_proxy, implicitly converts to std::string, - // quietly destroys table_proxy - std::string arf_string = lua["bark"]["woof"][2]; - - // lazy-evaluation of tables - auto x = lua["bark"]; - auto y = x["woof"]; - auto z = y[2]; - - // retrivies value inside of lua table above - std::string value = z; - sol_c_assert(value == "arf!"); - - // Can change the value later... - z = 20; - - // Yay, lazy-evaluation! - int changed_value = z; // now it's 20! - sol_c_assert(changed_value == 20); - lua.script("assert(bark.woof[2] == 20)"); - - lua["a_new_value"] = 24; - lua["chase_tail"] = [](int chasing) { - int r = 2; - for (int i = 0; i < chasing; ++i) { - r *= r; - } - return r; - }; - - lua.script("assert(a_new_value == 24)"); - lua.script("assert(chase_tail(2) == 16)"); - - return 0; -} diff --git a/third/sol2/examples/source/tables.cpp b/third/sol2/examples/source/tables.cpp deleted file mode 100644 index 4eb8713b..00000000 --- a/third/sol2/examples/source/tables.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -// this example shows how to read data in from a lua table - -int main() { - std::cout << "=== tables ===" << std::endl; - - sol::state lua; - // table used as an array - lua.script(R"(table1 = {"hello", "table"})"); - // table with a nested table and the key value syntax - lua.script(R"( - table2 = { - ["nestedTable"] = { - ["key1"] = "value1", - ["key2"]= "value2", - }, - ["name"] = "table2", - } - )"); - - - /* Shorter Syntax: */ - // using the values stored in table1 - /*std::cout << (std::string)lua["table1"][1] << " " - << (std::string)lua["table1"][2] << '\n'; - */ - // some retrieval of values from the nested table - // the cleaner way of doing things - // chain off the the get<>() / [] results - auto t2 = lua.get("table2"); - auto nestedTable = t2.get("nestedTable"); - // Alternatively: - // sol::table t2 = lua["table2"]; - // sol::table nestedTable = t2["nestedTable"]; - - std::string x = lua["table2"]["nestedTable"]["key2"]; - std::cout << "nested table: key1 : " - << nestedTable.get("key1") - << ", key2: " << x << '\n'; - std::cout << "name of t2: " << t2.get("name") - << '\n'; - std::string t2name = t2["name"]; - std::cout << "name of t2: " << t2name << '\n'; - - /* Longer Syntax: */ - // using the values stored in table1 - std::cout << lua.get("table1").get( - 1) << " " - << lua.get("table1").get( - 2) - << '\n'; - - // some retrieval of values from the nested table - // the cleaner way of doing things - std::cout << "nested table: key1 : " - << nestedTable.get("key1") - << ", key2: " - // yes you can chain the get<>() results - << lua.get("table2") - .get("nestedTable") - .get("key2") - << '\n'; - std::cout << "name of t2: " << t2.get("name") - << '\n'; - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/this_state.cpp b/third/sol2/examples/source/this_state.cpp deleted file mode 100644 index 9292e7de..00000000 --- a/third/sol2/examples/source/this_state.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main() { - sol::state lua; - - lua.set_function( - "bark", [](sol::this_state s, int a, int b) { - lua_State* L = s; // current state - return a + b + lua_gettop(L); - }); - - lua.script( - "first = bark(2, 2)"); // only takes 2 arguments, NOT 3 - - // Can be at the end, too, or in the middle: doesn't matter - lua.set_function( - "bark", [](int a, int b, sol::this_state s) { - lua_State* L = s; // current state - return a + b + lua_gettop(L); - }); - - lua.script("second = bark(2, 2)"); // only takes 2 arguments - int first = lua["first"]; - sol_c_assert(first == 6); - int second = lua["second"]; - sol_c_assert(second == 6); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/tie.cpp b/third/sol2/examples/source/tie.cpp deleted file mode 100644 index 63d2fe98..00000000 --- a/third/sol2/examples/source/tie.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - - const auto& code = R"( - bark_power = 11; - - function woof ( bark_energy ) - return (bark_energy * (bark_power / 4)) - end -)"; - - sol::state lua; - - lua.script(code); - - sol::function woof = lua["woof"]; - double numwoof = woof(20); - sol_c_assert(numwoof == 55.0); - - lua.script("function f () return 10, 11, 12 end"); - - sol::function f = lua["f"]; - std::tuple abc = f(); - sol_c_assert(std::get<0>(abc) == 10); - sol_c_assert(std::get<1>(abc) == 11); - sol_c_assert(std::get<2>(abc) == 12); - // or - int a, b, c; - sol::tie(a, b, c) = f(); - sol_c_assert(a == 10); - sol_c_assert(b == 11); - sol_c_assert(c == 12); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/erase_demo.cpp b/third/sol2/examples/source/tutorials/erase_demo.cpp deleted file mode 100644 index 23d1ef27..00000000 --- a/third/sol2/examples/source/tutorials/erase_demo.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - - sol::state lua; - lua["bark"] = 50; - sol::optional x = lua["bark"]; - // x will have a value - if (x) { - std::cout << "x has no value, as expected" - << std::endl; - } - else { - return -1; - } - - lua["bark"] = sol::lua_nil; - sol::optional y = lua["bark"]; - // y will not have a value - if (y) { - return -1; - } - else { - std::cout << "y has no value, as expected" - << std::endl; - } - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/first_snippet.cpp b/third/sol2/examples/source/tutorials/first_snippet.cpp deleted file mode 100644 index 32a9119d..00000000 --- a/third/sol2/examples/source/tutorials/first_snippet.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include // or #include "sol.hpp", whichever suits your needs - -int main(int argc, char* argv[]) { - // silence unused warnings - (void)argc; - (void)argv; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.script("print('bark bark bark!')"); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/lazy_demo.cpp b/third/sol2/examples/source/tutorials/lazy_demo.cpp deleted file mode 100644 index 70b12394..00000000 --- a/third/sol2/examples/source/tutorials/lazy_demo.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - - sol::state lua; - - auto barkkey = lua["bark"]; - if (barkkey.valid()) { - // Branch not taken: doesn't exist yet - std::cout << "How did you get in here, arf?!" - << std::endl; - } - - barkkey = 50; - if (barkkey.valid()) { - // Branch taken: value exists! - std::cout << "Bark Bjork Wan Wan Wan" << std::endl; - } - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/multiple_return.cpp b/third/sol2/examples/source/tutorials/multiple_return.cpp deleted file mode 100644 index a0b4e41e..00000000 --- a/third/sol2/examples/source/tutorials/multiple_return.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -int main() { - sol::state lua; - - lua.script("function f (a, b, c) return a, b, c end"); - - std::tuple result; - result = lua["f"](1, 2, 3); - sol_c_assert(result == std::make_tuple(1, 2, 3)); - int a, b; - std::string c; - // NOTE: sol::tie, NOT std::tie - // (ESS OH ELL prefix, not ESS TEE DEE prefix) - sol::tie(a, b, c) = lua["f"](1, 2, "bark"); - sol_c_assert(a == 1); - sol_c_assert(b == 2); - sol_c_assert(c == "bark"); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/object_lifetime.cpp b/third/sol2/examples/source/tutorials/object_lifetime.cpp deleted file mode 100644 index 2864ead1..00000000 --- a/third/sol2/examples/source/tutorials/object_lifetime.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -int main() { - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.script(R"( - obj = "please don't let me die"; - )"); - - sol::object keep_alive = lua["obj"]; - lua.script(R"( - obj = nil; - function say(msg) - print(msg) - end - )"); - - lua.collect_garbage(); - - lua["say"](lua["obj"]); - // still accessible here and still alive in Lua - // even though the name was cleared - std::string message = keep_alive.as(); - std::cout << message << std::endl; - - // Can be pushed back into Lua as an argument - // or set to a new name, - // whatever you like! - lua["say"](keep_alive); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/open_multiple_libraries.cpp b/third/sol2/examples/source/tutorials/open_multiple_libraries.cpp deleted file mode 100644 index 379cc2b5..00000000 --- a/third/sol2/examples/source/tutorials/open_multiple_libraries.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -int main(int argc, char* argv[]) { - // silence unused warnings - (void)argc; - (void)argv; - sol::state lua; - lua.open_libraries(sol::lib::base, - sol::lib::coroutine, - sol::lib::string, - sol::lib::io); - - lua.script("print('bark bark bark!')"); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/tutorials/pointer_lifetime.cpp b/third/sol2/examples/source/tutorials/pointer_lifetime.cpp deleted file mode 100644 index aef8ed4d..00000000 --- a/third/sol2/examples/source/tutorials/pointer_lifetime.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -struct my_type { - void stuff() { - } -}; - -int main() { - - sol::state lua; - - /* - // AAAHHH BAD - // dangling pointer! - lua["my_func"] = []() -> my_type* { return new my_type(); }; - - // AAAHHH! - lua.set("something", new my_type()); - - // AAAAAAHHH!!! - lua["something_else"] = new my_type(); - */ - - // :ok: - lua["my_func0"] = []() -> std::unique_ptr { - return std::make_unique(); - }; - - // :ok: - lua["my_func1"] = []() -> std::shared_ptr { - return std::make_shared(); - }; - - // :ok: - lua["my_func2"] = []() -> my_type { return my_type(); }; - - // :ok: - lua.set( - "something", std::unique_ptr(new my_type())); - - std::shared_ptr my_shared - = std::make_shared(); - // :ok: - lua.set("something_else", my_shared); - - // :ok: - auto my_unique = std::make_unique(); - lua["other_thing"] = std::move(my_unique); - - // :ok: - lua["my_func5"] = []() -> my_type* { - static my_type mt; - return &mt; - }; - - // THIS IS STILL BAD DON'T DO IT AAAHHH BAD - // return a unique_ptr that's empty instead - // or be explicit! - lua["my_func6"] = []() -> my_type* { return nullptr; }; - - // :ok: - lua["my_func7"] - = []() -> std::nullptr_t { return nullptr; }; - - // :ok: - lua["my_func8"] = []() -> std::unique_ptr { - // default-constructs as a nullptr, - // gets pushed as nil to Lua - return std::unique_ptr(); - // same happens for std::shared_ptr - }; - - // Acceptable, it will set 'something' to nil - // (and delete it on next GC if there's no more references) - lua.set("something", nullptr); - - // Also fine - lua["something_else"] = nullptr; - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/arguments_to_scripts.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/arguments_to_scripts.cpp deleted file mode 100644 index 728bf466..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/arguments_to_scripts.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main(int, char*[]) { - std::cout << "=== passing arguments to scripts ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - const auto& my_script = R"( -local a,b,c = ... -print(a,b,c) - )"; - - sol::load_result fx = lua.load(my_script); - if (!fx.valid()) { - sol::error err = fx; - std::cerr << "failed to load string-based script into " - "the program" - << err.what() << std::endl; - } - - // prints "your arguments here" - fx("your", "arguments", "here"); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/functions_all.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/functions_all.cpp deleted file mode 100644 index 514ba6e9..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/functions_all.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -void some_function() { - std::cout << "some function!" << std::endl; -} - -void some_other_function() { - std::cout << "some other function!" << std::endl; -} - -struct some_class { - int variable = 30; - - double member_function() { - return 24.5; - } -}; - -int main(int, char*[]) { - std::cout << "=== functions (all) ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // put an instance of "some_class" into lua - // (we'll go into more detail about this later - // just know here that it works and is - // put into lua as a userdata - lua.set("sc", some_class()); - - // binds a plain function - lua["f1"] = some_function; - lua.set_function("f2", &some_other_function); - - // binds just the member function - lua["m1"] = &some_class::member_function; - - // binds the class to the type - lua.set_function( - "m2", &some_class::member_function, some_class {}); - - // binds just the member variable as a function - lua["v1"] = &some_class::variable; - - // binds class with member variable as function - lua.set_function( - "v2", &some_class::variable, some_class {}); - - lua.script(R"( - f1() -- some function! - f2() -- some other function! - - -- need class instance if you don't bind it with the function - print(m1(sc)) -- 24.5 - -- does not need class instance: was bound to lua with one - print(m2()) -- 24.5 - - -- need class instance if you - -- don't bind it with the function - print(v1(sc)) -- 30 - -- does not need class instance: - -- it was bound with one - print(v2()) -- 30 - - -- can set, still - -- requires instance - v1(sc, 212) - -- can set, does not need - -- class instance: was bound with one - v2(254) - - print(v1(sc)) -- 212 - print(v2()) -- 254 - )"); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/functions_easy.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/functions_easy.cpp deleted file mode 100644 index 5f0a8b5b..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/functions_easy.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.script("function f (a, b, c, d) return 1 end"); - lua.script("function g (a, b) return a + b end"); - - // sol::function is often easier: - // takes a variable number/types of arguments... - sol::function fx = lua["f"]; - // fixed signature std::function<...> - // can be used to tie a sol::function down - std::function stdfx - = fx; - - int is_one = stdfx(1, 34.5, 3, "bark"); - sol_c_assert(is_one == 1); - int is_also_one = fx(1, "boop", 3, "bark"); - sol_c_assert(is_also_one == 1); - - // call through operator[] - int is_three = lua["g"](1, 2); - sol_c_assert(is_three == 3); - double is_4_8 = lua["g"](2.4, 2.4); - sol_c_assert(is_4_8 == 4.8); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/make_tables.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/make_tables.cpp deleted file mode 100644 index 29c39f32..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/make_tables.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua["abc_sol2"] = lua.create_table_with(0, 24); - - sol::table inner_table = lua.create_table_with("bark", - 50, - // can reference other existing stuff too - "woof", - lua["abc_sol2"]); - lua.create_named_table("def_sol2", "ghi", inner_table); - - std::string code = R"( - abc = { [0] = 24 } - def = { - ghi = { - bark = 50, - woof = abc - } - } - )"; - - lua.script(code); - lua.script(R"( - assert(abc_sol2[0] == abc[0]) - assert(def_sol2.ghi.bark == def.ghi.bark) - )"); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/multiple_returns_from_lua.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/multiple_returns_from_lua.cpp deleted file mode 100644 index a3494e1e..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/multiple_returns_from_lua.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - sol::state lua; - - lua.script("function f (a, b, c) return a, b, c end"); - - std::tuple result; - result = lua["f"](100, 200, 300); - // result == { 100, 200, 300 } - int a; - int b; - std::string c; - sol::tie(a, b, c) = lua["f"](100, 200, "bark"); - sol_c_assert(a == 100); - sol_c_assert(b == 200); - sol_c_assert(c == "bark"); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/multiple_returns_to_lua.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/multiple_returns_to_lua.cpp deleted file mode 100644 index 98719851..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/multiple_returns_to_lua.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua["f"] = [](int a, int b, sol::object c) { - // sol::object can be anything here: just pass it - // through - return std::make_tuple(a, b, c); - }; - - std::tuple result = lua["f"](100, 200, 300); - const std::tuple expected(100, 200, 300); - sol_c_assert(result == expected); - - std::tuple result2; - result2 = lua["f"](100, 200, "BARK BARK BARK!"); - const std::tuple expected2( - 100, 200, "BARK BARK BARK!"); - sol_c_assert(result2 == expected2); - - int a, b; - std::string c; - sol::tie(a, b, c) = lua["f"](100, 200, "bark"); - sol_c_assert(a == 100); - sol_c_assert(b == 200); - sol_c_assert(c == "bark"); - - lua.script(R"( - a, b, c = f(150, 250, "woofbark") - assert(a == 150) - assert(b == 250) - assert(c == "woofbark") - )"); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/namespacing.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/namespacing.cpp deleted file mode 100644 index 86b44001..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/namespacing.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - std::cout << "=== namespacing ===" << std::endl; - - struct my_class { - int b = 24; - - int f() const { - return 24; - } - - void g() { - ++b; - } - }; - - sol::state lua; - lua.open_libraries(); - - // "bark" namespacing in Lua - // namespacing is just putting things in a table - // forces creation if it does not exist - auto bark = lua["bark"].get_or_create(); - // equivalent-ish: - // sol::table bark = lua["bark"].force(); // forces table - // creation equivalent, and more flexible: sol::table bark = - // lua["bark"].get_or_create(sol::new_table()); - // equivalent, but less efficient/ugly: - // sol::table bark = lua["bark"] = lua.get_or("bark", - // lua.create_table()); - bark.new_usertype("my_class", - "f", - &my_class::f, - "g", - &my_class::g); // the usual - - // can add functions, as well (just like the global table) - bark.set_function("print_my_class", [](my_class& self) { - std::cout << "my_class { b: " << self.b << " }" - << std::endl; - }); - - // this works - lua.script("obj = bark.my_class.new()"); - lua.script("obj:g()"); - - // calling this function also works - lua.script("bark.print_my_class(obj)"); - my_class& obj = lua["obj"]; - sol_c_assert(obj.b == 25); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/opening_a_state.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/opening_a_state.cpp deleted file mode 100644 index 9c7a88eb..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/opening_a_state.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main(int, char*[]) { - std::cout << "=== opening a state ===" << std::endl; - - sol::state lua; - // open some common libraries - lua.open_libraries(sol::lib::base, sol::lib::package); - lua.script("print('bark bark bark!')"); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/opening_state_on_raw_lua.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/opening_state_on_raw_lua.cpp deleted file mode 100644 index 0f5c7e5b..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/opening_state_on_raw_lua.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int use_sol2(lua_State* L) { - sol::state_view lua(L); - lua.script("print('bark bark bark!')"); - return 0; -} - -int main(int, char*[]) { - std::cout << "=== opening sol::state_view on raw Lua ===" - << std::endl; - - lua_State* L = luaL_newstate(); - luaL_openlibs(L); - - lua_pushcclosure(L, &use_sol2, 0); - lua_setglobal(L, "use_sol2"); - - if (luaL_dostring(L, "use_sol2()")) { - lua_error(L); - return -1; - } - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/running_lua_code.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/running_lua_code.cpp deleted file mode 100644 index 6ea0aba8..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/running_lua_code.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -int main(int, char*[]) { - std::cout << "=== running lua code ===" << std::endl; - - { - std::ofstream out("a_lua_script.lua"); - out << "print('hi from a lua script file')"; - } - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // load and execute from string - lua.script("a = 'test'"); - // load and execute from file - lua.script_file("a_lua_script.lua"); - - // run a script, get the result - int value = lua.script("return 54"); - sol_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 Can - // throw your own custom error You can also just - // return it, and let the call-site handle the - // error if necessary. - return pfr; - }); - // it did not work - sol_c_assert(!bad_code_result.valid()); - - // the default handler panics or throws, depending on your - // settings uncomment for explosions: auto bad_code_result_2 - // = lua.script("bad.code", &sol::script_default_on_error); - - std::cout << std::endl; - - { std::remove("a_lua_script.lua"); } - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/running_lua_code_low_level.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/running_lua_code_low_level.cpp deleted file mode 100644 index dcf56536..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/running_lua_code_low_level.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include -#include - -int main(int, char*[]) { - std::cout << "=== running lua code (low level) ===" - << std::endl; - - { - std::ofstream out("a_lua_script.lua"); - out << "print('hi from a lua script file')"; - } - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // load file without execute - sol::load_result script1 - = lua.load_file("a_lua_script.lua"); - // execute - script1(); - - // load string without execute - sol::load_result script2 = lua.load("a = 'test'"); - // execute - sol::protected_function_result script2result = script2(); - // optionally, check if it worked - if (script2result.valid()) { - // yay! - } - else { - // aww - } - - sol::load_result script3 = lua.load("return 24"); - // execute, get return value - int value2 = script3(); - sol_c_assert(value2 == 24); - - std::cout << std::endl; - - { std::remove("a_lua_script.lua"); } - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/running_lua_code_safely.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/running_lua_code_safely.cpp deleted file mode 100644 index 7e639cad..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/running_lua_code_safely.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -int main(int, char*[]) { - std::cout << "=== running lua code (safely) ===" - << std::endl; - - { - std::ofstream out("a_lua_script.lua"); - out << "print('hi from a lua script file')"; - } - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // load and execute from string - auto result = lua.safe_script( - "a = 'test'", sol::script_pass_on_error); - if (!result.valid()) { - sol::error err = result; - std::cerr << "The code has failed to run!\n" - << err.what() << "\nPanicking and exiting..." - << std::endl; - return 1; - } - - // load and execute from file - auto script_from_file_result = lua.safe_script_file( - "a_lua_script.lua", sol::script_pass_on_error); - if (!script_from_file_result.valid()) { - sol::error err = script_from_file_result; - std::cerr - << "The code from the file has failed to run!\n" - << err.what() << "\nPanicking and exiting..." - << std::endl; - return 1; - } - - // run a script, get the result - sol::optional maybe_value = lua.safe_script( - "return 54", sol::script_pass_on_error); - sol_c_assert(maybe_value.has_value()); - sol_c_assert(*maybe_value == 54); - - auto bad_code_result = lua.safe_script( - "123 herp.derp", sol::script_pass_on_error); - sol_c_assert(!bad_code_result.valid()); - - // you can also specify a handler function, and it'll - // properly work here - auto bad_code_result2 = 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 Can - // throw your own custom error You can also just - // return it, and let the call-site handle the - // error if necessary. - return pfr; - }); - // it did not work - sol_c_assert(!bad_code_result2.valid()); - - // the default handler panics or throws, depending on your - // settings uncomment for explosions: auto bad_code_result_2 - // = lua.script("bad.code", &sol::script_default_on_error); - - std::cout << std::endl; - - { std::remove("a_lua_script.lua"); } - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/self_call.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/self_call.cpp deleted file mode 100644 index d29e0ebb..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/self_call.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - std::cout << "=== self_call ===" << std::endl; - - sol::state lua; - lua.open_libraries( - sol::lib::base, sol::lib::package, sol::lib::table); - - // a small script using 'self' syntax - lua.script(R"( - some_table = { some_val = 100 } - - function some_table:add_to_some_val(value) - self.some_val = self.some_val + value - end - - function print_some_val() - print("some_table.some_val = " .. some_table.some_val) - end - )"); - - // do some printing - lua["print_some_val"](); - // 100 - - sol::table self = lua["some_table"]; - self["add_to_some_val"](self, 10); - lua["print_some_val"](); - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/set_and_get_variables.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/set_and_get_variables.cpp deleted file mode 100644 index e9bb561f..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/set_and_get_variables.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - sol::state lua; - lua.open_libraries(sol::lib::base); - - // integer types - lua.set("number", 24); - // floating point numbers - lua["number2"] = 24.5; - // string types - lua["important_string"] = "woof woof"; - // is callable, therefore gets stored as a function that can - // be called - lua["a_function"] = []() { return 100; }; - // make a table - lua["some_table"] = lua.create_table_with("value", 24); - - - // equivalent to this code - std::string equivalent_code = R"( - t = { - number = 24, - number2 = 24.5, - important_string = "woof woof", - a_function = function () return 100 end, - some_table = { value = 24 } - } - )"; - - // check in Lua - lua.script(equivalent_code); - - lua.script(R"( - assert(t.number == number) - assert(t.number2 == number2) - assert(t.important_string == important_string) - assert(t.a_function() == a_function()) - assert(t.some_table.value == some_table.value) - )"); - - - // implicit conversion - int number = lua["number"]; - sol_c_assert(number == 24); - // explicit get - auto number2 = lua.get("number2"); - sol_c_assert(number2 == 24.5); - // strings too - std::string important_string = lua["important_string"]; - sol_c_assert(important_string == "woof woof"); - // dig into a table - int value = lua["some_table"]["value"]; - sol_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(); - sol_c_assert(value_is_100 == 100); - sol_c_assert(value_is_still_100 == 100); - - sol::object number_obj = lua.get("number"); - // sol::type::number - sol::type t1 = number_obj.get_type(); - sol_c_assert(t1 == sol::type::number); - - sol::object function_obj = lua["a_function"]; - // sol::type::function - sol::type t2 = function_obj.get_type(); - sol_c_assert(t2 == sol::type::function); - bool is_it_really = function_obj.is>(); - sol_c_assert(is_it_really); - - // will not contain data - sol::optional check_for_me = lua["a_function"]; - sol_c_assert(check_for_me == sol::nullopt); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/set_and_get_variables_exists.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/set_and_get_variables_exists.cpp deleted file mode 100644 index 26a05d71..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/set_and_get_variables_exists.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.script("exists = 250"); - - int first_try = lua.get_or("exists", 322); - sol_c_assert(first_try == 250); - - lua.set("exists", sol::lua_nil); - int second_try = lua.get_or("exists", 322); - sol_c_assert(second_try == 322); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/tables_and_nesting.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/tables_and_nesting.cpp deleted file mode 100644 index 20dbab04..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/tables_and_nesting.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -int main(int, char*[]) { - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.script(R"( - abc = { [0] = 24 } - def = { - ghi = { - bark = 50, - woof = abc - } - } - )"); - - sol::table abc = lua["abc"]; - sol::table def = lua["def"]; - sol::table ghi = lua["def"]["ghi"]; - - int bark1 = def["ghi"]["bark"]; - int bark2 = lua["def"]["ghi"]["bark"]; - sol_c_assert(bark1 == 50); - sol_c_assert(bark2 == 50); - - int abcval1 = abc[0]; - int abcval2 = ghi["woof"][0]; - sol_c_assert(abcval1 == 24); - sol_c_assert(abcval2 == 24); - - sol::optional will_not_error - = lua["abc"]["DOESNOTEXIST"]["ghi"]; - sol_c_assert(will_not_error == sol::nullopt); - - int also_will_not_error - = lua["abc"]["def"]["ghi"]["jklm"].get_or(25); - sol_c_assert(also_will_not_error == 25); - - // if you don't go safe, - // will throw (or do at_panic if no exceptions) - // int aaaahhh = lua["boom"]["the_dynamite"]; - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/userdata.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/userdata.cpp deleted file mode 100644 index 6520d8c9..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/userdata.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct Doge { - int tailwag = 50; - - Doge() { - } - - Doge(int wags) : tailwag(wags) { - } - - ~Doge() { - std::cout << "Dog at " << this - << " is being destroyed..." << std::endl; - } -}; - -int main(int, char*[]) { - std::cout << "=== userdata ===" << std::endl; - - sol::state lua; - - Doge dog { 30 }; - - // fresh one put into Lua - lua["dog"] = Doge {}; - // Copy into lua: destroyed by Lua VM during garbage - // collection - lua["dog_copy"] = dog; - // OR: move semantics - will call move constructor if - // present instead Again, owned by Lua - lua["dog_move"] = std::move(dog); - lua["dog_unique_ptr"] = std::make_unique(25); - lua["dog_shared_ptr"] = std::make_shared(31); - - // Identical to above - Doge dog2 { 30 }; - lua.set("dog2", Doge {}); - lua.set("dog2_copy", dog2); - lua.set("dog2_move", std::move(dog2)); - lua.set("dog2_unique_ptr", - std::unique_ptr(new Doge(25))); - lua.set("dog2_shared_ptr", - std::shared_ptr(new Doge(31))); - - // Note all of them can be retrieved the same way: - Doge& lua_dog = lua["dog"]; - Doge& lua_dog_copy = lua["dog_copy"]; - 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"]; - sol_c_assert(lua_dog.tailwag == 50); - sol_c_assert(lua_dog_copy.tailwag == 30); - sol_c_assert(lua_dog_move.tailwag == 30); - sol_c_assert(lua_dog_unique_ptr.tailwag == 25); - sol_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 - - // Use a C++ reference to handle memory directly - // otherwise take by value, without '&' - lua["f"] = [](Doge& dog) { - std::cout << "dog wags its tail " << dog.tailwag - << " times!" << std::endl; - }; - - // if you bind a function using a pointer, - // you can handle when `nil` is passed - lua["handling_f"] = [](Doge* dog) { - if (dog == nullptr) { - std::cout << "dog was nil!" << std::endl; - return; - } - std::cout << "dog wags its tail " << dog->tailwag - << " times!" << std::endl; - }; - - lua.script(R"( - f(dog) - f(dog_copy) - f(dog_move) - f(dog_unique_ptr) - f(dog_shared_ptr) - - -- C++ arguments that are pointers can handle nil - handling_f(dog) - handling_f(dog_copy) - handling_f(dog_move) - handling_f(dog_unique_ptr) - handling_f(dog_shared_ptr) - handling_f(nil) - - -- never do this - -- f(nil) - )"); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/userdata_memory_reference.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/userdata_memory_reference.cpp deleted file mode 100644 index 5d32d4f3..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/userdata_memory_reference.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct Doge { - int tailwag = 50; - - Doge() { - } - - Doge(int wags) : tailwag(wags) { - } - - ~Doge() { - std::cout << "Dog at " << this - << " is being destroyed..." << std::endl; - } -}; - -int main(int, char*[]) { - std::cout << "=== userdata memory reference ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - Doge dog {}; // Kept alive somehow - - // Later... - // The following stores a reference, and does not copy/move - // lifetime is same as dog in C++ - // (access after it is destroyed is bad) - lua["dog"] = &dog; - // Same as above: respects std::reference_wrapper - lua["dog"] = std::ref(dog); - // These two are identical to above - lua.set("dog", &dog); - lua.set("dog", std::ref(dog)); - - - Doge& dog_ref = lua["dog"]; // References Lua memory - Doge* dog_pointer = lua["dog"]; // References Lua memory - Doge dog_copy = lua["dog"]; // Copies, will not affect lua - - lua.new_usertype("Doge", "tailwag", &Doge::tailwag); - - dog_copy.tailwag = 525; - // Still 50 - lua.script("assert(dog.tailwag == 50)"); - - dog_ref.tailwag = 100; - // Now 100 - lua.script("assert(dog.tailwag == 100)"); - - dog_pointer->tailwag = 345; - // Now 345 - lua.script("assert(dog.tailwag == 345)"); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/quick_n_dirty/usertypes.cpp b/third/sol2/examples/source/tutorials/quick_n_dirty/usertypes.cpp deleted file mode 100644 index 3070af50..00000000 --- a/third/sol2/examples/source/tutorials/quick_n_dirty/usertypes.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct Doge { - int tailwag = 50; - - Doge() { - } - - Doge(int wags) : tailwag(wags) { - } - - ~Doge() { - std::cout << "Dog at " << this - << " is being destroyed..." << std::endl; - } -}; - -int main(int, char*[]) { - std::cout << "=== usertypes ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - Doge dog { 30 }; - - lua["dog"] = Doge {}; - lua["dog_copy"] = dog; - lua["dog_move"] = std::move(dog); - lua["dog_unique_ptr"] = std::make_unique(21); - lua["dog_shared_ptr"] = std::make_shared(51); - - // now we can access these types in Lua - lua.new_usertype("Doge", - sol::constructors(), - "tailwag", - &Doge::tailwag); - lua.script(R"( - function f (dog) - if dog == nil then - print('dog was nil!') - return - end - print('dog wags its tail ' .. dog.tailwag .. ' times!') - end - )"); - - lua.script(R"( - dog_lua = Doge.new() - - f(dog_lua) - f(dog) - f(dog_copy) - f(dog_move) - f(dog) - f(dog_unique_ptr) - f(dog_shared_ptr) - f(nil) - )"); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/reading_functions.cpp b/third/sol2/examples/source/tutorials/reading_functions.cpp deleted file mode 100644 index f1df362d..00000000 --- a/third/sol2/examples/source/tutorials/reading_functions.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -int main() { - - sol::state lua; - - lua.script(R"( - function f (a) - return a + 5 - end - )"); - - // Get and immediately call - int x = lua["f"](30); - sol_c_assert(x == 35); - - // Store it into a variable first, then call - sol::unsafe_function f = lua["f"]; - int y = f(20); - sol_c_assert(y == 25); - - // Store it into a variable first, then call - sol::protected_function safe_f = lua["f"]; - int z = safe_f(45); - sol_c_assert(z == 50); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/variables_demo.cpp b/third/sol2/examples/source/tutorials/variables_demo.cpp deleted file mode 100644 index 3e9a9612..00000000 --- a/third/sol2/examples/source/tutorials/variables_demo.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include // for std::pair - -int main() { - - sol::state lua; - /* - lua.script_file("variables.lua"); - */ - lua.script(R"( -config = { - fullscreen = false, - resolution = { x = 1024, y = 768 } -} - )"); - // the type "sol::state" behaves - // exactly like a table! - bool isfullscreen - = lua["config"] - ["fullscreen"]; // can get nested variables - sol::table config = lua["config"]; - sol_c_assert(!isfullscreen); - - // can also get it using the "get" member function - // auto replaces the unqualified type name - auto resolution = config.get("resolution"); - - // table and state can have multiple things pulled out of it - // too - std::tuple xyresolutiontuple - = resolution.get("x", "y"); - sol_c_assert(std::get<0>(xyresolutiontuple) == 1024); - sol_c_assert(std::get<1>(xyresolutiontuple) == 768); - - // test variable - auto bark = lua["config"]["bark"]; - if (bark.valid()) { - // branch not taken: config and/or bark are not - // variables - } - else { - // Branch taken: config and bark are existing variables - } - - // can also use optional - sol::optional not_an_integer - = lua["config"]["fullscreen"]; - if (not_an_integer) { - // Branch not taken: value is not an integer - } - - sol::optional is_a_boolean - = lua["config"]["fullscreen"]; - if (is_a_boolean) { - // Branch taken: the value is a boolean - } - - sol::optional does_not_exist - = lua["not_a_variable"]; - if (does_not_exist) { - // Branch not taken: that variable is not present - } - - // this will result in a value of '24' - // (it tries to get a number, and fullscreen is - // not a number - int is_defaulted = lua["config"]["fullscreen"].get_or(24); - sol_c_assert(is_defaulted == 24); - - // This will result in the value of the config, which is - // 'false' - bool is_not_defaulted = lua["config"]["fullscreen"]; - sol_c_assert(!is_not_defaulted); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/write_variables_demo.cpp b/third/sol2/examples/source/tutorials/write_variables_demo.cpp deleted file mode 100644 index d0d03b8b..00000000 --- a/third/sol2/examples/source/tutorials/write_variables_demo.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - - sol::state lua; - - // open those basic lua libraries - // again, for print() and other basic utilities - lua.open_libraries(sol::lib::base); - - // value in the global table - lua["bark"] = 50; - - // a table being created in the global table - lua["some_table"] = lua.create_table_with("key0", - 24, - "key1", - 25, - lua["bark"], - "the key is 50 and this string is its value!"); - - // Run a plain ol' string of lua code - // Note you can interact with things set through sol in C++ - // with lua! Using a "Raw String Literal" to have multi-line - // goodness: - // http://en.cppreference.com/w/cpp/language/string_literal - lua.script(R"( - - print(some_table[50]) - print(some_table["key0"]) - print(some_table["key1"]) - - -- a lua comment: access a global in a lua script with the _G table - print(_G["bark"]) - - )"); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/writing_functions.cpp b/third/sol2/examples/source/tutorials/writing_functions.cpp deleted file mode 100644 index 2be15479..00000000 --- a/third/sol2/examples/source/tutorials/writing_functions.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -std::string my_function(int D_count, std::string original) { - // Create a string with the letter 'D' "D_count" times, - // append it to 'original' - return original + std::string(D_count, 'D'); -} - -int main() { - - sol::state lua; - - lua["my_func"] = my_function; // way 1 - lua.set("my_func", my_function); // way 2 - lua.set_function("my_func", my_function); // way 3 - - // This function is now accessible as 'my_func' in - // lua scripts / code run on this state: - lua.script("some_str = my_func(1, 'Da')"); - - // Read out the global variable we stored in 'some_str' in - // the quick lua code we just executed - std::string some_str = lua["some_str"]; - sol_c_assert(some_str == "DaD"); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/writing_member_functions.cpp b/third/sol2/examples/source/tutorials/writing_member_functions.cpp deleted file mode 100644 index 49e0f72e..00000000 --- a/third/sol2/examples/source/tutorials/writing_member_functions.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -struct my_class { - int a = 0; - - my_class(int x) : a(x) { - } - - int func() { - ++a; // increment a by 1 - return a; - } -}; - -int main() { - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // Here, we are binding the member function and a class - // instance: it will call the function on the given class - // instance - lua.set_function( - "my_class_func", &my_class::func, my_class(0)); - - // We do not pass a class instance here: - // the function will need you to pass an instance of - // "my_class" to it in lua to work, as shown below - lua.set_function("my_class_func_2", &my_class::func); - - // With a pre-bound instance: - lua.script(R"( - first_value = my_class_func() - second_value = my_class_func() - assert(first_value == 1) - assert(second_value == 2) - )"); - - // With no bound instance: - lua.set("obj", my_class(24)); - // Calls "func" on the class instance - // referenced by "obj" in Lua - lua.script(R"( - third_value = my_class_func_2(obj) - fourth_value = my_class_func_2(obj) - assert(third_value == 25) - assert(fourth_value == 26) - )"); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/writing_overloaded_template_functions.cpp b/third/sol2/examples/source/tutorials/writing_overloaded_template_functions.cpp deleted file mode 100644 index 4fa98633..00000000 --- a/third/sol2/examples/source/tutorials/writing_overloaded_template_functions.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -template -auto my_add(A a, B b) { - return a + b; -} - -int main() { - - sol::state lua; - - auto int_function_pointer = &my_add; - auto string_function_pointer - = &my_add; - // adds 2 integers, or "adds" (concatenates) two strings - lua["my_combine"] = sol::overload( - int_function_pointer, string_function_pointer); - - lua.script("my_num = my_combine(1, 2)"); - lua.script( - "my_str = my_combine('bark bark', ' woof woof')"); - int my_num = lua["my_num"]; - std::string my_str = lua["my_str"]; - sol_c_assert(my_num == 3); - sol_c_assert(my_str == "bark bark woof woof"); - - return 0; -} diff --git a/third/sol2/examples/source/tutorials/writing_template_functions.cpp b/third/sol2/examples/source/tutorials/writing_template_functions.cpp deleted file mode 100644 index 6926645e..00000000 --- a/third/sol2/examples/source/tutorials/writing_template_functions.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -template -auto my_add(A a, B b) { - return a + b; -} - -int main() { - - sol::state lua; - - // adds 2 integers - auto int_function_pointer = &my_add; - lua["my_int_add"] = int_function_pointer; - - // concatenates 2 strings - auto string_function_pointer - = &my_add; - lua["my_string_combine"] = string_function_pointer; - - lua.script("my_num = my_int_add(1, 2)"); - int my_num = lua["my_num"]; - sol_c_assert(my_num == 3); - - lua.script( - "my_str = my_string_combine('bark bark', ' woof " - "woof')"); - std::string my_str = lua["my_str"]; - sol_c_assert(my_str == "bark bark woof woof"); - - return 0; -} diff --git a/third/sol2/examples/source/unique_ptr.cpp b/third/sol2/examples/source/unique_ptr.cpp deleted file mode 100644 index 5c7552aa..00000000 --- a/third/sol2/examples/source/unique_ptr.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - - -#include - -struct my_type { - int value = 10; - - my_type() { - std::cout << "my_type at " << static_cast(this) - << " being default constructed!" - << std::endl; - } - - my_type(const my_type& other) : value(other.value) { - std::cout << "my_type at " << static_cast(this) - << " being copy constructed!" << std::endl; - } - - my_type(my_type&& other) : value(other.value) { - std::cout << "my_type at " << static_cast(this) - << " being move-constructed!" << std::endl; - } - - my_type& operator=(const my_type& other) { - value = other.value; - std::cout << "my_type at " << static_cast(this) - << " being copy-assigned to!" << std::endl; - return *this; - } - - my_type& operator=(my_type&& other) { - value = other.value; - std::cout << "my_type at " << static_cast(this) - << " being move-assigned to!" << std::endl; - return *this; - } - - ~my_type() { - std::cout << "my_type at " << static_cast(this) - << " being destructed!" << std::endl; - } -}; - -int main() { - - std::cout << "=== unique_ptr support ===" << std::endl; - - sol::state lua; - lua.new_usertype( - "my_type", "value", &my_type::value); - { - std::unique_ptr unique - = std::make_unique(); - lua["unique"] = std::move(unique); - } - { - std::cout << "getting reference to unique_ptr..." - << std::endl; - std::unique_ptr& ref_to_unique_ptr - = lua["unique"]; - my_type& ref_to_my_type = lua["unique"]; - my_type* ptr_to_my_type = lua["unique"]; - - sol_c_assert( - ptr_to_my_type == ref_to_unique_ptr.get()); - sol_c_assert( - &ref_to_my_type == ref_to_unique_ptr.get()); - sol_c_assert(ref_to_unique_ptr->value == 10); - - // script affects all of them equally - lua.script("unique.value = 20"); - - sol_c_assert(ptr_to_my_type->value == 20); - sol_c_assert(ref_to_my_type.value == 20); - sol_c_assert(ref_to_unique_ptr->value == 20); - } - { - std::cout << "getting copy of unique_ptr..." - << std::endl; - my_type copy_of_value = lua["unique"]; - - sol_c_assert(copy_of_value.value == 20); - - // script still affects pointer, but does not affect - // copy of `my_type` - lua.script("unique.value = 30"); - - sol_c_assert(copy_of_value.value == 20); - } - // set to nil and collect garbage to destroy it - lua.script("unique = nil"); - lua.collect_garbage(); - lua.collect_garbage(); - - std::cout << "garbage has been collected" << std::endl; - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/usertype.cpp b/third/sol2/examples/source/usertype.cpp deleted file mode 100644 index 24e263f8..00000000 --- a/third/sol2/examples/source/usertype.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -struct foo { -private: - std::string name; - -public: - foo(std::string name) : name(std::string(name)) { - } - - void print() { - std::cout << name << '\n'; - } - - int test(int x) { - return static_cast(name.length()) + x; - } -}; - -struct vector { -private: - float x = 0; - float y = 0; - -public: - vector() = default; - vector(float x) : x(x) { - } - vector(float x, float y) : x(x), y(y) { - } - - bool is_unit() const { - return (x * x + y * y) == 1.f; - } -}; - -struct variables { - bool low_gravity = false; - int boost_level = 0; -}; - -int main() { - std::cout << "=== usertype ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base, sol::lib::math); - - // the simplest way to create a class is through - // sol::state::new_userdata - // the first template is the class type - // the rest are the constructor parameters - // using new_userdata you can only have one constructor - - - // you must make sure that the name of the function - // goes before the member function pointer - lua.new_usertype("foo", - sol::constructors(), - "print", - &foo::print, - "test", - &foo::test); - - // making the class from lua is simple - // same with calling member functions - lua.script( - "x = foo.new('test')\n" - "x:print()\n" - "y = x:test(10)"); - - auto y = lua.get("y"); - std::cout << y << std::endl; // show 14 - - // if you want a class to have more than one constructor - // the way to do so is through set_userdata and creating - // a userdata yourself with constructor types - - { - // Notice the brace: this means we're in a new scope - - // first, define the different types of constructors - // notice here that the return type - // on the function-type doesn't exactly matter, - // which allows you to use a shorter class name/void - // if necessary - sol::constructors - ctor; - // then you must register it - sol::usertype utype - = lua.new_usertype("vector", ctor); - - // add to it as much as you like - utype["is_unit"] = &vector::is_unit; - // You can throw away the usertype after - // you set it: you do NOT - // have to keep it around - // cleanup happens automagically! - } - - // calling it is the same as - // working with userdata is C++ - lua.script( - "v = vector.new()\n" - "v = vector.new(12)\n" - "v = vector.new(10, 10)\n" - "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 - lua.new_usertype("variables", - "low_gravity", - &variables::low_gravity, - "boost_level", - &variables::boost_level); - - // making the class from lua is simple - // same with calling member functions/variables - lua.script( - "local vars = variables.new()\n" - "assert(not vars.low_gravity)\n" - "vars.low_gravity = true\n" - "local x = vars.low_gravity\n" - "assert(x)"); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/usertype_advanced.cpp b/third/sol2/examples/source/usertype_advanced.cpp deleted file mode 100644 index 19abf395..00000000 --- a/third/sol2/examples/source/usertype_advanced.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -/* -#include "player.hpp" -*/ - -#include - -struct player { -public: - int bullets; - int speed; - - player() : player(3, 100) { - } - - player(int ammo) : player(ammo, 100) { - } - - player(int ammo, int hitpoints) - : bullets(ammo), hp(hitpoints) { - } - - void boost() { - speed += 10; - } - - bool shoot() { - if (bullets < 1) - return false; - --bullets; - return true; - } - - void set_hp(int value) { - hp = value; - } - - int get_hp() const { - return hp; - } - -private: - int hp; -}; - -int main() { - std::cout << "=== usertype_advanced ===" << std::endl; - sol::state lua; - - lua.open_libraries(sol::lib::base); - - // note that you can set a - // userdata before you register a usertype, - // and it will still carry - // the right metatable if you register it later - - // set a variable "p2" of type "player" with 0 ammo - lua["p2"] = player(0); - - // make usertype metatable - sol::usertype player_type - = lua.new_usertype("player", - // 3 constructors - sol::constructors()); - - // typical member function that returns a variable - player_type["shoot"] = &player::shoot; - // typical member function - player_type["boost"] = &player::boost; - - // gets or set the value using member variable syntax - player_type["hp"] - = sol::property(&player::get_hp, &player::set_hp); - - // read and write variable - player_type["speed"] = &player::speed; - // can only read from, not write to - // .set(foo, bar) is the same as [foo] = bar; - player_type.set("bullets", sol::readonly(&player::bullets)); - - // You can also add members to the code, defined in Lua! - // This lets you have a high degree of flexibility in the - // code - std::string prelude_script = R"( -function player:brake () - self.speed = 0 - print("we hit the brakes!") -end -)"; - - std::string player_script = R"( --- call single argument integer constructor -p1 = player.new(2) - --- p2 is still here from being --- set with lua["p2"] = player(0); below -local p2shoots = p2:shoot() -assert(not p2shoots) --- had 0 ammo - --- set variable property setter -p1.hp = 545 --- get variable through property unqualified_getter -print(p1.hp) -assert(p1.hp == 545) - -local did_shoot_1 = p1:shoot() -print(did_shoot_1) -print(p1.bullets) -local did_shoot_2 = p1:shoot() -print(did_shoot_2) -print(p1.bullets) -local did_shoot_3 = p1:shoot() -print(did_shoot_3) - --- can read -print(p1.bullets) --- would error: is a readonly variable, cannot write --- p1.bullets = 20 - -p1:boost() --- call the function we define at runtime from a Lua script -p1:brake() -)"; - - // Uncomment and use the file to try that out, too! - // Make sure it's in the local directory of the executable - // after you build, or adjust the filename path Or whatever - // else you like! - // - /* - lua.script_file("prelude_script.lua"); - lua.script_file("player_script.lua"); - */ - lua.script(prelude_script); - lua.script(player_script); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/usertype_automatic_operators.cpp b/third/sol2/examples/source/usertype_automatic_operators.cpp deleted file mode 100644 index 67dcc608..00000000 --- a/third/sol2/examples/source/usertype_automatic_operators.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -#include - -class automatic { -private: - std::list data; - -public: - using value_type = decltype(data)::value_type; - using iterator = decltype(data)::const_iterator; - using size_type = decltype(data)::size_type; - - // automatically bound to obj( args... ) [ __call ] - void operator()() { - data.push_back( - static_cast(data.size() + 1) / 3.0); - } - - // automatically used for pairs(obj) [ __pairs ], 5.2+ - iterator begin() const { - return data.begin(); - } - iterator end() const { - return data.end(); - } - - // automatically bound to #obj [ __len ] - size_type size() const { - return data.size(); - } - - // automatically bound for obj == obj [ __eq ] - bool operator==(const automatic& right) const { - return data == right.data; - } - // automatically bound for obj < obj [ __lt ] - bool operator<(const automatic& right) const { - return data < right.data; - } - // automatically bound for obj <= obj [ __le ] - bool operator<=(const automatic& right) const { - return data <= right.data; - } - // other comparison operators are based off the above in Lua - // and cannot be overridden directly -}; - -// automatically bound to tostring(obj) [ __tostring ] -std::ostream& operator<<( - std::ostream& os, const automatic& right) { - if (right.size() == 0) { - os << "{ empty }"; - return os; - } - auto b = right.begin(); - auto e = right.end(); - os << "{ " << right.size() << " | "; - os << *b; - ++b; - while (b != e) { - os << ", " << *b; - ++b; - } - os << " }"; - return os; -} - -int main(int, char*[]) { - std::cout << "=== usertype automatic operators ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("automatic"); - - lua.script(R"( -obj1 = automatic.new() -obj2 = automatic.new() -obj3 = automatic.new() - -print("obj1:", obj1) -print("obj2:", obj2) -print("obj3:", obj2) - -print("#obj1:", #obj1) -print("#obj2:", #obj2) -print("#obj3:", #obj3) - -obj1() obj1() obj1() obj1() obj1() obj1() -obj2() obj2() obj2() -obj3() obj3() obj3() - -print("after modifications using obj() operator") -print("obj1:", obj1) -print("obj2:", obj2) -print("obj3:", obj2) - -print("#obj1:", #obj1) -print("#obj2:", #obj2) -print("#obj3:", #obj3) - - )"); -#if SOL_LUA_VERSION_I_ > 501 - lua.script(R"( -for k, v in pairs(obj1) do - assert( (k / 3) == v ) -end -)"); -#endif - - lua.script(R"( -print("obj1 == obj2:", obj1 == obj2) -print("obj1 < obj2:", obj1 < obj2) -print("obj1 >= obj2:", obj1 >= obj2) -assert(obj1 ~= obj2) -assert(obj1 > obj2) -assert(obj1 >= obj2) - -print("obj2 == obj3:", obj2 == obj3) -print("obj2 > obj3:", obj2 > obj3) -print("obj2 <= obj3:", obj2 <= obj3) -assert(obj2 == obj3) -assert(obj2 <= obj3) - )"); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/usertype_basics.cpp b/third/sol2/examples/source/usertype_basics.cpp deleted file mode 100644 index b89925ad..00000000 --- a/third/sol2/examples/source/usertype_basics.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct ship { - int bullets = 20; - int life = 100; - - bool shoot() { - if (bullets > 0) { - --bullets; - // successfully shot - return true; - } - // cannot shoot - return false; - } - - bool hurt(int by) { - life -= by; - // have we died? - return life < 1; - } -}; - - -int main() { - - std::cout << "=== usertype basics ===" << std::endl; - - static const bool way_1 = true; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - if (way_1) { - lua.new_usertype( - "ship", // the name of the class, as you want it - // to be used in lua List the member - // functions you wish to bind: - // "name_of_item", - // &class_name::function_or_variable - "shoot", - &ship::shoot, - "hurt", - &ship::hurt, - // bind variable types, too - "life", - &ship::life, - // names in lua don't have to be the same as C++, - // but it probably helps if they're kept the same, - // here we change it just to show its possible - "bullet_count", - &ship::bullets); - } - else { - // set usertype explicitly, with the given name - sol::usertype usertype_table - = lua.new_usertype("ship"); - usertype_table["shoot"] = &ship::shoot; - usertype_table["hurt"] = &ship::hurt; - usertype_table["life"] = &ship::life; - usertype_table["bullet_count"] = &ship::bullets; - } - - const auto& code = R"( - fwoosh = ship.new() - -- note the ":" that is there: this is mandatory for member function calls - -- ":" means "pass self" in Lua - local success = fwoosh:shoot() - local is_dead = fwoosh:hurt(20) - -- check if it works - print(is_dead) -- the ship is not dead at this point - print(fwoosh.life .. "life left") -- 80 life left - print(fwoosh.bullet_count) -- 19 - )"; - - - lua.script(code); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/usertype_bitfields.cpp b/third/sol2/examples/source/usertype_bitfields.cpp deleted file mode 100644 index 7edf75a7..00000000 --- a/third/sol2/examples/source/usertype_bitfields.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include -#include -#include - -namespace itsy_bitsy { - - template - struct bit_type { - typedef uint64_t type; - }; - - template - struct bit_type> { - typedef bool type; - }; - - template - struct bit_type 2 && sz <= 16)>> { - typedef uint16_t type; - }; - - template - struct bit_type 16 && sz <= 32)>> { - typedef uint32_t type; - }; - - template - struct bit_type 32 && sz <= 64)>> { - typedef uint64_t type; - }; - - template - using bit_type_t = typename bit_type::type; - - template - bool vcxx_warning_crap(std::true_type, V val) { - return val != 0; - } - - template - T vcxx_warning_crap(std::false_type, V val) { - return static_cast(val); - } - - template - auto vcxx_warning_crap(V val) { - return vcxx_warning_crap( - std::is_same(), val); - } - - template - void write(Base& b, bit_type_t bits) { - typedef bit_type_t - aligned_type; - static const std::size_t aligned_type_bit_size - = sizeof(aligned_type) * CHAR_BIT; - static_assert( - sizeof(Base) * CHAR_BIT >= (bit_target + size), - "bit offset and size are too large for the " - "desired structure."); - static_assert((bit_target % aligned_type_bit_size) - <= ((bit_target + size) - % aligned_type_bit_size), - "bit offset and size cross beyond largest " - "integral constant boundary."); - - const std::size_t aligned_target - = (bit_target + size) / aligned_type_bit_size; - const aligned_type bits_left - = static_cast( - bit_target - aligned_target); - const aligned_type shifted_mask - = ((static_cast(1) << size) - 1) - << bits_left; - const aligned_type compl_shifted_mask = ~shifted_mask; - // Jump by native size of a pointer to target - // then OR the bits - aligned_type* jumper = static_cast( - static_cast(&b)); - jumper += aligned_target; - aligned_type& aligned = *jumper; - aligned &= compl_shifted_mask; - aligned - |= (static_cast(bits) << bits_left); - } - - template - bit_type_t read(Base& b) { - typedef bit_type_t - aligned_type; - typedef bit_type_t field_type; - static const std::size_t aligned_type_bit_size - = sizeof(aligned_type) * CHAR_BIT; - static_assert( - sizeof(Base) * CHAR_BIT >= (bit_target + size), - "bit offset and size are too large for the " - "desired structure."); - static_assert((bit_target % aligned_type_bit_size) - <= ((bit_target + size) - % aligned_type_bit_size), - "bit offset and size cross beyond largest " - "integral constant boundary."); - - const std::size_t aligned_target - = (bit_target + size) / aligned_type_bit_size; - const aligned_type bits_left - = static_cast( - bit_target - aligned_target); - const aligned_type mask - = (static_cast(1) << size) - 1; - // Jump by native size of a pointer to target - // then OR the bits - aligned_type* jumper = static_cast( - static_cast(&b)); - jumper += aligned_target; - const aligned_type& aligned = *jumper; - aligned_type field_bits - = (aligned >> bits_left) & mask; - field_type bits - = vcxx_warning_crap(field_bits); - return bits; - } - -} // namespace itsy_bitsy - -#include - -#if defined(_MSC_VER) || defined(__MINGW32__) -#pragma pack(1) -struct alignas(sizeof(uint32_t)) flags_t { -#else -struct __attribute__((packed, aligned(sizeof(uint32_t)))) -flags_t { -#endif - uint8_t C : 1; - uint8_t N : 1; - uint8_t PV : 1; - uint8_t _3 : 1; - uint8_t H : 1; - uint8_t _5 : 1; - uint8_t Z : 1; - uint8_t S : 1; - uint16_t D : 14; -} flags { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -int main() { - std::cout << "=== usertype_bitfields ===" << std::endl; -#ifdef __MINGW32__ - std::cout << "MinGW Detected, packing structs is broken in " - "MinGW and this test may fail" - << std::endl; -#endif - sol::state lua; - lua.open_libraries(); - - lua.new_usertype("flags_t", - "C", - sol::property(itsy_bitsy::read, - itsy_bitsy::write), - "N", - sol::property(itsy_bitsy::read, - itsy_bitsy::write), - "D", - sol::property(itsy_bitsy::read, - itsy_bitsy::write)); - - lua["f"] = std::ref(flags); - - lua.script(R"( - print(f.C) - f.C = true; - print(f.C) - - print(f.N) - f.N = true; - print(f.N) - - print(f.D) - f.D = 0xDF; - print(f.D) -)"); - - bool C = flags.C; - bool N = flags.N; - uint16_t D = flags.D; - - std::cout << std::hex; - std::cout << "sizeof(flags): " << sizeof(flags) - << std::endl; - std::cout << "C: " << C << std::endl; - std::cout << "N: " << N << std::endl; - std::cout << "D: " << D << std::endl; - - sol_c_assert(C); - sol_c_assert(N); - sol_c_assert(D == 0xDF); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/usertype_call_from_c++.cpp b/third/sol2/examples/source/usertype_call_from_c++.cpp deleted file mode 100644 index 55d790c0..00000000 --- a/third/sol2/examples/source/usertype_call_from_c++.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main(int, char*[]) { - std::cout << "=== usertype call from C++ ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - struct cpp_object { - int value = 5; - }; - - struct test { - int value = 0; - - int func(const cpp_object& obj) { - std::cout << "func\t" << obj.value << std::endl; - value += obj.value; - return value; - } - }; - - lua.new_usertype( - "test", "value", &cpp_object::value); - lua.new_usertype("test", "func", &test::func); - lua.script( - "function test:lua_func(obj) print('lua_func', " - "obj.value) end"); - - lua["obj"] = test {}; - cpp_object cppobj; - - lua["obj"]["func"](lua["obj"], cppobj); - lua["obj"]["lua_func"](lua["obj"], cppobj); - - lua["test"]["func"](lua["obj"], cppobj); - lua["test"]["lua_func"](lua["obj"], cppobj); - - // crashes - // lua["obj"]["func"](cppobj); - // lua["obj"]["lua_func"](cppobj); - - // crashes - // lua["test"]["func"](cppobj); - // lua["test"]["lua_func"](cppobj); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/usertype_constructors.cpp b/third/sol2/examples/source/usertype_constructors.cpp deleted file mode 100644 index 98934741..00000000 --- a/third/sol2/examples/source/usertype_constructors.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -class MyClass { -public: - MyClass(double d) : data(d) { - } - double data; -}; - -int main() { - std::cout << "=== usertype constructors ===" << std::endl; - - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.new_usertype("MyClass", - sol::meta_function::construct, - sol::factories( - // MyClass.new(...) -- dot syntax, no "self" value - // passed in - [](const double& d) { - return std::make_shared(d); - }, - // MyClass:new(...) -- colon syntax, passes in the - // "self" value as first argument implicitly - [](sol::object, const double& d) { - return std::make_shared(d); - }), - // MyClass(...) syntax, only - sol::call_constructor, - sol::factories([](const double& d) { - return std::make_shared(d); - }), - "data", - &MyClass::data); - - sol::optional maybe_error = lua.safe_script(R"( - d1 = MyClass(2.1) - d2 = MyClass:new(3.1) - d3 = MyClass(4.1) - assert(d1.data == 2.1) - assert(d2.data == 3.1) - assert(d3.data == 4.1) - )", - sol::script_pass_on_error); - - if (maybe_error) { - // something went wrong! - std::cerr << "Something has gone horribly unexpected " - "and wrong:\n" - << maybe_error->what() << std::endl; - return 1; - } - - // everything is okay! - std::cout - << "Everything went okay and all the asserts passed!" - << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/usertype_dynamic_get_set.cpp b/third/sol2/examples/source/usertype_dynamic_get_set.cpp deleted file mode 100644 index dc73e29f..00000000 --- a/third/sol2/examples/source/usertype_dynamic_get_set.cpp +++ /dev/null @@ -1,178 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -// Note that this is a bunch of if/switch statements -// for the sake of brevity and clarity -// A much more robust implementation could use a -// std::unordered_map to link between keys and desired actions -// for those keys on setting/getting The sky becomes the limit -// when you have this much control, so apply it wisely! - -struct vec { - double x; - double y; - - vec() : x(0), y(0) { - } - vec(double x) : vec(x, x) { - } - vec(double x, double y) : x(x), y(y) { - } - - sol::object get(sol::stack_object key, sol::this_state L) { - // we use stack_object for the arguments because we - // know the values from Lua will remain on Lua's stack, - // so long we we don't mess with it - auto maybe_string_key - = key.as>(); - if (maybe_string_key) { - const std::string& k = *maybe_string_key; - if (k == "x") { - // Return x - return sol::object( - L, sol::in_place, this->x); - } - else if (k == "y") { - // Return y - return sol::object( - L, sol::in_place, this->y); - } - } - - // String keys failed, check for numbers - auto maybe_numeric_key = key.as>(); - if (maybe_numeric_key) { - int n = *maybe_numeric_key; - switch (n) { - case 0: - return sol::object( - L, sol::in_place, this->x); - case 1: - return sol::object( - L, sol::in_place, this->y); - default: - break; - } - } - - // No valid key: push nil - // Note that the example above is a bit unnecessary: - // binding the variables x and y to the usertype - // would work just as well and we would not - // need to look it up here, - // but this is to show it works regardless - return sol::object(L, sol::in_place, sol::lua_nil); - } - - void set(sol::stack_object key, sol::stack_object value, - sol::this_state) { - // we use stack_object for the arguments because we - // know the values from Lua will remain on Lua's stack, - // so long we we don't mess with it - auto maybe_string_key - = key.as>(); - if (maybe_string_key) { - const std::string& k = *maybe_string_key; - if (k == "x") { - // set x - this->x = value.as(); - } - else if (k == "y") { - // set y - this->y = value.as(); - } - } - - // String keys failed, check for numbers - auto maybe_numeric_key = key.as>(); - if (maybe_numeric_key) { - int n = *maybe_numeric_key; - switch (n) { - case 0: - this->x = value.as(); - break; - case 1: - this->y = value.as(); - break; - default: - break; - } - } - } -}; - -int main() { - std::cout << "=== usertype dynamic get/set ===" - << std::endl; - - sol::state lua; - lua.open_libraries(); - - lua.new_usertype("vec", - sol::constructors(), - // index and newindex control what happens when a "key" - // is looked up that is not baked into the class itself - // it is called with the object and the key for index - // (get)s or it is called with the object, the key, and - // the index (set) we can use a member function to - // assume the "object" is of the `vec` type, and then - // just have a function that takes the key (get) or the - // key + the value (set) - sol::meta_function::index, - &vec::get, - sol::meta_function::new_index, - &vec::set); - - lua.script(R"( - v1 = vec.new(1, 0) - v2 = vec.new(0, 1) - - -- observe usage of get/set - print("v1:", v1.x, v1.y) - print("v2:", v2.x, v2.y) - -- gets 0, 1 by doing lookup into get function - print("changing v2...") - v2.x = 3 - v2[1] = 5 - -- can use [0] [1] like popular - -- C++-style math vector classes - print("v1:", v1.x, v1.y) - print("v2:", v2.x, v2.y) - -- both obj.name and obj["name"] - -- are equivalent lookup methods - -- and both will trigger the get - -- if it can't find 'name' on the object - assert(v1["x"] == v1.x) - assert(v1[0] == v1.x) - assert(v1["x"] == v1[0]) - - assert(v1["y"] == v1.y) - assert(v1[1] == v1.y) - assert(v1["y"] == v1[1]) -)"); - - - // Can also be manipulated from C++, - // and will call get/set methods: - sol::userdata v1 = lua["v1"]; - double v1x = v1["x"]; - double v1y = v1["y"]; - sol_c_assert(v1x == 1.000); - sol_c_assert(v1y == 0.000); - v1[0] = 2.000; - - lua.script(R"( - assert(v1.x == 2.000) - assert(v1["x"] == 2.000) - assert(v1[0] == 2.000) - )"); - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/usertype_initializers.cpp b/third/sol2/examples/source/usertype_initializers.cpp deleted file mode 100644 index f8c4375a..00000000 --- a/third/sol2/examples/source/usertype_initializers.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -struct holy { -private: - holy() : data() { - } - holy(int value) : data(value) { - } - ~holy() { - } - -public: - struct deleter { - void operator()(holy* p) const { - destroy(*p); - } - }; - - const int data; - - static std::unique_ptr create() { - std::cout << "creating 'holy' unique_ptr directly and " - "letting sol/Lua handle it" - << std::endl; - return std::unique_ptr(new holy(50)); - } - - static void initialize(holy& uninitialized_memory) { - std::cout << "initializing 'holy' userdata at " - << static_cast(&uninitialized_memory) - << std::endl; - // receive uninitialized memory from Lua: - // properly set it by calling a constructor - // on it - // "placement new" - new (&uninitialized_memory) holy(); - } - - static void destroy(holy& memory_from_lua) { - std::cout << "destroying 'holy' userdata at " - << static_cast(&memory_from_lua) - << std::endl; - memory_from_lua.~holy(); - } -}; - -int main() { - std::cout << "=== usertype_initializers ===" << std::endl; - { // additional scope to make usertype destroy earlier - sol::state lua; - lua.open_libraries(); - - lua.new_usertype("holy", - "new", - sol::initializers(&holy::initialize), - "create", - sol::factories(&holy::create), - sol::meta_function::garbage_collect, - sol::destructor(&holy::destroy), - "data", - &holy::data); - - lua.script(R"( -h1 = holy.create() -h2 = holy.new() -print('h1.data is ' .. h1.data) -print('h2.data is ' .. h2.data) -)"); - holy& h1 = lua["h1"]; - holy& h2 = lua["h2"]; - sol_c_assert(h1.data == 50); - sol_c_assert(h2.data == 0); - } - std::cout << std::endl; -} \ No newline at end of file diff --git a/third/sol2/examples/source/usertype_special_functions.cpp b/third/sol2/examples/source/usertype_special_functions.cpp deleted file mode 100644 index faa01260..00000000 --- a/third/sol2/examples/source/usertype_special_functions.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct vec { - double x; - double y; - - vec() : x(0), y(0) { - } - vec(double x, double y) : x(x), y(y) { - } - - vec operator-(const vec& right) const { - return vec(x - right.x, y - right.y); - } -}; - -double dot(const vec& left, const vec& right) { - return left.x * right.x + left.y * right.y; -} - -vec operator+(const vec& left, const vec& right) { - return vec(left.x + right.x, left.y + right.y); -} - -int main() { - sol::state lua; - lua.open_libraries(); - - lua.new_usertype( - "vec", - sol::constructors(), - "dot", - &dot, - "norm", - [](const vec& self) { - double len = std::sqrt(dot(self, self)); - return vec(self.x / len, self.y / len); - }, - // we use `sol::resolve` because other operator+ can - // exist in the (global) namespace - sol::meta_function::addition, - sol::resolve(::operator+), - sol::meta_function::subtraction, - &vec::operator-); - - lua.script(R"( - v1 = vec.new(1, 0) - v2 = vec.new(0, 1) - -- as "member function" - d1 = v1:dot(v2) - -- as "static" / "free function" - d2 = vec.dot(v1, v2) - assert(d1 == d2) - - -- doesn't matter if - -- bound as free function - -- or member function: - a1 = v1 + v2 - s1 = v1 - v2 -)"); - - vec& a1 = lua["a1"]; - vec& s1 = lua["s1"]; - - sol_c_assert(a1.x == 1 && a1.y == 1); - sol_c_assert(s1.x == 1 && s1.y == -1); - - lua["a2"] = lua["a1"]; - - lua.script(R"( - assert(a1 == a2) - )"); - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/usertype_var.cpp b/third/sol2/examples/source/usertype_var.cpp deleted file mode 100644 index 22ed7522..00000000 --- a/third/sol2/examples/source/usertype_var.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -struct test { - static int number; -}; -int test::number = 25; - - -int main() { - sol::state lua; - lua.open_libraries(); - lua.new_usertype("test", - "direct", - sol::var(2), - "number", - sol::var(test::number), - "ref_number", - sol::var(std::ref(test::number))); - - int direct_value = lua["test"]["direct"]; - sol_c_assert(direct_value == 2); - - int number = lua["test"]["number"]; - sol_c_assert(number == 25); - int ref_number = lua["test"]["ref_number"]; - sol_c_assert(ref_number == 25); - - test::number = 542; - - // number is its own memory: was passed by value - // So does not change - int number_again = lua["test"]["number"]; - sol_c_assert(number_again == 25); - - // ref_number is just test::number - // passed through std::ref - // so, it holds a reference - // which can be updated - int ref_number_again = lua["test"]["ref_number"]; - sol_c_assert(ref_number_again == 542); - // be careful about referencing local variables, - // if they go out of scope but are still reference - // you'll suffer dangling reference bugs! - - return 0; -} diff --git a/third/sol2/examples/source/variables.cpp b/third/sol2/examples/source/variables.cpp deleted file mode 100644 index adc43c3d..00000000 --- a/third/sol2/examples/source/variables.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - std::cout << "=== variables ===" << std::endl; - - sol::state lua; - - // need the base library for assertions - lua.open_libraries(sol::lib::base); - - // basic setting of a variable - // through multiple ways - lua["x"] = 10; - lua.set("y", "hello"); - - // assert values are as given - lua.script("assert(x == 10)"); - lua.script("assert(y == 'hello')"); - - - // basic retrieval of a variable - // through multiple ways - int x = lua["x"]; - auto y = lua.get("y"); - - int x2; - std::string y2; - std::tie(x2, y2) = lua.get("x", "y"); - - // show the values - std::cout << x << std::endl; - std::cout << y << std::endl; - std::cout << x2 << std::endl; - std::cout << y2 << std::endl; - std::cout << std::endl; -} \ No newline at end of file diff --git a/third/sol2/examples/source/variadic_args.cpp b/third/sol2/examples/source/variadic_args.cpp deleted file mode 100644 index 3e72dc33..00000000 --- a/third/sol2/examples/source/variadic_args.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - std::cout << "=== variadic_args ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // Function requires 2 arguments - // rest can be variadic, but: - // va will include everything after "a" argument, - // which means "b" will be part of the varaidic_args list - // too at position 0 - lua.set_function( - "v", [](int a, sol::variadic_args va, int /*b*/) { - int r = 0; - for (auto v : va) { - int value - = v; // get argument out (implicit - // conversion) can also do int v = - // v.as(); can also do int v = - // va.get(i); with index i - r += value; - } - // Only have to add a, b was included from - // variadic_args and beyond - return r + a; - }); - - lua.script("x = v(25, 25)"); - lua.script("x2 = v(25, 25, 100, 50, 250, 150)"); - lua.script("x3 = v(1, 2, 3, 4, 5, 6)"); - // 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("print(x)"); // 50 - lua.script("print(x2)"); // 600 - lua.script("print(x3)"); // 21 - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/variadic_args_into_lua.cpp b/third/sol2/examples/source/variadic_args_into_lua.cpp deleted file mode 100644 index 24ee22ff..00000000 --- a/third/sol2/examples/source/variadic_args_into_lua.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - std::cout << "=== variadic_args ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - // another function, which doubles the argument - lua.script("function doubler (x) return x * 2 end"); - sol::protected_function doubler = lua["doubler"]; - - // Function requires 2 arguments - // rest can be variadic, but: - // va will include everything after "a" argument, - // which means "b" will be part of the varaidic_args list - // too at position 0 - lua.set_function("v", - [doubler](int a, sol::variadic_args va, int /*b*/) { - int r = 0; - for (auto v : va) { - int value = doubler( - v); // pass directly to Lua as well! - r += value; - } - // Only have to add a, b was included from - // variadic_args and beyond use explicit "call" - // syntax to return exactly an integer! this is - // useful for ambiguous operator overloads in C++ - // and other shenanigans - return r + a; - }); - - lua.script("x = v(25, 25)"); - lua.script("x2 = v(25, 25, 100, 50, 250, 150)"); - lua.script("x3 = v(1, 2, 3, 4, 5, 6)"); - // will error: not enough arguments! - // lua.script("x4 = v(1)"); - - lua.script("assert(x == 75)"); - lua.script("assert(x2 == 1175)"); - lua.script("assert(x3 == 41)"); - lua.script("print(x)"); - lua.script("print(x2)"); - lua.script("print(x3)"); - - std::cout << std::endl; - - return 0; -} \ No newline at end of file diff --git a/third/sol2/examples/source/variadic_args_shifted.cpp b/third/sol2/examples/source/variadic_args_shifted.cpp deleted file mode 100644 index b24eb48d..00000000 --- a/third/sol2/examples/source/variadic_args_shifted.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main() { - - std::cout << "=== variadic_args shifting constructor ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - lua.set_function("f", [](sol::variadic_args va) { - int r = 0; - sol::variadic_args shifted_va(va.lua_state(), 3); - for (auto v : shifted_va) { - int value = v; - r += value; - } - return r; - }); - - lua.script("x = f(1, 2, 3, 4)"); - lua.script("x2 = f(8, 200, 3, 4)"); - lua.script("x3 = f(1, 2, 3, 4, 5, 6)"); - - lua.script("print(x)"); // 7 - lua.script("print(x2)"); // 7 - lua.script("print(x3)"); // 18 - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/variadic_args_storage.cpp b/third/sol2/examples/source/variadic_args_storage.cpp deleted file mode 100644 index b7933482..00000000 --- a/third/sol2/examples/source/variadic_args_storage.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include -#include - -int main() { - - std::cout << "=== variadic_args serialization/storage ===" - << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - std::function function_storage; - - auto store_routine = [&function_storage](sol::function f, - sol::variadic_args va) { - function_storage = - [f, - args = std::vector(va.begin(), - va.end())]() { f(sol::as_args(args)); }; - }; - - lua.set_function("store_routine", store_routine); - - lua.script(R"( -function a(name) - print(name) -end -store_routine(a, "some name") -)"); - function_storage(); - - lua.script(R"( -function b(number, text) - print(number, "of", text) -end -store_routine(b, 20, "these apples") -)"); - function_storage(); - - std::cout << std::endl; - - return 0; -} diff --git a/third/sol2/examples/source/wip/lua_inheritance.cpp b/third/sol2/examples/source/wip/lua_inheritance.cpp deleted file mode 100644 index 0d0e3804..00000000 --- a/third/sol2/examples/source/wip/lua_inheritance.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#define SOL_ALL_SAFETIES_ON 1 -#include - -#include - -int main(int, char*[]) { - std::cout << "=== lua inheritance ===" << std::endl; - - sol::state lua; - lua.open_libraries(sol::lib::base); - - /* This example is currently under construction. - For inheritance and classes within Lua, - consider using kikito's middleclass - -- https://github.com/kikito/middleclass */ - - return 0; -} diff --git a/third/sol2/include/sol/as_args.hpp b/third/sol2/include/sol/as_args.hpp deleted file mode 100644 index 719a3cdc..00000000 --- a/third/sol2/include/sol/as_args.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// sol2 - -// The MIT License (MIT) - -// Copyright (c) 2013-2022 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 Spermission 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. - -#ifndef SOL_AS_ARGS_HPP -#define SOL_AS_ARGS_HPP - -#include - -namespace sol { - template - struct as_args_t { - T src; - }; - - template - auto as_args(Source&& source) { - return as_args_t { std::forward(source) }; - } - - namespace stack { - template - struct unqualified_pusher> { - int push(lua_State* L, const as_args_t& e) { - int p = 0; - for (const auto& i : e.src) { - p += stack::push(L, i); - } - return p; - } - }; - } // namespace stack -} // namespace sol - -#endif // SOL_AS_ARGS_HPP diff --git a/third/sol2/include/sol/as_returns.hpp b/third/sol2/include/sol/as_returns.hpp deleted file mode 100644 index 982f408b..00000000 --- a/third/sol2/include/sol/as_returns.hpp +++ /dev/null @@ -1,62 +0,0 @@ -// sol2 - -// The MIT License (MIT) - -// Copyright (c) 2013-2022 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. - -#ifndef SOL_AS_RETURNS_HPP -#define SOL_AS_RETURNS_HPP - -#include -#include -#include - -namespace sol { - template - struct as_returns_t : private detail::ebco { - private: - using base_t = detail::ebco; - - public: - using base_t::base_t; - using base_t::value; - }; - - template - auto as_returns(Source&& source) { - return as_returns_t> { std::forward(source) }; - } - - namespace stack { - template - struct unqualified_pusher> { - int push(lua_State* L, const as_returns_t& e) { - auto& src = detail::unwrap(e.value()); - int p = 0; - for (const auto& i : src) { - p += stack::push(L, i); - } - return p; - } - }; - } // namespace stack -} // namespace sol - -#endif // SOL_AS_RETURNS_HPP diff --git a/third/sol2/include/sol/assert.hpp b/third/sol2/include/sol/assert.hpp deleted file mode 100644 index 668dcd2e..00000000 --- a/third/sol2/include/sol/assert.hpp +++ /dev/null @@ -1,99 +0,0 @@ -// sol2 - -// The MIT License (MIT) - -// Copyright (c) 2013-2022 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. - -#pragma once - -#ifndef SOL_ASSERT_HPP -#define SOL_ASSERT_HPP - -#include - -#if SOL_IS_ON(SOL2_CI) - -struct pre_main { - pre_main() { -#ifdef _MSC_VER - _set_abort_behavior(0, _WRITE_ABORT_MSG); -#endif - } -} inline sol2_ci_dont_lock_ci_please = {}; - -#endif // Prevent lockup when doing Continuous Integration - - -// clang-format off - -#if SOL_IS_ON(SOL_USER_C_ASSERT) - #define sol_c_assert(...) SOL_C_ASSERT(__VA_ARGS__) -#else - #if SOL_IS_ON(SOL_DEBUG_BUILD) - #include - #include - #include - - #define sol_c_assert(...) \ - do { \ - if (!(__VA_ARGS__)) { \ - std::cerr << "Assertion `" #__VA_ARGS__ "` failed in " << __FILE__ << " line " << __LINE__ << std::endl; \ - std::terminate(); \ - } \ - } while (false) - #else - #define sol_c_assert(...) \ - do { \ - if (false) { \ - (void)(__VA_ARGS__); \ - } \ - } while (false) - #endif -#endif - -#if SOL_IS_ON(SOL_USER_M_ASSERT) - #define sol_m_assert(message, ...) SOL_M_ASSERT(message, __VA_ARGS__) -#else - #if SOL_IS_ON(SOL_DEBUG_BUILD) - #include - #include - #include - - #define sol_m_assert(message, ...) \ - do { \ - if (!(__VA_ARGS__)) { \ - std::cerr << "Assertion `" #__VA_ARGS__ "` failed in " << __FILE__ << " line " << __LINE__ << ": " << message << std::endl; \ - std::terminate(); \ - } \ - } while (false) - #else - #define sol_m_assert(message, ...) \ - do { \ - if (false) { \ - (void)(__VA_ARGS__); \ - (void)sizeof(message); \ - } \ - } while (false) - #endif -#endif - -// clang-format on - -#endif // SOL_ASSERT_HPP diff --git a/third/sol2/include/sol/base_traits.hpp b/third/sol2/include/sol/base_traits.hpp deleted file mode 100644 index 6178088a..00000000 --- a/third/sol2/include/sol/base_traits.hpp +++ /dev/null @@ -1,123 +0,0 @@ -// sol2 - -// The MIT License (MIT) - -// Copyright (c) 2013-2022 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. - -#ifndef SOL_BASE_TRAITS_HPP -#define SOL_BASE_TRAITS_HPP - -#include - -namespace sol { - namespace detail { - struct unchecked_t { }; - const unchecked_t unchecked = unchecked_t {}; - } // namespace detail - - namespace meta { - using sfinae_yes_t = std::true_type; - using sfinae_no_t = std::false_type; - - template - using void_t = void; - - template - using unqualified = std::remove_cv>; - - template - using unqualified_t = typename unqualified::type; - - namespace meta_detail { - template - struct unqualified_non_alias : unqualified { }; - - template