Merge branch 'sol3' into develop

This commit is contained in:
ThePhD 2019-03-28 23:20:07 -04:00
commit 72181513d5
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA
485 changed files with 37123 additions and 27861 deletions

View File

@ -1,7 +1,7 @@
# # # # sol2
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -25,7 +25,7 @@ BasedOnStyle: WebKit
IndentWidth: 5
TabWidth: 5
ContinuationIndentWidth: 5
UseTab: Always
UseTab: ForIndentation
# Namespaces
NamespaceIndentation: All
@ -33,7 +33,7 @@ CompactNamespaces: true
FixNamespaceComments: true
# Overall Alignment
ColumnLimit: 0
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
@ -59,7 +59,7 @@ AlwaysBreakAfterReturnType: None
BreakConstructorInitializers: BeforeComma
ConstructorInitializerIndentWidth: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: true
BinPackArguments: true
BinPackArguments: false
BinPackParameters: true
# Classes

View File

@ -1,7 +1,7 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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

27
.gitignore vendored
View File

@ -1,7 +1,7 @@
# # # # sol2
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -72,15 +72,6 @@ main.pdb
*.files
*.includes
# Scratchpad Files
m.lua
main.lua
catch_mock.hpp
main_aux.cpp
main.hpp
main2.cpp
main.cpp
# Local Lua Testbeds
lua-5.4.0-cxx/
lua-5.4.0/
@ -98,7 +89,6 @@ lua-5.1.5/
LuaJIT-2.1.0/
luajit-2.0.5/
luajit-2.0.3/
include/
liblua.a
lib/liblua5.2.a
@ -110,6 +100,9 @@ docs/build/
*.sublime-project
# MacOS Garbage
.DS_Store
# Windows Crap
desktop.ini
*.db
@ -123,10 +116,10 @@ cmake-build-relwithdebinfo/
cmake-build-release/
/subprojects/*
!/subprojects/*.wrap
LuaJIT-2.1/
LuaJIT-2.0/
lua-5.4/
lua-5.3-cxx/
lua-5.3/
lua-5.2/
lua-5.3-cxx/
lua-5.4/
LuaJIT-2.0/
LuaJIT-2.1/
lua-5.1/
lua-5.2/

View File

@ -1,7 +1,7 @@
# # # # sol2
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -35,8 +35,7 @@ before_install:
script:
- export SOL2_DIR=${TRAVIS_BUILD_DIR}
- sudo docker image pull thephd/sol2:gcc-${GCC_VERSION}_llvm-${LLVM_VERSION}
- sudo docker run --rm --interactive --tty --name "sol2.test" -v "${SOL2_DIR}:/root/sol2" --env "CI=${CI}" --env "PLATFORM=${PLATFORM}" --env "LUA_VERSION=${LUA_VERSION}" --env "GCC_VERSION=${GCC_VERSION}" --env "LLVM_VERSION=${LLVM_VERSION}" thephd/sol2:gcc-${GCC_VERSION}_llvm-${LLVM_VERSION}
- sudo docker rmi $(sudo docker image ls -q)
- sudo docker run --rm --interactive --tty --name "sol2.test" -v "${SOL2_DIR}:/root/sol2" --env "SOL2_CI=${SOL2_CI}" --env "SOL2_PLATFORM=${SOL2_PLATFORM}" --env "SOL2_LUA_VERSION=${SOL2_LUA_VERSION}" --env "SOL2_TEST_SINGLE=${SOL2_TEST_SINGLE}" --env "SOL2_TEST_INTEROP=${SOL2_TEST_INTEROP}" --env "GCC_VERSION=${GCC_VERSION}" --env "LLVM_VERSION=${LLVM_VERSION}" thephd/sol2:gcc-${GCC_VERSION}_llvm-${LLVM_VERSION}
matrix:
fast_finish: true
@ -44,116 +43,109 @@ matrix:
- os: osx
include:
# GCC 4.9.x, 5.x, 6.x, 7.x
# LLVM 5.0.x -> 8.0.x
- env:
- LUA_VERSION=5.3.4
- SOL2_LUA_VERSION=5.3.5
LLVM_VERSION=5.0.2
SOL2_PLATFORM=x64
SOL2_CI=true
- env:
- SOL2_LUA_VERSION=5.3.5
LLVM_VERSION=6.0.1
SOL2_PLATFORM=x64
SOL2_CI=true
- env:
- SOL2_LUA_VERSION=5.3.5
LLVM_VERSION=7.0.1
SOL2_PLATFORM=x64
SOL2_CI=true
- env:
- SOL2_LUA_VERSION=5.3.5
LLVM_VERSION=8.0.0
SOL2_PLATFORM=x64
SOL2_CI=true
# GCC 7.x, 8.x
- env:
- SOL2_LUA_VERSION=5.3.5
GCC_VERSION=7
PLATFORM=i686
CI=true
SOL2_PLATFORM=x64
SOL2_CI=true
- env:
- LUA_VERSION=luajit-2.0.5
GCC_VERSION=7
PLATFORM=i686
CI=true
- SOL2_LUA_VERSION=5.3.5
GCC_VERSION=8
SOL2_PLATFORM=x64
SOL2_CI=true
# Lua Versions 5.2.4, 5.1.5, and LuaJIT
- env:
- SOL2_LUA_VERSION=5.1.5
GCC_VERSION=8
SOL2_PLATFORM=x64
SOL2_CI=true
- env:
- LUA_VERSION=luajit-2.1.0-beta3
GCC_VERSION=7
PLATFORM=i686
CI=true
- SOL2_LUA_VERSION=5.2.4
GCC_VERSION=8
SOL2_PLATFORM=x64
SOL2_CI=true
- env:
- LUA_VERSION=5.3.4
GCC_VERSION=4.9
PLATFORM=x64
CI=true
- SOL2_LUA_VERSION=luajit-2.0.4
GCC_VERSION=8
SOL2_PLATFORM=x64
SOL2_CI=true
- env:
- LUA_VERSION=5.3.4
GCC_VERSION=5
CI=true
PLATFORM=x64
- SOL2_LUA_VERSION=luajit-2.0.5
GCC_VERSION=8
SOL2_PLATFORM=x64
SOL2_CI=true
# x86 builds
- env:
- SOL2_LUA_VERSION=5.3.5
GCC_VERSION=8
SOL2_PLATFORM=i686
SOL2_CI=true
- env:
- LUA_VERSION=5.3.4
GCC_VERSION=6
PLATFORM=x64
CI=true
- SOL2_LUA_VERSION=luajit-2.0.5
GCC_VERSION=8
SOL2_PLATFORM=i686
SOL2_CI=true
- env:
- LUA_VERSION=5.3.4
GCC_VERSION=7
PLATFORM=x64
CI=true
- SOL2_LUA_VERSION=luajit-2.1.0-beta3
GCC_VERSION=8
SOL2_PLATFORM=i686
SOL2_CI=true
# LLVM 3.6.x -> 5.0.x
# Test Single, Interop, Etc.
- env:
- LUA_VERSION=5.3.4
LLVM_VERSION=3.6.2
PLATFORM=x64
CI=true
- SOL2_LUA_VERSION=5.3.5
SOL2_TEST_SINGLE=true
SOL2_TEST_INTEROP=true
LLVM_VERSION=8.0.0
SOL2_PLATFORM=x64
SOL2_CI=true
- env:
- LUA_VERSION=5.3.4
LLVM_VERSION=3.7.1
PLATFORM=x64
CI=true
- env:
- LUA_VERSION=5.3.4
LLVM_VERSION=3.8.1
PLATFORM=x64
CI=true
- env:
- LUA_VERSION=5.3.4
LLVM_VERSION=3.9.1
PLATFORM=x64
CI=true
- env:
- LUA_VERSION=5.3.4
LLVM_VERSION=4.0.1
PLATFORM=x64
CI=true
- env:
- LUA_VERSION=5.3.4
LLVM_VERSION=5.0.1
PLATFORM=x64
CI=true
# Lua Versions 5.2.4, 5.1.5, and LuaJIT (as well as x86)
- env:
- LUA_VERSION=5.2.4
GCC_VERSION=7
PLATFORM=x64
CI=true
- env:
- LUA_VERSION=5.1.5
GCC_VERSION=7
PLATFORM=x64
CI=true
- env:
- LUA_VERSION=luajit-2.0.4
GCC_VERSION=7
PLATFORM=x64
CI=true
- env:
- LUA_VERSION=luajit-2.0.5
GCC_VERSION=7
PLATFORM=x64
CI=true
- SOL2_LUA_VERSION=5.3.5
SOL2_TEST_SINGLE=true
SOL2_TEST_INTEROP=true
GCC_VERSION=8
SOL2_PLATFORM=x64
SOL2_CI=true
- os: osx
osx_image: xcode9.0
osx_image: xcode10.1
env:
- LUA_VERSION=lua-5.3.4
LLVM_VERSION=5.0.1
- SOL2_LUA_VERSION=lua-5.3.5
before_install:
- chmod +x ./scripts/run.osx.sh
- chmod +x ./scripts/preparation.osx.sh
@ -162,10 +154,20 @@ matrix:
- ./scripts/run.osx.sh
- os: osx
osx_image: xcode9.1
osx_image: xcode9.4
env:
- LUA_VERSION=lua-5.3.4
LLVM_VERSION=5.0.1
- SOL2_LUA_VERSION=lua-5.3.5
before_install:
- chmod +x ./scripts/run.osx.sh
- chmod +x ./scripts/preparation.osx.sh
- ./scripts/preparation.osx.sh
script:
- ./scripts/run.osx.sh
- os: osx
osx_image: xcode9.3
env:
- SOL2_LUA_VERSION=lua-5.3.5
before_install:
- chmod +x ./scripts/run.osx.sh
- chmod +x ./scripts/preparation.osx.sh
@ -176,8 +178,7 @@ matrix:
- os: osx
osx_image: xcode9.2
env:
- LUA_VERSION=lua-5.3.4
LLVM_VERSION=5.0.1
- SOL2_LUA_VERSION=lua-5.3.5
before_install:
- chmod +x ./scripts/run.osx.sh
- chmod +x ./scripts/preparation.osx.sh
@ -188,7 +189,7 @@ matrix:
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/b864d553270a069d26c8
- http://skyhook.glitch.me/api/webhooks/427786348108185611/y2nTmghqltv1SKX2DclEMEKyZtRcwKFlwfZpB_mL1A0nZTVS5MSfumqDKq30-gvWgeL5/travis
on_success: change
on_failure: always
on_start: always

View File

@ -1,7 +1,7 @@
# # # # sol2
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -20,82 +20,15 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# # # # sol2
# # # # sol3
# # # Required minimum version statement
cmake_minimum_required(VERSION 3.5.0)
# # # project declaration
project(sol2 VERSION 2.20.0 LANGUAGES CXX C)
project(sol2 VERSION 3.0.0 LANGUAGES CXX C)
include(GNUInstallDirs)
# # # General Project Requirements
# Set general standard requirements here
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Features a C++ compiler must have to be used to compile sol2
# This list is not *complete* as CMake does not support features for
# all of the advanced features utilized.
set(CXX_FEATURES
cxx_auto_type
cxx_constexpr
cxx_decltype
cxx_decltype_auto
cxx_default_function_template_args
cxx_final
cxx_lambdas
cxx_noexcept
cxx_nullptr
cxx_override
cxx_range_for
cxx_return_type_deduction
cxx_right_angle_brackets
cxx_static_assert
cxx_strong_enums
cxx_variadic_macros
cxx_variadic_templates)
# # #
if (PLATFORM MATCHES "i686" OR PLATFORM STREQUAL "x86")
set(IS_X86 TRUE)
elseif (PLATFORM MATCHES "ARM64")
set(IS_ARM64 TRUE)
set(IS_X64 TRUE)
elseif (PLATFORM MATCHES "ARM")
set(IS_ARM TRUE)
elseif (PLATFORM MATCHES "x86_64" OR PLATFORM STREQUAL "x64")
set(IS_X64 TRUE)
else()
set(IS_X64 TRUE)
endif()
# # # General project flags
if (MSVC)
add_definitions(/DUNICODE /D_UNICODE /D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_DEPRECATE)
# Warning level, exceptions
add_compile_options(/W4 /EHsc)
add_compile_options("$<$<CONFIG:Debug>:/MDd>"
"$<$<CONFIG:Release>:/MD>"
"$<$<CONFIG:RelWithDebInfo>:/MD>"
"$<$<CONFIG:MinSizeRel>:/MD>")
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(/MP)
endif()
else()
add_compile_options(-Wno-unknown-warning -Wno-unknown-warning-option -Wall -Wextra -Wpedantic -pedantic -pedantic-errors)
endif()
# # # General project output locations
if (IS_X86 OR 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()
# # # Modules
# # Include modules useful to the project, whether locally made in our own cmake DIRECTORY
# # our from the standard cmake libraries
@ -109,44 +42,78 @@ include(CMakePackageConfigHelpers)
# # # Configuration
# # Cached defines, strings, paths and options
set(LUA_VERSION "5.3.4" CACHE STRING "The version of Lua needed. Can be 5.1, 5.2, 5.3, LuaJIT, or a more specific 3-part version number for a specifc Lua (e.g., 5.3.4 or luajit-2.0.5)")
set(BUILD_LUA TRUE CACHE BOOL "Always build Lua, do not search for it in the system")
set(PLATFORM "x64" CACHE STRING "Target platform to compile for when building binaries (x86, x64)")
option(CI "Whether or not we are in continguous integration mode" OFF)
option(TESTS "Enable build of tests" OFF)
option(EXAMPLES "Enable build of examples" OFF)
option(INTEROP_EXAMPLES "Enable build of interop examples" OFF)
option(DYNAMIC_LOADING_EXAMPLES "Enable build of interop examples" OFF)
option(SINGLE "Enable build of single header files" OFF)
option(DOCS "Enable build of documentation" OFF)
set(SOL2_LUA_VERSION "5.3.5" 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.3.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_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_GENERATE_SINGLE "Enable generation and build of single header files" OFF)
option(SOL2_SINGLE "Enable use of prepackaged single header files" OFF)
option(SOL2_DOCS "Enable build of documentation" OFF)
# Single tests and examples tests will only be turned on if both SINGLE and TESTS are defined
CMAKE_DEPENDENT_OPTION(TESTS_SINGLE "Enable build of tests using the generated single headers" ON
"SINGLE;TESTS" OFF)
CMAKE_DEPENDENT_OPTION(EXAMPLES_SINGLE "Enable build of examples using the generated single headers" OFF
"SINGLE;EXAMPLES" OFF)
CMAKE_DEPENDENT_OPTION(INTEROP_EXAMPLES_SINGLE "Enable build of interop examples using the generated single headers" OFF
"SINGLE;INTEROP_EXAMPLES" OFF)
CMAKE_DEPENDENT_OPTION(DYNAMIC_LOADING_EXAMPLES_SINGLE "Enable build of dynamic loading examples using the generated single headers" OFF
"SINGLE;DYNAMIC_LOADING_EXAMPLES" OFF)
CMAKE_DEPENDENT_OPTION(TESTS_EXAMPLES "Enable build of examples as tests" ON
"EXAMPLES" OFF)
CMAKE_DEPENDENT_OPTION(TESTS_INTEROP_EXAMPLES "Enable build of interop examples as tests" ON
"INTEROP_EXAMPLES" OFF)
CMAKE_DEPENDENT_OPTION(TESTS_DYNAMIC_LOADING_EXAMPLES "Enable build of dynamic loading examples as tests" ON
"DYNAMIC_LOADING_EXAMPLES" OFF)
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_TESTS_SINGLE_GENERATED "Enable build of tests using the generated single headers" ON
"SOL2_GENERATE_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_EXAMPLES_SINGLE_GENERATED "Enable build of examples using the premade single headers" OFF
"SOL2_GENERATE_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_INTEROP_EXAMPLES_SINGLE_GENERATED "Enable build of interop examples using the generated single headers" OFF
"SOL2_GENERATE_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_DYNAMIC_LOADING_EXAMPLES_SINGLE_GENERATED "Enable build of dynamic loading examples using the generated single headers" OFF
"SOL2_GENERATE_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)
# # # Platform
# Detect x86 and x64 stuff
if (SOL2_PLATFORM MATCHES "i686" OR SOL2_PLATFORM STREQUAL "x86")
set(IS_X86 TRUE)
elseif (SOL2_PLATFORM MATCHES "ARM64")
set(IS_ARM64 TRUE)
set(IS_X64 TRUE)
elseif (SOL2_PLATFORM MATCHES "ARM")
set(IS_ARM TRUE)
elseif (SOL2_PLATFORM MATCHES "x86_64" OR SOL2_PLATFORM STREQUAL "x64")
set(IS_X64 TRUE)
else()
set(IS_X64 TRUE)
endif()
# # # sol2 Source Groups
# # Sources everyone is going to need
# Header files
file(GLOB SOL2_HEADER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/include/sol*.hpp)
source_group(sol2 FILES ${SOL2_HEADER_SOURCES})
# # # 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_sources(sol2 INTERFACE ${SOL2_SINGLE_HEADER_SOURCES})
set_target_properties(sol2
PROPERTIES
EXPORT_NAME sol2::sol2)
target_include_directories(sol2 INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:sol/include>)
# # Version configurations
configure_package_config_file(
@ -168,62 +135,26 @@ install(EXPORT sol2
FILE sol2-targets.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/sol2")
install(DIRECTORY sol
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(FILES sol.hpp
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(DIRECTORY include/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/sol/include")
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")
# # # Source Groups
# # Sources everyone is going to need
# Header files
file(GLOB SOL2_HEADER_SOURCES sol*.hpp)
source_group(headers FILES ${SOL2_HEADER_SOURCES})
# single header files
file(GLOB SOL2_SINGLE_HEADER_SOURCES single/sol/sol_forward.hpp single/sol/sol.hpp)
source_group(headers FILES ${SOL2_SINGLE_HEADER_SOURCES})
# # # Single header target
# Find Python3 for single header / forward header generation
find_package(PythonInterp 3)
set(SOL2_SINGLE_HEADER_FOUND FALSE)
set(SOL2_SINGLE_FOUND FALSE)
set(SOL2_DOCS_FOUND FALSE)
if (PYTHONINTERP_FOUND)
if (SINGLE)
set(SOL2_SINGLE_FOUND TRUE)
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/single/sol.hpp" "${CMAKE_CURRENT_BINARY_DIR}/single/sol_forward.hpp"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/single"
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/single.py" --output "${CMAKE_CURRENT_BINARY_DIR}/single/sol.hpp")
add_custom_target(sol2_single_header ALL
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/single/sol.hpp" "${CMAKE_CURRENT_BINARY_DIR}/single/sol_forward.hpp")
add_library(sol2_single INTERFACE)
add_library(sol2::sol2_single ALIAS sol2_single)
set_target_properties(sol2_single
PROPERTIES
EXPORT_NAME sol2::sol2_single
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/single")
add_dependencies(sol2_single sol2_single_header)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/single/sol.hpp" "${CMAKE_CURRENT_BINARY_DIR}/single/sol_forward.hpp"
DESTINATION include/sol/single/sol)
endif()
if (DOCS)
set(SOL2_DOCS_FOUND TRUE)
add_custom_command(OUTPUT docs
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/docs" docs
COMMAND make -C docs html)
add_custom_target(documentation ALL DEPENDS docs)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/docs/build/html" DESTINATION "${CMAKE_INSTALL_DOCDIR}")
endif()
else()
if (SINGLE)
message(STATUS "sol2 single_header cannot be generated as python 3 has not been found.")
endif()
if (SOL2_GENERATE_SINGLE OR 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(docs)
endif()
# pkg-config support, except on Windows
@ -236,23 +167,23 @@ if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sol2.pc" DESTINATION "${PKGCONFIG_INSTALL_DIR}")
endif()
if (CI)
if (SOL2_CI)
message(STATUS "sol2 Contiguous Integration is on")
endif()
if (EXAMPLES OR TESTS_EXAMPLES OR EXAMPLES_SINGLE OR INTEROP_EXAMPLES OR TESTS_INTEROP_EXAMPLES OR INTEROP_EXAMPLES_SINGLE OR DYNAMIC_LOADING_EXAMPLES OR TESTS_DYNAMIC_LOADING_EXAMPLES OR DYNAMIC_LOADING_EXAMPLES_SINGLE)
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(DO_EXAMPLES TRUE)
else()
set(DO_EXAMPLES FALSE)
endif()
if (TESTS OR TESTS_SINGLE)
if (SOL2_TESTS OR SOL2_TESTS_SINGLE)
set(DO_TESTS TRUE)
else()
set(DO_TESTS FALSE)
endif()
if (DO_TESTS OR TESTS_EXAMPLES OR TESTS_INTEROP_EXAMPLES OR TESTS_DYNAMIC_LOADING_EXAMPLES)
if (DO_TESTS OR SOL2_TESTS_EXAMPLES OR SOL2_TESTS_INTEROP_EXAMPLES OR SOL2_TESTS_DYNAMIC_LOADING_EXAMPLES)
set(ENABLE_TESTING TRUE)
else()
set(ENABLE_TESTING FALSE)
@ -260,6 +191,17 @@ endif()
# # # Tests, Examples and other CI suites that come with sol2
if (DO_TESTS OR DO_EXAMPLES)
# # # General project output locations
if (IS_X86 OR 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()
# # # Libraries
# Here, we pull in all the necessary libraries for building examples and tests
# Find threading library
@ -272,31 +214,71 @@ if (DO_TESTS OR DO_EXAMPLES)
endif()
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
else()
string(REGEX REPLACE "/W[0-4]" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
find_package(Threads REQUIRED)
string(TOLOWER ${LUA_VERSION} NORMALIZED_LUA_VERSION)
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 (BUILD_LUA)
find_package(LuaBuild REQUIRED COMPONENTS ${LUA_VERSION})
elseif (NOT LUA_VERSION)
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 ${LUA_VERSION} REQUIRED)
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}
IMPORTED_LINK_INTERFACE_LANGUAGES C
IMPORTED_LOCATION ${lualiblocation})
if (CMAKE_DL_LIBS)
set_property(TARGET ${lualib}
APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS})
endif()
set(LUA_LIBRARIES ${lualib})
endif()
if (NOT LUA_FOUND AND NOT LUABUILD_FOUND)
message(FATAL_ERROR "sol2 Lua \"${LUA_VERSION}\" not found and could not be targeted for building")
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

View File

@ -1,18 +1,26 @@
# Donators! ♥
# 🎉 Donators! ♥ 🎉
Thank you to all patrons, donators and contributors who help keep sol2 amazing.
Robert Salvet
Ορφέας Ζαφείρης - 2x Donations!
Michael Wallar
Johannes Schultz
Dailidzionak Ilya
- Robert Salvet
- Ορφέας Ζαφείρης - 2x Donations!
- Michael Wallar
- Johannes Schultz
- Dailidzionak Ilya
- BECKMANN & EGLE Industrieelektronik GmbH [bue.de](https://www.bue.de/)
# Patrons
# 🎉 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.
Michael Caisse
Joshua Fisher
- 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/)

View File

@ -20,8 +20,8 @@
# 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:xenial image
FROM ubuntu:xenial
# Start from the ubuntu:bionic image
FROM ubuntu:bionic
# owner
LABEL author="ThePhD <phdofthehouse@gmail.com>"
LABEL maintainer="ThePhD <phdofthehouse@gmail.com>"
@ -48,13 +48,17 @@ VOLUME /root/sol2
# # 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 CI=true
ARG SOL2_PLATFORM=x64
ARG SOL2_LUA_VERSION=x64
ARG SOL2_LUA_VERSION=5.3.5
ARG SOL2_TEST_SINGLE=false
ARG SOL2_TEST_INTEROP=false
ARG SOL2_CI=true
ARG GCC_VERSION
ARG LLVM_VERSION
ARG PLATFORM=x64
# Potential environment variables
ENV CI=${CI} PLATFORM=${PLATFORM} GCC_VERSION=${GCC_VERSION} LLVM_VERSION=${LLVM_VERSION} SOL2_DIR=/root/sol2
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"]

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
Copyright (c) 2013-2019 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

View File

@ -1,7 +1,7 @@
# # # # sol2
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -44,53 +44,63 @@ platform:
environment:
matrix:
# apparently, I can't quite make LLVM work right now...
#- LUA_VERSION: 5.3.4
# LLVM_VERSION: 4.0.0
- LUA_VERSION: 5.3.4
MINGW_VERSION: 7.2.0
- LUA_VERSION: 5.3.4
MINGW_VERSION: 6.3.0
- LUA_VERSION: luajit-2.0.5
MINGW_VERSION: 6.3.0
- LUA_VERSION: luajit-2.1.0-beta3
MINGW_VERSION: 6.3.0
- LUA_VERSION: 5.3.4
- LUA_VERSION: 5.2.4
- LUA_VERSION: 5.1.5
- LUA_VERSION: luajit-2.0.5
- LUA_VERSION: luajit-2.1.0-beta3
- SOL2_LUA_VERSION: luajit-2.0.5
SOL2_BUILD_NINJA: 1
SOL2_NO_2015: 1
- SOL2_LUA_VERSION: luajit-2.1.0-beta3
SOL2_BUILD_NINJA: 1
SOL2_NO_2015: 1
- SOL2_LUA_VERSION: 5.3.5
SOL2_BUILD_NINJA: 1
MINGW_VERSION: 7.3.0
- SOL2_LUA_VERSION: 5.3.5
SOL2_BUILD_NINJA: 1
MINGW_VERSION: 8.1.0
- SOL2_LUA_VERSION: luajit-2.0.5
SOL2_BUILD_NINJA: 1
MINGW_VERSION: 8.1.0
- SOL2_LUA_VERSION: luajit-2.1.0-beta3
SOL2_BUILD_NINJA: 1
MINGW_VERSION: 8.1.0
- SOL2_LUA_VERSION: 5.3.5
SOL2_NO_2015: 1
- SOL2_LUA_VERSION: 5.2.4
SOL2_NO_2015: 1
- SOL2_LUA_VERSION: 5.1.5
SOL2_NO_2015: 1
matrix:
#fast_finish: true
allow_failures:
# 32-bit builds are temperamental with exceptions
- platform: x86
# Visual Studio 2015 builds are allowed to fail, since I have no intention of dealing with bad old builds
- image: Visual Studio 2015
# LLVM is experimental as all get-out
- LLVM_VERSION: 4.0.0
- SOL2_LUA_VERSION: luajit-2.0.5
- SOL2_LUA_VERSION: luajit-2.1.0-beta3
exclude:
# Necessary: MinGW doesn't exist on VS 2017 images
# Also does not have MinGW x64 for 5.3.0
- image: Visual Studio 2017
MINGW_VERSION: 6.3.0
# LLVM exists in all images, and we only want the VS 2017 x64 versions
MINGW_VERSION: 7.3.0
- image: Visual Studio 2017
MINGW_VERSION: 8.1.0
# There are no recent i686 compilers on the VS2015/2017 images
- MINGW_VERSION: 7.3.0
platform: x86
- MINGW_VERSION: 8.1.0
platform: x86
# Get rid of Visual Studio 2015 builds (unsupported)
- image: Visual Studio 2015
LLVM_VERSION: 4.0.0
SOL2_NO_2015: 1
- platform: x86
LLVM_VERSION: 4.0.0
# Get rid of x86 builds
SOL2_LUA_VERSION: 5.2.4
- platform: x86
LUA_VERSION: 5.2.4
SOL2_LUA_VERSION: 5.1.5
# Get rid of x86 builds for non-latest (no reason to redo that work)
- platform: x86
LUA_VERSION: 5.1.5
SOL2_LUA_VERSION: 5.3.5
- platform: x86
MINGW_VERSION: 7.2.0
# Get rid of redundant Visual Studio 2015 builds
- image: Visual Studio 2015
LUA_VERSION: 5.1.5
- image: Visual Studio 2015
LUA_VERSION: 5.2.4
SOL2_LUA_VERSION: 5.2.4
- platform: x86
SOL2_LUA_VERSION: 5.1.5
init:
# # Ninja
@ -109,10 +119,8 @@ init:
- set python_path=C:\Python36
- set mingw_path=
- set llvm_path=
- if "%MINGW_VERSION%"=="5.3.0" (set mingw_path=C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin)
- if "%MINGW_VERSION%"=="6.3.0" (if "%PLATFORM%"=="x64" (set mingw_path=C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin) else ( set mingw_path=C:\mingw-w64\i686-6.3.0-posix-dwarf-rt_v5-rev1\mingw32\bin))
- if "%MINGW_VERSION%"=="7.2.0" (if "%PLATFORM%"=="x64" (set mingw_path=C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin) else ( set mingw_path=C:\mingw-w64\i686-7.2.0-posix-seh-rt_v5-rev1\mingw32\bin))
- if "%LLVM_VERSION%"=="4.0.0" (set llvm_path=C:\Program Files\LLVM\bin)
- if "%MINGW_VERSION%"=="7.3.0" (if "%PLATFORM%"=="x64" (set mingw_path=C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin) else ( set mingw_path=C:\mingw-w64\i686-7.3.0-posix-seh-rt_v5-rev0\mingw32\bin))
- if "%MINGW_VERSION%"=="8.1.0" (if "%PLATFORM%"=="x64" (set mingw_path=C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin) else ( set mingw_path=C:\mingw-w64\i686-8.1.0-posix-seh-rt_v6-rev0\mingw32\bin))
- if "%PLATFORM%"=="x64" (set python_path=C:\Python36-x64)
- set PATH=%python_path%;%PATH%
- set PATH=%mingw_path%;%PATH%
@ -121,53 +129,46 @@ init:
- echo PATH=%PATH%
# # Generators and CMake arguments
# configure the generator appropriately
- set arch=
- set CMAKE_GENERATOR=Ninja
- set arch= x86
- set parallelism=
- set logger=
- set build_type=
- set build_compiler=
- set lua_build_type=OFF
- set vcvars_script="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
- if "%PLATFORM%"=="x64" (set arch= Win64)
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (set CMAKE_GENERATOR=Visual Studio 15 2017%arch%&&set parallelism=/maxcpucount&&set logger=/verbosity:quiet /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"&&set vcvars_script="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat")
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" (set CMAKE_GENERATOR=Visual Studio 14 2015%arch%&&set parallelism=/maxcpucount&&set logger=/verbosity:quiet /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll")
- if "%MINGW_VERSION%"=="5.3.0" (set CMAKE_GENERATOR=Ninja&&set parallelism= &&set logger= &&set build_type=-DCMAKE_BUILD_TYPE=Release&&set build_compiler=-DCMAKE_CXX_COMPILER=g++.exe -DCMAKE_C_COMPILER=gcc.exe)
- if "%MINGW_VERSION%"=="6.3.0" (set CMAKE_GENERATOR=Ninja&&set parallelism= &&set logger= &&set build_type=-DCMAKE_BUILD_TYPE=Release&&set build_compiler=-DCMAKE_CXX_COMPILER=g++.exe -DCMAKE_C_COMPILER=gcc.exe)
- if "%MINGW_VERSION%"=="7.2.0" (set CMAKE_GENERATOR=Ninja&&set parallelism= &&set logger= &&set build_type=-DCMAKE_BUILD_TYPE=Release&&set build_compiler=-DCMAKE_CXX_COMPILER=g++.exe -DCMAKE_C_COMPILER=gcc.exe)
- if "%LLVM_VERSION%"=="4.0.0" (set CMAKE_GENERATOR=Ninja&&set parallelism= &&set logger= &&set build_type=-DCMAKE_BUILD_TYPE=Release&&set build_compiler=-DCMAKE_CXX_COMPILER=clang-cl.exe -DCMAKE_C_COMPILER=clang-cl.exe)
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (set CMAKE_GENERATOR=Visual Studio 15 2017%arch%)
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" (set CMAKE_GENERATOR=Visual Studio 14 2015%arch%)
- if "%SOL2_BUILD_NINJA%"=="1" (set CMAKE_GENERATOR=Ninja) else (set parallelism=/maxcpucount)
- if "%SOL2_BUILD_NINJA%"=="1" (set build_compiler=-DCMAKE_CXX_COMPILER=cl.exe -DCMAKE_C_COMPILER=cl.exe)
- set vcvars_script="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
- if "%PLATFORM%"=="x86" (set vcvars_script="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86)
- if "%MINGW_VERSION%"=="7.3.0" (set CMAKE_GENERATOR=Ninja&&set build_compiler=-DCMAKE_CXX_COMPILER=g++.exe -DCMAKE_C_COMPILER=gcc.exe)
- if "%MINGW_VERSION%"=="8.1.0" (set CMAKE_GENERATOR=Ninja&&set build_compiler=-DCMAKE_CXX_COMPILER=g++.exe -DCMAKE_C_COMPILER=gcc.exe)
# # Last printouts
# print out generator information
- echo Appveyor Image is %APPVEYOR_BUILD_WORKER_IMAGE% (vcvars script is %vcvars_script%)
- echo cmake generator is %CMAKE_GENERATOR% using build_type=%build_type% and build_compiler=%build_compiler% with special flags logger=%logger% parallelism=%parallelism%
- echo Appveyor Image is %APPVEYOR_BUILD_WORKER_IMAGE%
- echo vcvars_script is %vcvars_script%
- echo cmake generator is %CMAKE_GENERATOR%
- echo build_compiler is %build_compiler%
- echo parallelism is %parallelism%
# print out useful tool information
- ninja --version
- cmake --version
- if DEFINED LLVM_VERSION (clang-cl.exe -v)
- if DEFINED MINGW_VERSION (g++.exe --version)
# We need to use CMAKE_BUILD_TYPE=Release since there are no "configuration"
# toolsets for Ninja or Makefiles as far as cmake is concerned, so
# the --config / -C switches on builds do nothing...!
before_build:
- if DEFINED LLVM_VERSION (call %vcvars_script% && cd C:\projects\sol2)
- md build-sol2
- cd build-sol2
- cmake .. -G "%CMAKE_GENERATOR%" %build_type% %build_compiler% -DLUA_VERSION="%LUA_VERSION%" -DCI=ON -DBUILD_LUA=ON -DBUILD_LUA_AS_DLL=%lua_build_type% -DTESTS=ON -DEXAMPLES=ON -DSINGLE=ON -DTESTS_EXAMPLES=ON -DEXAMPLES_SINGLE=ON -DTESTS_SINGLE=ON
- echo %vcvars_script%
- cd && %vcvars_script%
- cmake .. -G "%CMAKE_GENERATOR%" %build_compiler% -DCMAKE_BUILD_TYPE=Release "-DSOL2_LUA_VERSION=%SOL2_LUA_VERSION%" -DSOL2_PLATFORM=%PLATFORM% -DSOL2_CI=ON -DSOL2_BUILD_LUA=ON -DBUILD_LUA_AS_DLL=ON -DSOL2_TESTS=ON -DSOL2_EXAMPLES=ON -DSOL2_TESTS_EXAMPLES=ON
# We do not build the debug versions because the compiler
# generates too much debug info for MinGW to handle
# TODO: fix the damn compilation space and time already
build_script:
- if NOT "%build_type%"=="-DCMAKE_BUILD_TYPE=Release" (cmake --build . --config Debug -- %parallelism% %logger%)
- cmake --build . --config Release -- %parallelism% %logger%
- cmake --build . --config Release -- %parallelism%
test_script:
- if NOT "%build_type%"=="-DCMAKE_BUILD_TYPE=Release" (ctest -C Debug --output-on-failure)
- ctest -C Release --output-on-failure
notifications:
- provider: Webhook
url: https://webhooks.gitter.im/e/1af10e654a918bef7f1e
url: http://skyhook.glitch.me/api/webhooks/427786348108185611/y2nTmghqltv1SKX2DclEMEKyZtRcwKFlwfZpB_mL1A0nZTVS5MSfumqDKq30-gvWgeL5/appveyor
method: POST
on_build_success: true
on_build_failure: true

View File

@ -1,7 +1,7 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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

View File

@ -1,7 +1,7 @@
# # # # sol2
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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

View File

@ -1,8 +1,8 @@
# # # # sol2
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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

View File

@ -1,233 +0,0 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#.rst:
# FindLua
# -------
#
#
#
# Locate Lua library. This module defines
#
# ::
#
# LUA_FOUND - if false, do not try to link to Lua
# LUA_LIBRARIES - both lua and lualib
# LUA_INCLUDE_DIR - where to find lua.h
# LUA_LIBRARY_DIR - Dir(s) where Lua libraries are found
# LUA_VERSION_STRING - the version of Lua found
# LUA_VERSION_MAJOR - the major version of Lua
# LUA_VERSION_MINOR - the minor version of Lua
# LUA_VERSION_PATCH - the patch version of Lua
#
#
#
# Note that the expected include convention is
#
# ::
#
# #include "lua.h"
#
# and not
#
# ::
#
# #include <lua/lua.h>
#
# This is because, the lua location is not standardized and may exist in
# locations other than lua/
unset(_lua_include_subdirs)
unset(_lua_append_versions)
unset(_lua_library_names)
include(${CMAKE_CURRENT_LIST_DIR}/FindLua/set_version_vars.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/FindLua/version_check.cmake)
# # this is a function only to have all the variables inside go away automatically
# function(_lua_set_version_vars)
# set(LUA_VERSIONS5 5.3 5.2 5.1 5.0)
# if (Lua_FIND_VERSION_EXACT)
# if (Lua_FIND_VERSION_COUNT GREATER 1)
# set(_lua_append_versions ${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR})
# endif ()
# elseif (Lua_FIND_VERSION)
# # once there is a different major version supported this should become a loop
# if (NOT Lua_FIND_VERSION_MAJOR GREATER 5)
# if (Lua_FIND_VERSION_COUNT EQUAL 1)
# set(_lua_append_versions ${LUA_VERSIONS5})
# else ()
# foreach (subver IN LISTS LUA_VERSIONS5)
# if (NOT subver VERSION_LESS ${Lua_FIND_VERSION})
# list(APPEND _lua_append_versions ${subver})
# endif ()
# endforeach ()
# endif ()
# endif ()
# else ()
# # once there is a different major version supported this should become a loop
# set(_lua_append_versions ${LUA_VERSIONS5})
# endif ()
# list(APPEND _lua_include_subdirs "include/lua" "include")
# foreach (ver IN LISTS _lua_append_versions)
# string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _ver "${ver}")
# list(APPEND _lua_include_subdirs
# include/lua${CMAKE_MATCH_1}${CMAKE_MATCH_2}
# include/lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
# include/lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
# )
# list(APPEND _lua_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(_lua_include_subdirs "${_lua_include_subdirs}" PARENT_SCOPE)
# set(_lua_append_versions "${_lua_append_versions}" PARENT_SCOPE)
# endfunction(_lua_set_version_vars)
# function(_lua_check_header_version _hdr_file)
# # 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 "${_hdr_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" LUA_VERSION_MAJOR ";${lua_version_strings};")
# if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$")
# string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings};")
# string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings};")
# set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")
# else ()
# string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_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" LUA_VERSION_STRING ";${lua_version_strings};")
# endif ()
# string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}")
# string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}")
# string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}")
# endif ()
# foreach (ver IN LISTS _lua_append_versions)
# if (ver STREQUAL "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
# set(LUA_VERSION_MAJOR ${LUA_VERSION_MAJOR} PARENT_SCOPE)
# set(LUA_VERSION_MINOR ${LUA_VERSION_MINOR} PARENT_SCOPE)
# set(LUA_VERSION_PATCH ${LUA_VERSION_PATCH} PARENT_SCOPE)
# set(LUA_VERSION_STRING ${LUA_VERSION_STRING} PARENT_SCOPE)
# return()
# endif ()
# endforeach ()
# endfunction(_lua_check_header_version)
_lua_set_version_vars(lua "")
find_path(LUA_INCLUDE_DIR lua.h
HINTS
ENV LUA_DIR
PATH_SUFFIXES ${_lua_include_subdirs} include
PATHS
${LUA_DIR}
~/Library/Frameworks
/Library/Frameworks
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
/usr
/usr/local # Homebrew
)
if (LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
_lua_check_header_version("${LUA_INCLUDE_DIR}/lua.h" "LUA")
endif ()
if (NOT LUA_VERSION_STRING)
foreach (subdir IN LISTS _lua_include_subdirs)
unset(LUA_INCLUDE_PREFIX CACHE)
find_path(LUA_INCLUDE_PREFIX ${subdir}/lua.h
HINTS
ENV LUA_DIR
PATHS
${LUA_DIR}
~/Library/Frameworks
/Library/Frameworks
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
/usr
/usr/local
)
if (LUA_INCLUDE_PREFIX)
_lua_check_header_version("${LUA_INCLUDE_PREFIX}/${subdir}/lua.h")
if (LUA_VERSION_STRING)
set(LUA_INCLUDE_DIR "${LUA_INCLUDE_PREFIX}/${subdir}")
break()
endif ()
endif ()
endforeach ()
endif ()
unset(_lua_include_subdirs)
unset(_lua_append_versions)
find_library(LUA_LIBRARY
NAMES ${_lua_library_names} lua
HINTS
ENV LUA_DIR
PATH_SUFFIXES lib bin
PATHS
${LUA_DIR}
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
/usr
/usr/local
# From the include_dir
${LUA_INCLUDE_DIR}/../lib
)
unset(_lua_library_names)
if (LUA_LIBRARY)
# include the math library for Unix
if (UNIX AND NOT APPLE AND NOT BEOS)
find_library(LUA_MATH_LIBRARY m)
set(LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}")
# include dl library for statically-linked Lua library
get_filename_component(LUA_LIB_EXT ${LUA_LIBRARY} EXT)
if (LUA_LIB_EXT STREQUAL CMAKE_STATIC_LIBRARY_SUFFIX)
list(APPEND LUA_LIBRARIES ${CMAKE_DL_LIBS})
endif ()
# For Windows and Mac, don't need to explicitly include the math library
else ()
set(LUA_LIBRARIES "${LUA_LIBRARY}")
endif ()
set(LUA_LIBRARY_DIR )
foreach (lib ${LUA_LIBRARIES})
get_filename_component(lib_dir ${lib} DIRECTORY CACHE)
list(APPEND LUA_LIBRARY_DIR ${lib_dir})
endforeach ()
list(REMOVE_DUPLICATES LUA_LIBRARY_DIR)
endif ()
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if
# all listed variables are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua
FOUND_VAR Lua_FOUND
REQUIRED_VARS LUA_LIBRARIES LUA_LIBRARY_DIR LUA_INCLUDE_DIR
VERSION_VAR LUA_VERSION_STRING)
mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARY LUA_LIBRARY_DIR LUA_MATH_LIBRARY)

View File

@ -1,7 +1,7 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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

View File

@ -1,7 +1,7 @@
# # # # sol2
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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

View File

@ -1,7 +1,7 @@
# # # # sol2
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -107,7 +107,7 @@ if (LuaBuild_FIND_VERSION)
endif()
endif()
if (NOT LUA_VERSION)
set(LUA_VERSION 5.3.4)
set(LUA_VERSION 5.3.5)
endif()
find_lua_build(${LUA_VERSION})
unset(find_lua_build)
@ -116,5 +116,5 @@ unset(find_lua_build)
# all listed variables are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaBuild
FOUND_VAR LUABUILD_FOUND
REQUIRED_VARS LUA_LIBRARIES LUA_INTERPRETER LUA_INCLUDE_DIRS
REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIRS
VERSION_VAR LUA_VERSION_STRING)

View File

@ -1,7 +1,7 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -145,6 +145,7 @@ 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})
@ -164,11 +165,40 @@ set(LUA_JIT_EXE_FILE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${LUA_JIT_EXE_FILENAME}"
if (MSVC)
# Visual C++ is predicated off running msvcbuild.bat
# which requires a Visual Studio Command Prompt
if (BUILD_LUA_AS_DLL)
set(LUA_JIT_BUILD_COMMAND BUILD_COMMAND cd src && msvcbuild.bat)
else()
set(LUA_JIT_BUILD_COMMAND BUILD_COMMAND cd src && msvcbuild.bat static)
# 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")
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 (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")
@ -189,13 +219,12 @@ else ()
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 "")
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")
set(LUA_JIT_MAKE_TARGET_CFLAGS_MODIFICATIONS "${LUA_JIT_MAKE_TARGET_CFLAGS_MODIFICATIONS} -fPIC")
endif()
if (IS_X86)
list(APPEND LUA_JIT_MAKE_BUILD_MODIFICATIONS "CC=${CMAKE_C_COMPILER} -m32")
@ -217,10 +246,11 @@ else ()
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_BUILD_COMMAND BUILD_COMMAND "${MAKE_PROGRAM}" ${LUA_JIT_MAKE_BUILD_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})
@ -247,15 +277,20 @@ elseif(LUA_JIT_NORMALIZED_LUA_VERSION MATCHES "latest")
set(LUA_JIT_PULL_LATEST TRUE)
endif()
set(LUA_JIT_BYPRODUCTS "${LUA_JIT_SOURCE_LUA_LIB}" "${LUA_JIT_SOURCE_LUA_LIB_EXP}"
"${LUA_JIT_SOURCE_LUA_DLL}" "${LUA_JIT_SOURCE_LUA_INTERPRETER}")
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}")
set(LUA_JIT_INSTALL_BYPRODUCTS "${LUA_JIT_DESTINATION_LUA_LIB}" "${LUA_JIT_DESTINATION_LUA_LIB_EXP}"
"${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)
set(LUA_JIT_BYPRODUCTS "${LUA_JIT_BYPRODUCTS}" "${LUA_JIT_SOURCE_LUA_IMP_LIB}")
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
@ -264,20 +299,37 @@ set(LUA_JIT_POSTBUILD_COMMENTS "Executable - Moving \"${LUA_JIT_SOURCE_LUA_INTER
set(LUA_JIT_POSTBUILD_COMMANDS COMMAND "${CMAKE_COMMAND}" -E copy "${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}\nImport Library - Moving \"${LUA_JIT_SOURCE_LUA_IMP_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_IMP_LIB}\"...")
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 "${LUA_JIT_SOURCE_LUA_IMP_LIB}" "${LUA_JIT_DESTINATION_LUA_IMP_LIB}")
set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS}\nLibrary - Moving \"${LUA_JIT_SOURCE_LUA_LIB_EXP}\" to \"${LUA_JIT_DESTINATION_LUA_LIB_EXP}\"...")
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 "${LUA_JIT_SOURCE_LUA_LIB_EXP}" "${LUA_JIT_DESTINATION_LUA_LIB_EXP}")
endif()
set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS}\nDynamic Library - Moving \"${LUA_JIT_SOURCE_LUA_DLL}\" to \"${LUA_JIT_DESTINATION_LUA_DLL}\"...")
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 "${LUA_JIT_SOURCE_LUA_DLL}" "${LUA_JIT_DESTINATION_LUA_DLL}")
else()
set(LUA_JIT_POSTBUILD_COMMENTS "${LUA_JIT_POSTBUILD_COMMENTS}\nLibrary - Moving \"${LUA_JIT_SOURCE_LUA_LIB}\" to \"${LUA_JIT_DESTINATION_LUA_LIB}\"...")
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 "${LUA_JIT_SOURCE_LUA_LIB}" "${LUA_JIT_DESTINATION_LUA_LIB}")
endif()
if (LUA_JIT_GIT_COMMIT OR LUA_JIT_PULL_LATEST)
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)
@ -304,7 +356,7 @@ if (LUA_JIT_GIT_COMMIT OR LUA_JIT_PULL_LATEST)
else()
ExternalProject_Add(LUA_JIT
BUILD_IN_SOURCE TRUE
BUILD_ALWAYS FALSE
BUILD_ALWAYS TRUE
# LuaJIT does not offer a TLS/SSL port
TLS_VERIFY FALSE
PREFIX "${LUA_BUILD_TOPLEVEL}"
@ -323,58 +375,46 @@ else()
BUILD_BYPRODUCTS ${LUA_JIT_BYPRODUCTS})
endif()
# # MAYBE?:
# Add additional post-build step to move all necessary headers/lua files
# for now, we just point directly to the `src` directory...
add_custom_command(TARGET LUA_JIT
POST_BUILD
${LUA_JIT_POSTBUILD_COMMANDS}
COMMENT ${LUA_JIT_POSTBUILD_COMMENTS}
BYPRODUCTS ${LUA_JIT_INSTALL_BYPRODUCTS})
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} ${LUA_BUILD_LIBRARY_TYPE} IMPORTED)
# make sure the library we export really does depend on Lua JIT's external project
add_dependencies(${lualib} LUA_JIT)
# Configure properties
add_library(${lualib} INTERFACE)
add_dependencies(${lualib} LUA_JIT-move)
target_include_directories(${lualib}
INTERFACE "${LUA_JIT_SOURCE_DIR}")
if (BUILD_LUA_AS_DLL)
if (MSVC)
set_target_properties(${lualib}
PROPERTIES
IMPORTED_IMPLIB "${LUA_JIT_DESTINATION_LUA_IMP_LIB}")
target_link_libraries(${lualib}
INTERFACE "${LUA_JIT_DESTINATION_LUA_LIB}")
else()
target_link_libraries(${lualib}
INTERFACE "${LUA_JIT_DESTINATION_LUA_DLL}")
endif()
set_target_properties(${lualib}
PROPERTIES
IMPORTED_LOCATION "${LUA_JIT_DESTINATION_LUA_DLL}")
else ()
set_target_properties(${lualib}
PROPERTIES
IMPORTED_LOCATION "${LUA_JIT_DESTINATION_LUA_LIB}")
else()
target_link_libraries(${lualib}
INTERFACE "${LUA_JIT_DESTINATION_LUA_LIB}")
endif()
set_target_properties(${lualib}
PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES C
INTERFACE_INCLUDE_DIRECTORIES "${LUA_JIT_SOURCE_DIR}")
if (CMAKE_DL_LIBS)
set_target_properties(${lualib}
PROPERTIES
INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS})
target_link_libraries(${lualib}
INTERFACE ${CMAKE_DL_LIBS})
endif()
if (XCODE)
target_compile_options(${lualib}
PUBLIC -pagezero_size 10000 -image_base 100000000)
INTERFACE -pagezero_size 10000 -image_base 100000000)
endif ()
# # Lua Executable
add_executable(${luainterpreter} IMPORTED)
# Add location pointing to executable
set_target_properties(${luainterpreter}
PROPERTIES
IMPORTED_LOCATION "${LUA_JIT_DESTINATION_LUA_INTERPRETER}")
add_dependencies(${luainterpreter} LUA_JIT)
# # set externally-visible target indicator
set(LUA_LIBRARIES ${lualib})
set(LUA_INTERPRETER ${luainterpreter})
set(LUA_INCLUDE_DIRS "${LUA_JIT_SOURCE_DIR}")
set(LUA_INTERPRETER "")
set(LUA_INCLUDE_DIRS "${LUA_JIT_INCLUDE_DIRS}")

View File

@ -1,7 +1,7 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -34,10 +34,17 @@ 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.4)
set(LUA_VANILLA_5.3_LATEST_VERSION 5.3.5)
set(LUA_VANILLA_5.4_LATEST_VERSION 5.4.0-work1)
# exact version, coming from CI: pull directly from Lua and use external project to build
# list of known md5 / sha1: must update when there are changes
set(LUA_VANILLA_MD5_5.4.0-work2 3cdf2a4eb84dde6b6aaf5d2d1de07be9)
set(LUA_VANILLA_SHA1_5.4.0-work2 e8484e61c5c338e3ec2f75dbe0f6703d079fecf9)
set(LUA_VANILLA_MD5_5.4.0-work1 0ff232b8658884155a43cf72212edbd9)
set(LUA_VANILLA_SHA1_5.4.0-work1 a8193b14ed3869917d1102cb0418cf9dfb0d9baf)
set(LUA_VANILLA_MD5_5.3.5 4f4b4f323fd3514a68e0ab3da8ce3455)
set(LUA_VANILLA_SHA1_5.3.5 112eb10ff04d1b4c9898e121d6bdf54a81482447)
set(LUA_VANILLA_MD5_5.3.4 53a9c68bcc0eda58bdc2095ad5cdfc63)
set(LUA_VANILLA_SHA1_5.3.4 79790cfd40e09ba796b01a571d4d63b52b1cd950)
set(LUA_VANILLA_MD5_5.3.3 703f75caa4fdf4a911c1a72e67a27498)
@ -118,6 +125,8 @@ elseif (LUA_VERSION MATCHES "([0-9]+)\\.([0-9]+)")
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
@ -156,7 +165,6 @@ endif()
# # Potential compiler variables
if (MSVC)
set(LUA_VANILLA_LUA_LUAC_COMPILER_OPTIONS "/W1")
if (BUILD_LUA_AS_DLL)
set(LUA_VANILLA_DLL_DEFINE LUA_BUILD_AS_DLL)
else()
@ -169,6 +177,7 @@ 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
@ -187,10 +196,7 @@ elseif (LUA_VANILLA_VERSION MATCHES "^5\\.2")
set(LUA_VANILLA_LUA_SOURCES lua.c )
set(LUA_VANILLA_LUAC_SOURCES luac.c )
set(LUA_VANILLA_GENERATE_LUA_HPP false)
else()
if (NOT LUA_VANILLA_VERSION MATCHES "^5\\.3")
message(STATUS "Using the Lua 5.3 sources list for a version of Lua that is not 5.3: may result in an incomplete build or errors later")
endif()
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
@ -199,6 +205,28 @@ else()
set(LUA_VANILLA_LUA_SOURCES lua.c )
set(LUA_VANILLA_LUAC_SOURCES luac.c )
set(LUA_VANILLA_GENERATE_LUA_HPP false)
elseif (LUA_VANILLA_VERSION MATCHES "^5\\.4")
if (LUA_VANILLA_VERSION MATCHES "work")
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 )
set(LUA_VANILLA_LUAC_SOURCES luac.c )
set(LUA_VANILLA_GENERATE_LUA_HPP false)
else()
MESSAGE(WARNING "Using Lua 5.4.0-work1 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 )
set(LUA_VANILLA_LUAC_SOURCES luac.c )
set(LUA_VANILLA_GENERATE_LUA_HPP false)
endif()
set(LUA_VANILLA_SOURCE_DIR "${LUA_BUILD_TOPLEVEL}/src")
@ -207,32 +235,38 @@ prepend(LUA_VANILLA_LUA_SOURCES "${LUA_VANILLA_SOURCE_DIR}/" ${LUA_VANILLA_LUA_S
prepend(LUA_VANILLA_LUAC_SOURCES "${LUA_VANILLA_SOURCE_DIR}/" ${LUA_VANILLA_LUAC_SOURCES})
# download, just for the sake of download + extract
# have to use 2 different commands just to have an empty command
# that results in nothing being run
# TODO: talk to smarter CMake people...?
# 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}" "${LUA_VANILLA_LUAC_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}
URL_MD5 ${LUA_VANILLA_MD5}
URL_HASH SHA1=${LUA_VANILLA_SHA1}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
BUILD_BYPRODUCTS "${LUA_VANILLA_LIB_SOURCES}" "${LUA_VANILLA_LUA_SOURCES}" "${LUA_VANILLA_LUAC_SOURCES}")
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 https://www.lua.org/ftp/lua-${LUA_VANILLA_VERSION}.tar.gz
URL_MD5 ${LUA_VANILLA_MD5}
URL_HASH SHA1=${LUA_VANILLA_SHA1}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
BUILD_BYPRODUCTS "${LUA_VANILLA_LIB_SOURCES}" "${LUA_VANILLA_LUA_SOURCES}" "${LUA_VANILLA_LUAC_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
# 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++
// <<extern \"C\">> not supplied automatically because Lua also compiles as C++
@ -242,19 +276,22 @@ extern \"C\" {
#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}")
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
@ -279,13 +316,12 @@ set_target_properties(${liblua}
C_STANDARD 99
C_EXTENSIONS TRUE
POSITION_INDEPENDENT_CODE TRUE
INCLUDE_DIRECTORIES ${LUA_VANILLA_SOURCE_DIR}
OUTPUT_NAME ${LUA_BUILD_LIBNAME}
RUNTIME_OUTPUT_NAME ${LUA_BUILD_LIBNAME}
LIBRARY_OUTPUT_NAME ${LUA_BUILD_LIBNAME}
ARCHIVE_OUTPUT_NAME ${LUA_BUILD_LIBNAME})
target_include_directories(${liblua}
PUBLIC ${LUA_VANILLA_SOURCE_DIR})
PUBLIC "${LUA_VANILLA_INCLUDE_DIRS}")
target_compile_definitions(${liblua}
PUBLIC LUA_COMPAT_ALL ${LUA_VANILLA_DLL_DEFINE})
if (MSVC)
@ -306,10 +342,10 @@ target_compile_options(${liblua}
PRIVATE ${LUA_VANILLA_LUALIB_COMPILER_OPTIONS})
add_dependencies(${liblua} LUA_VANILLA)
if (CMAKE_DL_LIBS)
target_link_libraries(${liblua} ${CMAKE_DL_LIBS})
target_link_libraries(${liblua} PRIVATE ${CMAKE_DL_LIBS})
endif()
if (UNIX)
target_link_libraries(${liblua} m)
target_link_libraries(${liblua} PRIVATE m)
endif()
# we don't really need this section...
@ -323,7 +359,7 @@ set_target_properties(${luainterpreter}
C_EXTENSIONS TRUE
OUTPUT_NAME lua-${LUA_VANILLA_VERSION})
target_include_directories(${luainterpreter}
PRIVATE ${LUA_VANILLA_SOURCE_DIR})
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})
@ -341,14 +377,12 @@ else()
target_compile_definitions(${luainterpreter}
PRIVATE LUA_USE_LINUX)
endif()
target_compile_options(${luainterpreter}
PRIVATE ${LUA_VANILLA_LUA_LUAC_COMPILER_OPTIONS})
target_link_libraries(${luainterpreter} ${liblua})
target_link_libraries(${luainterpreter} PRIVATE ${liblua})
if (CMAKE_DL_LIBS)
target_link_libraries(${luainterpreter} ${CMAKE_DL_LIBS})
target_link_libraries(${luainterpreter} PRIVATE ${CMAKE_DL_LIBS})
endif()
if (UNIX)
target_link_libraries(${luainterpreter} m readline)
target_link_libraries(${luainterpreter} PRIVATE m readline)
endif()
# LuaC Compiler
@ -365,9 +399,7 @@ set_target_properties(${luacompiler}
C_EXTENSIONS TRUE
OUTPUT_NAME luac-${LUA_VANILLA_VERSION})
target_include_directories(${luacompiler}
PRIVATE ${LUA_VANILLA_SOURCE_DIR})
target_compile_options(${luacompiler}
PRIVATE ${LUA_VANILLA_LUA_LUAC_COMPILER_OPTIONS})
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})
@ -385,13 +417,13 @@ else()
target_compile_definitions(${luacompiler}
PRIVATE LUA_USE_LINUX)
endif()
target_link_libraries(${luacompiler} ${liblua})
target_link_libraries(${luacompiler} PRIVATE ${liblua})
if (CMAKE_DL_LIBS)
target_link_libraries(${luacompiler} ${CMAKE_DL_LIBS})
target_link_libraries(${luacompiler} PRIVATE ${CMAKE_DL_LIBS})
endif()
if (UNIX)
# TODO: make readline optional?
target_link_libraries(${luacompiler} m readline)
target_link_libraries(${luacompiler} PRIVATE m readline)
endif()
# set externally-visible target indicator

View File

@ -1,173 +0,0 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#.rst:
# FindLuaJIT
# -------
#
#
#
# Locate LuaJIT library. This module defines
#
# ::
#
# LUAJIT_FOUND - if false, do not try to link to LuaJIT
# LUAJIT_LIBRARIES - both lua and lualib
# LUAJIT_INCLUDE_DIR - where to find lua.h and luajit.h
# LUAJIT_VERSION_STRING - the version of LuaJIT found
# LUAJIT_VERSION_MAJOR - the major version of LuaJIT
# LUAJIT_VERSION_MINOR - the minor version of LuaJIT
# LUAJIT_VERSION_PATCH - the patch version of LuaJIT
# LUAJIT_LUA_VERSION_STRING - the version of Lua the found LuaJIT is compatible with
#
#
#
# Note that the expected include convention is
#
# ::
#
# #include "lua.h"
#
# and not
#
# ::
#
# #include <lua/lua.h>
#
# This is because, the lua location is not standardized and may exist in
# locations other than lua/
unset(_luajit_include_subdirs)
unset(_luajit_append_versions)
unset(_luajit_library_names)
include(${CMAKE_CURRENT_LIST_DIR}/FindLua/set_version_vars.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/FindLua/version_check.cmake)
_lua_set_version_vars(luajit "jit")
find_path(LUAJIT_INCLUDE_DIR luajit.h
HINTS
ENV LUAJIT_DIR
PATH_SUFFIXES ${_luajit_include_subdirs} include/luajit include
PATHS
${LUAJIT_DIR}
~/Library/Frameworks
/Library/Frameworks
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
/usr
/usr/local # Homebrew
)
if (LUAJIT_INCLUDE_DIR AND EXISTS "${LUAJIT_INCLUDE_DIR}/lua.h")
_lua_check_header_version("${LUAJIT_INCLUDE_DIR}/lua.h" "LUAJIT")
endif ()
if (NOT LUAJIT_VERSION_STRING)
foreach (subdir IN LISTS _luajit_include_subdirs)
unset(LUAJIT_INCLUDE_PREFIX CACHE)
find_path(LUAJIT_INCLUDE_PREFIX ${subdir}/lua.h
HINTS
ENV LUA_DIR
PATHS
${LUA_DIR}
~/Library/Frameworks
/Library/Frameworks
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
/usr
/usr/local # Homebrew
)
if (LUAJIT_INCLUDE_PREFIX)
_lua_check_header_version("${LUAJIT_INCLUDE_PREFIX}/${subdir}/lua.h" "LUAJIT")
if (LUAJIT_VERSION_STRING)
set(LUAJIT_INCLUDE_DIR "${LUAJIT_INCLUDE_PREFIX}/${subdir}")
break()
endif ()
endif ()
endforeach ()
endif ()
unset(_luajit_include_subdirs)
unset(_luajit_append_versions)
if (LUAJIT_INCLUDE_DIR AND EXISTS "${LUAJIT_INCLUDE_DIR}/luajit.h")
# LuaJIT defines two preprocessor macros:
# LUA_VERSION -> version string with lua version in it
# LUA_VERSION_NUM -> numeric representation, i.e. 20003 for 2.0.3
# This just parses the LUAJIT_VERSION macro and extracts the version.
file(STRINGS "${LUAJIT_INCLUDE_DIR}/luajit.h" version_strings
REGEX "^#define[ \t]+LUAJIT_VERSION?[ \t]+(\"LuaJIT [0-9\\.]+(-(beta|alpha)[0-9]*)?\").*")
string(REGEX REPLACE ".*;#define[ \t]+LUAJIT_VERSION[ \t]+\"LuaJIT ([0-9\\.]+(-(beta|alpha)[0-9]*)?)\"[ \t]*;.*" "\\1" LUAJIT_VERSION_STRING_SHORT ";${version_strings};")
string(REGEX REPLACE ".*;([0-9]+\\.[0-9]+\\.[0-9]+(-(beta|alpha)[0-9]*)?);.*" "\\1" luajit_version_num ";${LUAJIT_VERSION_STRING_SHORT};")
string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.(-(beta|alpha)[0-9]*)?$" "\\1" LUAJIT_VERSION_MAJOR "${luajit_version_num}")
string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9](-(beta|alpha)[0-9]*)?$" "\\1" LUAJIT_VERSION_MINOR "${luajit_version_num}")
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+(-(beta|alpha)[0-9]*)?)$" "\\1" LUAJIT_VERSION_PATCH "${luajit_version_num}")
# We can also set the LUAJIT_LUA_VERSION_* fields that are found by FindLua.
# We do this as LuaJIT claims full compatibility with a certain LUA version.
_lua_check_header_version("${LUAJIT_INCLUDE_DIR}/lua.h" "LUAJIT_LUA_")
set(LUAJIT_VERSION_STRING "${LUAJIT_LUA_VERSION_STRING} (${LUAJIT_VERSION_STRING_SHORT})")
endif()
find_library(LUAJIT_LIBRARY
NAMES ${_luajit_library_names} luajit lua
HINTS
ENV LUAJIT_DIR
PATH_SUFFIXES lib
PATHS
${LUAJIT_DIR}
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
/usr
/usr/local # Homebrew
)
unset(_luajit_library_names)
if (LUAJIT_LIBRARY)
# include the math library for Unix
if (UNIX AND NOT APPLE AND NOT BEOS)
find_library(LUAJIT_MATH_LIBRARY m)
set(LUAJIT_LIBRARIES "${LUAJIT_LIBRARY};${LUAJIT_MATH_LIBRARY}")
# For Windows and Mac, don't need to explicitly include the math library
else ()
set(LUAJIT_LIBRARIES "${LUAJIT_LIBRARY}")
endif ()
set(LUAJIT_LIBRARY_DIR )
foreach (lib ${LUAJIT_LIBRARIES})
get_filename_component(lib_dir ${lib} DIRECTORY CACHE)
list(APPEND LUAJIT_LIBRARY_DIR ${lib_dir})
endforeach ()
list(REMOVE_DUPLICATES LUAJIT_LIBRARY_DIR)
endif ()
if(APPLE)
# Not sure why this is true, but its mentioned here:
# http://luajit.org/install.html#embed
set(LUAJIT_LINK_FLAGS "-pagezero_size 10000 -image_base 100000000")
else()
set(LUAJIT_LINK_FLAGS "")
endif()
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LuaJIT_FOUND to TRUE if
# all listed variables are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaJIT
FOUND_VAR LuaJIT_FOUND
REQUIRED_VARS LUAJIT_LIBRARIES LUAJIT_INCLUDE_DIR LUAJIT_LIBRARY_DIR
VERSION_VAR LUAJIT_VERSION_STRING)
mark_as_advanced(LUAJIT_INCLUDE_DIR LUAJIT_LIBRARY LUAJIT_LIBRARY_DIR LUAJIT_MATH_LIBRARY LUAJIT_LINK_FLAGS)

View File

@ -1,7 +1,7 @@
# # # # sol2
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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

View File

@ -1,7 +1,7 @@
# # # # sol2
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -57,7 +57,7 @@ ExternalProject_Add(TOLUAPP_BUILD_SOURCE
TEST_COMMAND ""
BUILD_BYPRODUCTS "${toluapp_sources}")
set(toluapp_lib toluapp_lib_5.2.4)
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
@ -70,7 +70,7 @@ if (MSVC)
target_compile_options(${toluapp_lib}
PRIVATE /W1)
target_compile_definitions(${toluapp_lib}
PRIVATE TOLUA_API=__declspec(dllexport))
PRIVATE "TOLUA_API=__declspec(dllexport)")
else()
target_compile_options(${toluapp_lib}
PRIVATE -w

View File

@ -1,7 +1,7 @@
# # # # sol2
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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

43
docs/CMakeLists.txt Normal file
View File

@ -0,0 +1,43 @@
# # # # sol3
# The MIT License (MIT)
#
# Copyright (c) 2013-2019 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.
# # # # sol3, documentation generation
# # # Required minimum version statement
cmake_minimum_required(VERSION 3.5.0)
find_package(PythonInterp 3)
if (NOT PYTHONINTERP_FOUND)
message(FATAL_ERROR "sol2 documentation cannot be generated as python 3 has not been found: install or set the python 3 interpreter for the docs to find it and be sure to pip install sphinx")
endif()
find_program(sol2_make_executable make make.exe mingw32-make mingw32-make.exe)
if(NOT sol2_make_executable)
message(FATAL_ERROR "could not find a suitable make executable to build Sphinx documentation")
endif()
add_custom_command(OUTPUT docs_invisible_file_always_generate
USES_TERMINAL
COMMAND "${sol2_make_executable}" -C "${CMAKE_CURRENT_SOURCE_DIR}" html "BUILDDIR=${CMAKE_CURRENT_BINARY_DIR}")
add_custom_target(docs
DEPENDS docs_invisible_file_always_generate)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/docs/html" DESTINATION "${CMAKE_INSTALL_DOCDIR}")

View File

@ -15,7 +15,7 @@ as_args
``sol::as_args`` is a function that that takes an iterable and turns it into multiple arguments to a function call. It forwards its arguments, and is meant to be used as shown below:
.. literalinclude:: ../../../examples/args_from_container.cpp
.. literalinclude:: ../../../examples/source/args_from_container.cpp
:caption: args_from_container.cpp
:linenos:

View File

@ -12,7 +12,7 @@ This function serves the purpose of ensuring that a callable struct (like a lamb
This class can also make it so usertypes bind variable types as functions to for usertype bindings.
.. literalinclude:: ../../../examples/docs/as_function.cpp
.. literalinclude:: ../../../examples/source/docs/as_function.cpp
:linenos:
@ -20,5 +20,5 @@ Note that if you actually want a userdata, but you want it to be callable, you s
Here's an example of binding a variable as a function to a usertype:
.. literalinclude:: ../../../examples/docs/as_function_usertype_member_variable.cpp
.. literalinclude:: ../../../examples/source/docs/as_function_usertype_member_variable.cpp
:linenos:

View File

@ -15,5 +15,5 @@ as_returns
This allows you to wrap up a source that has ``begin`` and ``end`` iterator-returning functions on it and return it as multiple results into Lua. To have more control over the returns, use :doc:`sol::variadic_results<variadic_results>`.
.. literalinclude:: ../../../examples/as_returns.cpp
.. literalinclude:: ../../../examples/source/as_returns.cpp
:linenos:

View File

@ -13,7 +13,7 @@ as_table
This function serves the purpose of ensuring that an object is pushed -- if possible -- like a table into Lua. The container passed here can be a pointer, a reference, a ``std::reference_wrapper`` around a container, or just a plain container value. It must have a begin/end function, and if it has a ``std::pair<Key, Value>`` as its ``value_type``, it will be pushed as a dictionary. Otherwise, it's pushed as a sequence.
.. literalinclude:: ../../../examples/docs/as_table_ipairs.cpp
.. literalinclude:: ../../../examples/source/docs/as_table_ipairs.cpp
:linenos:
Note that any caveats with Lua tables apply the moment it is serialized, and the data cannot be gotten out back out in C++ as a C++ type. You can deserialize the Lua table into something explicitly using the ``sol::as_table_t`` marker for your get and conversion operations using Sol. At that point, the returned type is deserialized **from** a table, meaning you cannot reference any kind of C++ data directly as you do with regular userdata/usertypes. *All C++ type information is lost upon serialization into Lua.*

View File

@ -23,7 +23,7 @@ It is advisable for the user to consider making a macro to do the necessary ``de
Here's an example below of various ways to use ``sol::c_call``:
.. literalinclude:: ../../../examples/c_call.cpp
.. literalinclude:: ../../../examples/source/c_call.cpp
:linenos:
.. _one similar to this: http://stackoverflow.com/a/5628222/5280922

View File

@ -18,7 +18,7 @@ This type is passed to :ref:`sol::state(_view)::script/do_x<state-script-functio
There are many more uses, including storing state or special dependent variables in an environment that you pre-create using regular table opertions, and then changing at-will:
.. literalinclude:: ../../../examples/docs/preparing_environments.cpp
.. literalinclude:: ../../../examples/source/docs/preparing_environments.cpp
:linenos:
Also note that ``sol::environment`` derives from ``sol::table``, which also derives from ``sol::reference``: in other words, copying one ``sol::environment`` value to another ``sol::environment`` value **does not** deep-copy the table, just creates a new reference pointing to the same lua object.
@ -56,14 +56,14 @@ members
environment(lua_State* L, sol::new_table nt);
environment(lua_State* L, sol::new_table nt, const sol::reference& fallback);
environment(sol::env_t, const sol::reference& object_that_has_environment);
environment(sol::env_t, const sol::stack_reference& object_that_has_environment);
environment(sol::env_key_t, const sol::reference& object_that_has_environment);
environment(sol::env_key_t, const sol::stack_reference& object_that_has_environment);
The ones from table are used here (of particular note is the ability to use ``sol::environment(my_lua_state, sol::create);`` to make a fresh, unnamed environment), plus the three unique constructors shown above.
The first constructor is generally used as ``sol::environment my_env(my_lua_state, sol::create, my_fallback_table);``. The fallback table serves as the backup to lookup attempts on the environment table being created. It is achieved by simply creating a metatable for the ``sol::environment`` being created, and then doing ``env_metatable["__index"] = fallback;``. You can achieve fancier effects by changing the metatable of the environment to your liking, by creating it in some fashion and then setting the metatable explicitly and populating it with data, particularly with :doc:`sol::metatable_key<metatable_key>`.
The second and third unique constructors take a special empty type that serves as a key to trigger this constructor and serves no other purpose, ``sol::env_t``. The shortcut value so you don't have to create one is called ``sol::env_key``. It is used like ``sol::environment my_env(sol::env_key, some_object);``. It will extract the environment out of whatever the second argument is that may or may not have an environment. If it does not have an environment, the constructor will complete but the object will have ``env.valid() == false``, since it will reference Lua's ``nil``.
The second and third unique constructors take a special empty type that serves as a key to trigger this constructor and serves no other purpose, ``sol::env_key_t``. The shortcut value so you don't have to create one is called ``sol::env_key``. It is used like ``sol::environment my_env(sol::env_key, some_object);``. It will extract the environment out of whatever the second argument is that may or may not have an environment. If it does not have an environment, the constructor will complete but the object will have ``env.valid() == false``, since it will reference Lua's ``nil``.
.. code-block:: cpp

View File

@ -22,14 +22,14 @@ Function is a correct-assuming version of :doc:`protected_function<protected_fun
Calls the constructor and creates this type, straight from the stack. For example:
.. literalinclude:: ../../../examples/tie.cpp
.. literalinclude:: ../../../examples/source/tie.cpp
:caption: funcs.lua
:lines: 9-13
:linenos:
The following C++ code will call this function from this file and retrieve the return value:
.. literalinclude:: ../../../examples/tie.cpp
.. literalinclude:: ../../../examples/source/tie.cpp
:lines: 1-7,16-22
:linenos:
@ -37,7 +37,7 @@ The call ``woof(20)`` generates a :ref:`unsafe_function_result<unsafe-function-r
You can also return multiple values by using ``std::tuple``, or if you need to bind them to pre-existing variables use ``sol::tie``:
.. literalinclude:: ../../../examples/tie.cpp
.. literalinclude:: ../../../examples/source/tie.cpp
:lines: 24-
:linenos:

View File

@ -10,6 +10,6 @@ metatable_key
You can use this in conjunction with :doc:`sol::table<table>` to set/get a metatable. Lua metatables are powerful ways to override default behavior of objects for various kinds of operators, among other things. Here is an entirely complete example, showing getting and working with a :doc:`usertype<usertype>`'s metatable defined by Sol:
.. literalinclude:: ../../../examples/metatable_key_low_level.cpp
.. literalinclude:: ../../../examples/source/metatable_key_low_level.cpp
:caption: messing with metatables
:linenos:

View File

@ -32,19 +32,19 @@ Its use is simple: wherever you can pass a function type to Lua, whether its on
The functions can be any kind of function / function object (lambda). Given these functions and struct:
.. literalinclude:: ../../../examples/overloading_with_members.cpp
.. literalinclude:: ../../../examples/source/overloading_with_members.cpp
:linenos:
:lines: 1-27
You then use it just like you would for any other part of the api:
.. literalinclude:: ../../../examples/overloading_with_members.cpp
.. literalinclude:: ../../../examples/source/overloading_with_members.cpp
:linenos:
:lines: 29-45
Doing the following in Lua will call the specific overloads chosen, and their associated functions:
.. literalinclude:: ../../../examples/overloading_with_members.cpp
.. literalinclude:: ../../../examples/source/overloading_with_members.cpp
:linenos:
:lines: 47-

View File

@ -13,6 +13,6 @@ property
These set of functions create a type which allows a setter and getter pair (or a single getter, or a single setter) to be used to create a variable that is either read-write, read-only, or write-only. When used during :doc:`usertype<usertype>` construction, it will create a variable that uses the setter/getter member function specified.
.. literalinclude:: ../../../examples/property.cpp
.. literalinclude:: ../../../examples/source/property.cpp
:linenos:

View File

@ -10,5 +10,5 @@ protect
``sol::protect( my_func )`` allows you to protect a function call or member variable call when it is being set to Lua. It can be used with usertypes or when just setting a function into Sol. Below is an example that demonstrates that a call that would normally not error without :doc:`Safety features turned on<../safety>` that instead errors and makes the Lua safety-call wrapper ``pcall`` fail:
.. literalinclude:: ../../../examples/protect.cpp
.. literalinclude:: ../../../examples/source/protect.cpp
:linenos:

View File

@ -11,13 +11,13 @@ Inspired by a request from `starwing`_ in the :doc:`old sol repository<../origin
When called without the return types being specified by either a ``sol::types<...>`` list or a ``call<Ret...>( ... )`` template type list, it generates a :doc:`protected_function_result<proxy>` class that gets implicitly converted to the requested return type. For example:
.. literalinclude:: ../../../examples/error_handler.cpp
.. literalinclude:: ../../../examples/source/error_handler.cpp
:linenos:
:lines: 10-28
The following C++ code will call this function from this file and retrieve the return value, unless an error occurs, in which case you can bind an error handling function like so:
.. literalinclude:: ../../../examples/error_handler.cpp
.. literalinclude:: ../../../examples/source/error_handler.cpp
:linenos:
:lines: 1-6,30-66
@ -26,7 +26,7 @@ This code is much more long-winded than its :doc:`function<function>` counterpar
Alternatively, with a bad or good function call, you can use ``sol::optional`` to check if the call succeeded or failed:
.. literalinclude:: ../../../examples/error_handler.cpp
.. literalinclude:: ../../../examples/source/error_handler.cpp
:linenos:
:lines: 67-

View File

@ -27,19 +27,19 @@ proxy
``proxy`` is returned by lookups into :doc:`sol::table<table>` and table-like entities. Because it is templated on key and table type, it would be hard to spell: you can capture it using the word ``auto`` if you feel like you need to carry it around for some reason before using it. ``proxy`` evaluates its arguments lazily, when you finally call ``get`` or ``set`` on it. Here are some examples given the following lua script:
.. literalinclude:: ../../../examples/table_proxy.cpp
.. literalinclude:: ../../../examples/source/table_proxy.cpp
:linenos:
:lines: 11-15
After loading that file in or putting it in a string and reading the string directly in lua (see :doc:`state`), you can start kicking around with it in C++ like so:
.. literalinclude:: ../../../examples/table_proxy.cpp
.. literalinclude:: ../../../examples/source/table_proxy.cpp
:linenos:
:lines: 1-8,18-40
We don't recommend using ``proxy`` lazy evaluation the above to be used across classes or between function: it's more of something you can do to save a reference to a value you like, call a script or run a lua function, and then get it afterwards. You can also set functions (and function objects) this way, and retrieve them as well:
.. literalinclude:: ../../../examples/table_proxy.cpp
.. literalinclude:: ../../../examples/source/table_proxy.cpp
:linenos:
:lines: 41-

View File

@ -14,7 +14,7 @@ The goal of read-only is to protect a variable set on a usertype or a function.
If you are looking to make a read-only table, you need to go through a bit of a complicated song and dance by overriding the ``__index`` metamethod. Here's a complete example on the way to do that using ``sol``:
.. literalinclude:: ../../../examples/read_only.cpp
.. literalinclude:: ../../../examples/source/read_only.cpp
:caption: read_only.cpp
:linenos:

View File

@ -241,7 +241,7 @@ This is an SFINAE-friendly struct that is meant to expose static function ``get`
:name: pusher
template <typename X, typename = void>
struct pusher {
struct unqualified_pusher {
template <typename T>
static int push ( lua_State* L, T&&, ... ) {
// can optionally take more than just 1 argument

View File

@ -17,7 +17,7 @@ This type is particular to working with the stack. It does not push the function
Furthermore, if you know you have a function in the right place alongside proper arguments on top of it, you can use the ``sol::stack_count`` structure and give its constructor the number of arguments off the top that you want to call your pre-prepared function with:
.. literalinclude:: ../../../examples/stack_aligned_function.cpp
.. literalinclude:: ../../../examples/source/stack_aligned_function.cpp
:caption: stack_aligned_function.cpp
:linenos:
:name: stack-aligned-function-example

View File

@ -100,7 +100,7 @@ If your script returns a value, you can capture it from the returned :ref:`sol::
To handle errors when using the second overload, provide a callable function/object that takes a ``lua_State*`` as its first argument and a ``sol::protected_function_result`` as its second argument. ``sol::script_default_on_error`` and ``sol::script_pass_on_error`` are 2 functions provided by sol that will either generate a traceback error to return / throw (if throwing is allowed); or, pass the error on through and return it to the user (respectively). An example of having your:
.. literalinclude:: ../../../examples/docs/state_script_safe.cpp
.. literalinclude:: ../../../examples/source/docs/state_script_safe.cpp
:linenos:
:name: state-script-safe

View File

@ -9,7 +9,7 @@ Sometimes in C++ it's useful to know where a Lua call is coming from and what :d
:linenos:
#define SOL_CHECK_ARGUMENTS
#include <sol.hpp>
#include <sol/sol.hpp>
#include <iostream>

View File

@ -9,5 +9,5 @@ this_state
This class is a transparent type that is meant to be gotten in functions to get the current lua state a bound function or usertype method is being called from. It does not actually retrieve anything from lua nor does it increment the argument count, making it "invisible" to function calls in lua and calls through ``std::function<...>`` and :doc:`sol::function<function>` on this type. It can be put in any position in the argument list of a function:
.. literalinclude:: ../../../examples/this_state.cpp
.. literalinclude:: ../../../examples/source/this_state.cpp
:linenos:

View File

@ -5,7 +5,7 @@ tie
`std::tie()`_ does not work well with :doc:`sol::function<function>`'s ``sol::function_result`` returns. Use ``sol::tie`` instead. Because they're both named `tie`, you'll need to be explicit when you use Sol's by naming it with the namespace (``sol::tie``), even with a ``using namespace sol;``. Here's an example:
.. literalinclude:: ../../../examples/tie.cpp
.. literalinclude:: ../../../examples/source/tie.cpp
:linenos:
.. _std::tie(): http://en.cppreference.com/w/cpp/utility/tuple/tie

View File

@ -199,7 +199,7 @@ runtime functions
You can add functions at runtime **to the whole class** (not to individual objects). Set a name under the metatable name you bound using ``new_usertype`` to an object. For example:
.. literalinclude:: ../../../examples/docs/runtime_extension.cpp
.. literalinclude:: ../../../examples/source/docs/runtime_extension.cpp
:caption: runtime_extension.cpp
:name: runtime-extension-example
:linenos:
@ -232,7 +232,7 @@ Register the base classes explicitly.
Always specify your bases if you plan to retrieve a base class using the Sol abstraction directly and not casting yourself.
.. literalinclude:: ../../../examples/docs/inheritance.cpp
.. literalinclude:: ../../../examples/source/docs/inheritance.cpp
:caption: inheritance.cpp
:name: inheritance-example
:linenos:

View File

@ -5,5 +5,5 @@ var
The sole purpose of this tagging type is to work with :doc:`usertypes<usertype>` to provide ``my_class.my_static_var`` access, and to also provide reference-based access as well.
.. literalinclude:: ../../../examples/usertype_var.cpp
.. literalinclude:: ../../../examples/source/usertype_var.cpp
:linenos:

View File

@ -11,15 +11,15 @@ This class is meant to represent every single argument at its current index and
``variadic_args`` also has ``begin()`` and ``end()`` functions that return (almost) random-acess iterators. These return a proxy type that can be implicitly converted to a type you want, much like the :doc:`table proxy type<proxy>`.
.. literalinclude:: ../../../examples/variadic_args.cpp
.. literalinclude:: ../../../examples/source/variadic_args.cpp
:linenos:
You can also "save" arguments and the like later, by stuffing them into a ``std::vector<sol::object>`` or something similar that serializes them into the registry. Below is an example of saving all of the arguments provided by ``sol::variadic_args`` in a lambda capture variable called ``args``.
.. literalinclude:: ../../../examples/variadic_args_storage.cpp
.. literalinclude:: ../../../examples/source/variadic_args_storage.cpp
:linenos:
Finally, note that you can use ``sol::variadic_args`` constructor to "offset"/"shift over" the arguments being viewed:
.. literalinclude:: ../../../examples/variadic_args_shifted.cpp
.. literalinclude:: ../../../examples/source/variadic_args_shifted.cpp
:linenos:

View File

@ -55,9 +55,9 @@ author = 'ThePhD'
# built documents.
#
# The short X.Y version.
version = '2.20'
version = '3.0'
# The full version, including alpha/beta/rc tags.
release = '2.20.5'
release = '3.0.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

View File

@ -217,7 +217,7 @@ a complete example
Here's a complete working example of it working for Lua 5.3 and Lua 5.2, and how you can retrieve out the container in all versions:
.. literalinclude:: ../../examples/containers.cpp
.. literalinclude:: ../../examples/source/containers.cpp
:name: containers-example
:linenos:
@ -236,7 +236,7 @@ There are also other ways to iterate over key/values, but they can be difficult
If you can't upgrade, use the "member" function ``my_container:pairs()`` in Lua to perform iteration:
.. literalinclude:: ../../examples/container_with_pairs.cpp
.. literalinclude:: ../../examples/source/container_with_pairs.cpp
:name: containers-pairs-example
:linenos:

View File

@ -9,7 +9,7 @@ If you turn this off, the default `at_panic`_ function :doc:`state<api/state>` s
To make this not be the case, you can set a panic function directly with ``lua_atpanic( lua, my_panic_function );`` or when you create the ``sol::state`` with ``sol::state lua(my_panic_function);``. Here's an example ``my_panic_function`` you can have that prints out its errors:
.. literalinclude:: ../../examples/docs/my_panic.cpp
.. literalinclude:: ../../examples/source/docs/my_panic.cpp
:caption: typical panic function
:name: typical-panic-function
:linenos:
@ -26,7 +26,7 @@ various sol and lua handlers
Lua comes with two kind of built-in handlers that sol provides easy opt-ins for. One is the ``panic`` function, as :ref:`demonstrated above<typical-panic-function>`. Another is the ``pcall`` error handler, used with :doc:`sol::protected_function<api/protected_function>`. It is any function that takes a single argument. The single argument is the error type being passed around: in Lua, this is a single string message:
.. literalinclude:: ../../examples/protected_functions.cpp
.. literalinclude:: ../../examples/source/protected_functions.cpp
:caption: regular error handling
:name: regular-error-handling
:linenos:
@ -34,7 +34,7 @@ Lua comes with two kind of built-in handlers that sol provides easy opt-ins for.
The other handler is specific to sol2. If you open a ``sol::state``, or open the default state handlers for your ``lua_State*`` (see :ref:`sol::state's automatic handlers<state-automatic-handlers>` for more details), there is a ``sol::exception_handler_function`` type. It allows you to register a function in the event that an exception happens that bubbles out of your functions. The function requires that you push 1 item onto the stack that will be used with a call to `lua_error`_
.. literalinclude:: ../../examples/exception_handler.cpp
.. literalinclude:: ../../examples/source/exception_handler.cpp
:caption: exception handling
:name: exception-handling
:linenos:

View File

@ -42,7 +42,7 @@ To be explicit about wanting a struct to be interpreted as a function, use ``my_
Furthermore, it is important to know that lambdas without a specified return type (and a non-const, non-reference-qualified ``auto``) will decay return values. To capture or return references explicitly, use ``decltype(auto)`` or specify the return type **exactly** as desired:
.. literalinclude:: ../../examples/docs/references_in_lambdas.cpp
.. literalinclude:: ../../examples/source/docs/references_in_lambdas.cpp
:name: refereces-in-lambdas-example
:linenos:

View File

@ -57,11 +57,11 @@ the basics:
The code below *and* more examples can be found in the `examples directory`_
.. literalinclude:: ../../examples/docs/simple_functions.cpp
.. literalinclude:: ../../examples/source/docs/simple_functions.cpp
:name: simple-functions-example
:linenos:
.. literalinclude:: ../../examples/docs/simple_structs.cpp
.. literalinclude:: ../../examples/source/docs/simple_structs.cpp
:name: simple-structs-example
:linenos:

View File

@ -34,6 +34,6 @@ You can mitigate some of the pressure of using coroutines and threading by using
Here's an example of explicit state transferring below:
.. literalinclude:: ../../examples/docs/state_transfer.cpp
.. literalinclude:: ../../examples/source/docs/state_transfer.cpp
:name: state-transfer
:linenos:

View File

@ -14,11 +14,11 @@ These are all the things. Use your browser's search to find things you want.
asserts / prerequisites
-----------------------
You'll need to ``#include <sol.hpp>``/``#include "sol.hpp"`` somewhere in your code. Sol is header-only, so you don't need to compile anything. However, **Lua must be compiled and available**. See the :doc:`getting started tutorial<getting-started>` for more details.
You'll need to ``#include <sol/sol.hpp>``/``#include "sol.hpp"`` somewhere in your code. Sol is header-only, so you don't need to compile anything. However, **Lua must be compiled and available**. See the :doc:`getting started tutorial<getting-started>` for more details.
The implementation for ``assert.hpp`` with ``c_assert`` looks like so:
.. literalinclude:: ../../../examples/assert.hpp
.. literalinclude:: ../../../examples/source/assert.hpp
:linenos:
:lines: 1-3, 19-
@ -27,7 +27,7 @@ This is the assert used in the quick code below.
opening a state
---------------
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/opening_a_state.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/opening_a_state.cpp
:linenos:
@ -39,7 +39,7 @@ using sol2 on a lua_State\*
For your system/game that already has Lua or uses an in-house or pre-rolled Lua system (LuaBridge, kaguya, Luwra, etc.), but you'd still like sol2 and nice things:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/opening_state_on_raw_lua.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/opening_state_on_raw_lua.cpp
:linenos:
.. _running-lua-code:
@ -47,13 +47,13 @@ For your system/game that already has Lua or uses an in-house or pre-rolled Lua
running lua code
----------------
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/running_lua_code.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/running_lua_code.cpp
:linenos:
:lines: 1-10, 16-26
To run Lua code but have an error handler in case things go wrong:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/running_lua_code.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/running_lua_code.cpp
:linenos:
:lines: 28-39,47-
@ -68,46 +68,49 @@ You can use the individual load and function call operator to load, check, and t
This is ONLY if you need some sort of fine-grained control: for 99% of cases, :ref:`running lua code<running-lua-code>` is preferred and avoids pitfalls in not understanding the difference between script/load and needing to run a chunk after loading it.
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/running_lua_code_low_level.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/running_lua_code_low_level.cpp
:linenos:
:lines: 1-10, 16-40, 47-49
You can also `develop custom loaders`_ that pull from things that are not strings or files.
set and get variables
---------------------
You can set/get everything using table-like syntax.
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/set_and_get_variables.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/set_and_get_variables.cpp
:linenos:
:lines: 1-19
Equivalent to loading lua values like so:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/set_and_get_variables.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/set_and_get_variables.cpp
:linenos:
:lines: 22-34
You can show they are equivalent:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/set_and_get_variables.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/set_and_get_variables.cpp
:linenos:
:lines: 36-44
Retrieve these variables using this syntax:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/set_and_get_variables.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/set_and_get_variables.cpp
:linenos:
:lines: 45-64
Retrieve Lua types using ``object`` and other ``sol::`` types.
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/set_and_get_variables.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/set_and_get_variables.cpp
:linenos:
:lines: 66-
You can erase things by setting it to ``nullptr`` or ``sol::lua_nil``.
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/set_and_get_variables_exists.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/set_and_get_variables_exists.cpp
:linenos:
Note that if its a :doc:`userdata/usertype<../api/usertype>` for a C++ type, the destructor will run only when the garbage collector deems it appropriate to destroy the memory. If you are relying on the destructor being run when its set to ``sol::lua_nil``, you're probably committing a mistake.
@ -117,13 +120,13 @@ tables
Tables can be manipulated using accessor-syntax. Note that :doc:`sol::state<../api/state>` is a table and all the methods shown here work with ``sol::state``, too.
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/tables_and_nesting.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/tables_and_nesting.cpp
:linenos:
:lines: 1-34
If you're going deep, be safe:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/tables_and_nesting.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/tables_and_nesting.cpp
:linenos:
:lines: 35-
@ -132,13 +135,13 @@ make tables
There are many ways to make a table. Here's an easy way for simple ones:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/make_tables.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/make_tables.cpp
:linenos:
:lines: 1-21
Equivalent Lua code, and check that they're equivalent:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/make_tables.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/make_tables.cpp
:linenos:
:lines: 22-
@ -152,7 +155,7 @@ functions
They're easy to use, from Lua and from C++:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/functions_easy.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/functions_easy.cpp
:linenos:
:lines: 1-
@ -160,13 +163,13 @@ If you need to protect against errors and parser problems and you're not ready t
You can bind member variables as functions too, as well as all KINDS of function-like things:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/functions_all.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/functions_all.cpp
:linenos:
:lines: 1-50
The lua code to call these things is:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/functions_all.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/functions_all.cpp
:linenos:
:lines: 51-
@ -178,7 +181,7 @@ self call
You can pass the ``self`` argument through C++ to emulate 'member function' calls in Lua.
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/self_call.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/self_call.cpp
:linenos:
:lines: 1-
@ -186,7 +189,7 @@ You can pass the ``self`` argument through C++ to emulate 'member function' call
multiple returns from lua
-------------------------
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/multiple_returns_from_lua.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/multiple_returns_from_lua.cpp
:linenos:
:lines: 1-
@ -194,7 +197,7 @@ multiple returns from lua
multiple returns to lua
-----------------------
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/multiple_returns_to_lua.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/multiple_returns_to_lua.cpp
:linenos:
:lines: 1-
@ -214,7 +217,7 @@ Everything that is not a:
Is set as a :doc:`userdata + usertype<../api/usertype>`.
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/userdata.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/userdata.cpp
:linenos:
:lines: 1-57,97-
@ -222,13 +225,13 @@ Is set as a :doc:`userdata + usertype<../api/usertype>`.
If you want it to refer to something, whose memory you know won't die in C++ while it is used/exists in Lua, do the following:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/userdata_memory_reference.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/userdata_memory_reference.cpp
:linenos:
:lines: 1-45
You can retrieve the userdata in the same way as everything else. Importantly, note that you can change the data of usertype variables and it will affect things in lua if you get a pointer or a reference:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/userdata_memory_reference.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/userdata_memory_reference.cpp
:linenos:
:lines: 46-
@ -246,7 +249,7 @@ namespacing
You can emulate namespacing by having a table and giving it the namespace names you want before registering enums or usertypes:
.. literalinclude:: ../../../examples/tutorials/quick_n_dirty/namespacing.cpp
.. literalinclude:: ../../../examples/source/tutorials/quick_n_dirty/namespacing.cpp
:linenos:
:lines: 1-
@ -271,6 +274,7 @@ Some more things you can do/read about:
* :doc:`stack references<../api/stack_reference>` to have zero-overhead Sol abstractions while not copying to the Lua registry.
* :doc:`resolve<../api/resolve>` overloads in case you have overloaded functions; a cleaner casting utility. You must use this to emulate default parameters.
.. _develop custom loaders: https://github.com/ThePhD/sol2/blob/develop/examples/custom_reader.cpp
.. _basic example: https://github.com/ThePhD/sol2/blob/develop/examples/usertype.cpp
.. _special functions example: https://github.com/ThePhD/sol2/blob/develop/examples/usertype_special_functions.cpp
.. _initializers example: https://github.com/ThePhD/sol2/blob/develop/examples/usertype_initializers.cpp

View File

@ -1,21 +1,21 @@
adding your own types
=====================
Sometimes, overriding Sol to make it handle certain ``struct``'s and ``class``'es as something other than just userdata is desirable. The way to do this is to take advantage of the 4 customization points for Sol. These are ``sol::lua_size<T>``, ``sol::stack::pusher<T, C>``, ``sol::stack::getter<T, C>``, ``sol::stack::checker<T, sol::type t, C>``.
Sometimes, overriding Sol to make it handle certain ``struct``'s and ``class``'es as something other than just userdata is desirable. The way to do this is to take advantage of the 4 customization points for Sol. These are ``sol::lua_size<T>``, ``sol::stack::unqualified_pusher<T, C>``, ``sol::stack::getter<T, C>``, ``sol::stack::checker<T, sol::type t, C>``.
These are template class/structs, so you'll override them using a technique C++ calls *class/struct specialization*. Below is an example of a struct that gets broken apart into 2 pieces when going in the C++ --> Lua direction, and then pulled back into a struct when going in the Lua --> C++:
.. literalinclude:: ../../../examples/customization.cpp
.. literalinclude:: ../../../examples/source/customization_multiple.cpp
:name: customization-overriding
:linenos:
:lines: 1-72
:lines: 1-52
This is the base formula that you can follow to extend to your own classes. Using it in the rest of the library should then be seamless:
.. literalinclude:: ../../../examples/customization.cpp
.. literalinclude:: ../../../examples/source/customization_multiple.cpp
:name: customization-overriding-use
:linenos:
:lines: 73-
:lines: 52-
And that's it!

View File

@ -93,7 +93,7 @@ To do this, you bind things using the ``new_usertype`` and ``set_usertype`` meth
.. code-block:: cpp
:caption: player_script.cpp
#include <sol.hpp>
#include <sol/sol.hpp>
int main () {
sol::state lua;

View File

@ -13,7 +13,7 @@ Given a C++ function, you can drop it into Sol in several equivalent ways, worki
:caption: Registering C++ functions
:name: writing-functions
#include <sol.hpp>
#include <sol/sol.hpp>
std::string my_function( int a, std::string b ) {
// Create a string with the letter 'D' "a" times,

View File

@ -16,7 +16,7 @@ When you're ready, try compiling this short snippet:
:caption: test.cpp: the first snippet
:name: the-first-snippet
#include <sol.hpp> // or #include "sol.hpp", whichever suits your needs
#include <sol/sol.hpp> // or #include "sol.hpp", whichever suits your needs
int main (int argc, char* argv[]) {
@ -47,7 +47,7 @@ The second line opens a single lua-provided library, "base". There are several o
:caption: test.cpp: the first snippet
:name: the-second-snippet
#include <sol.hpp>
#include <sol/sol.hpp>
int main (int argc, char* argv[]) {

View File

@ -8,28 +8,28 @@ reading
Given this lua file that gets loaded into sol:
.. literalinclude:: ../../../examples/tutorials/variables_demo.cpp
.. literalinclude:: ../../../examples/source/tutorials/variables_demo.cpp
:linenos:
:lines: 15-18
You can interact with the Lua Virtual Machine like so:
.. literalinclude:: ../../../examples/tutorials/variables_demo.cpp
.. literalinclude:: ../../../examples/source/tutorials/variables_demo.cpp
:linenos:
:lines: 1-10, 12-12, 20-24, 70-
From this example, you can see that there's many ways to pull out the varaibles you want. For example, to determine if a nested variable exists or not, you can use ``auto`` to capture the value of a ``table[key]`` lookup, and then use the ``.valid()`` method:
.. literalinclude:: ../../../examples/tutorials/variables_demo.cpp
.. literalinclude:: ../../../examples/source/tutorials/variables_demo.cpp
:linenos:
:lines: 1-10, 12-12, 34-43, 70-
This comes in handy when you want to check if a nested variable exists. You can also check if a toplevel variable is present or not by using ``sol::optional``, which also checks if A) the keys you're going into exist and B) the type you're trying to get is of a specific type:
.. literalinclude:: ../../../examples/tutorials/variables_demo.cpp
.. literalinclude:: ../../../examples/source/tutorials/variables_demo.cpp
:linenos:
:caption: optional lookup
:lines: 1-10, 12-12, 43-58, 70-
@ -37,7 +37,7 @@ This comes in handy when you want to check if a nested variable exists. You can
This can come in handy when, even in optimized or release modes, you still want the safety of checking. You can also use the `get_or` methods to, if a certain value may be present but you just want to default the value to something else:
.. literalinclude:: ../../../examples/tutorials/variables_demo.cpp
.. literalinclude:: ../../../examples/source/tutorials/variables_demo.cpp
:linenos:
:caption: optional lookup
:lines: 1-10, 12-12, 60-
@ -51,19 +51,19 @@ writing
Writing gets a lot simpler. Even without scripting a file or a string, you can read and write variables into lua as you please:
.. literalinclude:: ../../../examples/tutorials/write_variables_demo.cpp
.. literalinclude:: ../../../examples/source/tutorials/write_variables_demo.cpp
:linenos:
:name: writing-variables-demo
This example pretty much sums up what can be done. Note that the syntax ``lua["non_existing_key_1"] = 1`` will make that variable, but if you tunnel too deep without first creating a table, the Lua API will panic (e.g., ``lua["does_not_exist"]["b"] = 20`` will trigger a panic). You can also be lazy with reading / writing values:
.. literalinclude:: ../../../examples/tutorials/lazy_demo.cpp
.. literalinclude:: ../../../examples/source/tutorials/lazy_demo.cpp
:linenos:
Finally, it's possible to erase a reference/variable by setting it to ``nil``, using the constant ``sol::nil`` in C++:
.. literalinclude:: ../../../examples/tutorials/erase_demo.cpp
.. literalinclude:: ../../../examples/source/tutorials/erase_demo.cpp
:linenos:

View File

@ -1,7 +1,7 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -22,82 +22,110 @@
# # # sol2 Examples
if (DYNAMIC_LOADING_EXAMPLES)
if (SOL2_DYNAMIC_LOADING_EXAMPLES OR SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE OR SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE_GENERATED)
# # require_from_dll example
# just add the subdirectory
add_subdirectory(require_dll_example)
endif(DYNAMIC_LOADING_EXAMPLES)
endif()
if (INTEROP_EXAMPLES)
if (SOL2_INTEROP_EXAMPLES OR SOL2_INTEROP_EXAMPLES_SINGLE OR SOL2_INTEROP_EXAMPLES_SINGLE_GENERATED)
# # interop examples
add_subdirectory(interop/kaguya)
add_subdirectory(interop/tolua)
add_subdirectory(interop/LuaBridge)
add_subdirectory(interop/luwra)
endif(INTEROP_EXAMPLES)
endif()
# # Utility assert.hpp "library"
add_library(sol2_assert INTERFACE)
add_library(sol2::assert ALIAS sol2_assert)
set_target_properties(sol2_assert
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include")
if (SOL2_CI)
target_compile_definitions(sol2_assert
INTERFACE SOL2_CI)
endif()
# # single-source compilable examples
file(GLOB EXAMPLES_SRC *.cpp tutorials/quick_n_dirty/*.cpp docs/*.cpp)
file(GLOB EXAMPLES_SRC source/*.cpp source/tutorials/quick_n_dirty/*.cpp source/docs/*.cpp)
source_group(examples FILES ${EXAMPLES_SRC})
function (MAKE_EXAMPLE example_source_file is_single)
function (MAKE_EXAMPLE example_source_file example_suffix 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 (is_single)
set(example_name "${example_name}.single")
endif()
set(example_name "${example_name}${example_suffix}")
if (example_output_relative_dir_name STREQUAL "")
set(example_output_name "${example_name}")
else()
set(example_output_name "${example_output_relative_dir_name}.${example_name}")
endif()
add_executable(${example_name} ${example_source_file} assert.hpp)
add_executable(${example_name} ${example_source_file})
set_target_properties(${example_name}
PROPERTIES
OUTPUT_NAME "${example_output_name}")
if (is_single)
target_link_libraries(${example_name} sol2_single)
else()
target_link_libraries(${example_name} sol2)
endif()
target_compile_features(${example_name}
PRIVATE ${CXX_FEATURES})
target_link_libraries(${example_name} ${LUA_LIBRARIES})
if(CMAKE_DL_LIBS)
target_link_libraries(${example_name} ${CMAKE_DL_LIBS})
endif()
if (CI)
target_compile_definitions(${example_name}
PRIVATE SOL2_CI)
endif()
if (MSVC)
OUTPUT_NAME "${example_output_name}"
EXPORT_NAME sol2::${example_output_name})
if (MSVC)
target_compile_options(${example_name}
PRIVATE /std:c++latest /EHsc "$<$<CONFIG:Debug>:/MDd>"
"$<$<CONFIG:Release>:/MD>"
"$<$<CONFIG:RelWithDebInfo>:/MD>"
"$<$<CONFIG:MinSizeRel>:/MD>")
target_compile_definitions(${example_name}
PRIVATE UNICODE _UNICODE
_CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE )
else()
target_compile_options(${example_name}
PRIVATE -Wno-noexcept-type)
PRIVATE -std=c++1z
-ftemplate-backtrace-limit=0
-Wno-unknown-warning -Wno-unknown-warning-option
-Wall -Wpedantic -Werror -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(${example_name}
# PRIVATE -Wcomma)
endif()
endif()
if (TESTS_EXAMPLES)
if ((NOT is_single) OR (is_single AND TESTS_SINGLE))
add_test(NAME ${example_output_name} COMMAND ${example_name})
endif()
target_link_libraries(${example_name}
PRIVATE ${target_sol} ${LUA_LIBRARIES} sol2::assert)
if(CMAKE_DL_LIBS)
target_link_libraries(${example_name} PRIVATE ${CMAKE_DL_LIBS})
endif()
if (SOL2_TESTS_EXAMPLES)
add_test(NAME ${example_output_name} COMMAND ${example_name})
endif()
install(TARGETS ${example_name} RUNTIME DESTINATION bin)
endfunction(MAKE_EXAMPLE)
if (EXAMPLES)
if (SOL2_EXAMPLES)
foreach(example_source_file ${EXAMPLES_SRC})
MAKE_EXAMPLE(${example_source_file} FALSE)
MAKE_EXAMPLE(${example_source_file} "" sol2::sol2)
endforeach()
endif()
if (SOL2_EXAMPLES_SINGLE)
foreach(example_source_file ${EXAMPLES_SRC})
MAKE_EXAMPLE(${example_source_file} ".single" sol2::sol2_single)
endforeach()
endif()
if (SOL2_EXAMPLES_SINGLE_GENERATED)
foreach(example_source_file ${EXAMPLES_SRC})
MAKE_EXAMPLE(${example_source_file} ".single.generated" sol2::sol2_single_generated)
endforeach()
if (SOL2_SINGLE_FOUND AND EXAMPLES_SINGLE)
foreach(example_source_file ${EXAMPLES_SRC})
MAKE_EXAMPLE(${example_source_file} TRUE)
endforeach()
endif()
endif()

View File

@ -1,74 +0,0 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
// Something that can't be collided with
static const auto& script_key = "GlobalResource.MySpecialIdentifier123";
struct GlobalResource {
int value = 2;
};
// Customize sol2 to handle this type
namespace sol {
template <>
struct lua_type_of<GlobalResource*> : std::integral_constant<sol::type, sol::type::lightuserdata> {};
namespace stack {
template <>
struct checker<GlobalResource*> {
template <typename Handler>
static bool check(lua_State* L, int /*index*/, Handler&& handler, record& tracking) {
tracking.use(0);
// get the field from global storage
stack::get_field<true>(L, script_key);
// verify type
type t = static_cast<type>(lua_type(L, -1));
lua_pop(L, 1);
if (t != type::lightuserdata) {
handler(L, 0, type::lightuserdata, t, "global resource is not present");
return false;
}
return true;
}
};
template <>
struct getter<GlobalResource*> {
static GlobalResource* get(lua_State* L, int /*index*/, record& tracking) {
// retrieve the (light) userdata for this type
tracking.use(0); // not actually pulling anything off the stack
stack::get_field<true>(L, script_key);
GlobalResource* ls = static_cast<GlobalResource*>(lua_touserdata(L, -1));
lua_pop(L, 1); // clean up stack value returned by `get_field`
return ls;
};
};
template <>
struct pusher<GlobalResource*> {
static int push(lua_State* L, GlobalResource* ls) {
// push light userdata
return stack::push(L, make_light(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 being 2
lua.script("assert(f(1) == 3)");
return 0;
}

View File

@ -1,98 +0,0 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <iostream>
#include "assert.hpp"
struct two_things {
int a;
bool b;
};
namespace sol {
// First, the expected size
// Specialization of a struct
template <>
struct lua_size<two_things> : std::integral_constant<int, 2> {};
// Then, specialize the type
// this makes sure Sol can return it properly
template <>
struct lua_type_of<two_things> : std::integral_constant<sol::type, sol::type::poly> {};
// Now, specialize various stack structures
namespace stack {
template <>
struct checker<two_things> {
template <typename Handler>
static bool check(lua_State* L, int index, Handler&& handler, 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 = stack::check<int>(L, absolute_index, handler)
&& stack::check<bool>(L, absolute_index + 1, handler);
tracking.use(2);
return success;
}
};
template <>
struct getter<two_things> {
static two_things get(lua_State* L, int index, record& tracking) {
int absolute_index = lua_absindex(L, index);
// Get the first element
int a = stack::get<int>(L, absolute_index);
// Get the second element,
// in the +1 position from the first
bool b = stack::get<bool>(L, absolute_index + 1);
// we use 2 slots, each of the previous takes 1
tracking.use(2);
return two_things{ a, b };
}
};
template <>
struct pusher<two_things> {
static int push(lua_State* L, const two_things& things) {
int amount = stack::push(L, things.a);
// amount will be 1: int pushes 1 item
amount += 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 });
c_assert(things.a == 24);
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;
}

View File

@ -1,68 +0,0 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <iostream>
#include <iomanip>
#include "assert.hpp"
struct number_shim {
double num = 0;
};
namespace sol {
template <>
struct lua_type_of<number_shim> : std::integral_constant<sol::type, sol::type::poly> {};
namespace stack {
template <>
struct checker<number_shim> {
template <typename Handler>
static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
// check_usertype is a backdoor for directly checking sol2 usertypes
if (!check_usertype<number_shim>(L, index) && !stack::check<double>(L, index)) {
handler(L, index, type_of(L, index), type::userdata, "expected a number_shim or a number");
return false;
}
tracking.use(1);
return true;
}
};
template <>
struct getter<number_shim> {
static number_shim get(lua_State* L, int index, record& tracking) {
if (check_usertype<number_shim>(L, index)) {
number_shim& ns = get_usertype<number_shim>(L, index, tracking);
return ns;
}
number_shim ns{};
ns.num = stack::get<double>(L, index, tracking);
return ns;
}
};
} // namespace stack
} // namespace sol
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"];
c_assert(thingsf.num == 25);
c_assert(thingsg.num == 35);
return 0;
}

View File

@ -1,7 +1,7 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -24,27 +24,46 @@
find_package(LuaBridgeBuild)
function (make_luabridge_interop_example target_library is_single)
function (make_luabridge_interop_example target_library example_suffix)
set(example_name luabridge_interop_example)
if (is_single)
set(example_name "${example_name}.single")
endif(is_single)
add_executable(${example_name} LuaBridge.cpp)
target_link_libraries(${example_name} PUBLIC ${LUA_LIBRARIES} PRIVATE ${LUABRIDGE_LIBRARIES} ${target_library})
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} sol2::assert)
if (MSVC)
target_compile_options(${example_name}
PRIVATE /std:c++latest /EHsc "$<$<CONFIG:Debug>:/MDd>"
"$<$<CONFIG:Release>:/MD>"
"$<$<CONFIG:RelWithDebInfo>:/MD>"
"$<$<CONFIG:MinSizeRel>:/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 (CMAKE_DL_LIBS)
target_link_libraries(${example_name} PRIVATE ${CMAKE_DL_LIBS})
endif()
if (MSVC)
target_compile_options(${example_name} PRIVATE /W1)
else()
target_compile_options(${example_name} PRIVATE -w)
endif()
if (TESTS_EXAMPLES)
if (SOL2_TESTS_INTEROP_EXAMPLES)
add_test(NAME ${example_name} COMMAND ${example_name})
endif()
endfunction()
make_luabridge_interop_example(sol2 FALSE)
if (SOL2_SINGLE_FOUND AND INTEROP_EXAMPLES_SINGLE)
make_luabridge_interop_example(sol2_single TRUE)
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()
if (SOL2_INTEROP_EXAMPLES_SINGLE_GENERATED)
make_luabridge_interop_example(sol2::sol2_single_generated ".single.generated")
endif()

View File

@ -1,11 +1,11 @@
#define SOL_CHECK_ARGUMENTS 1
#define SOL_ENABLE_INTEROP 1 // MUST be defined to use interop features
#include <sol.hpp>
#include <sol/sol.hpp>
#include <LuaBridge/LuaBridge.h>
#include <iostream>
#include "../../assert.hpp"
#include <assert.hpp>
// LuaBridge,
// no longer maintained, by VinnieFalco:
@ -29,36 +29,27 @@ private:
int v_ = 50;
};
namespace sol {
namespace stack {
template <typename T>
struct userdata_checker<extensible<T>> {
template <typename Handler>
static bool check(lua_State* L, int relindex, type index_type, Handler&& handler, 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<T>(L, index, true);
return corrected != nullptr;
}
};
template <typename T>
struct userdata_getter<extensible<T>> {
static std::pair<bool, T*> get(lua_State* L, int relindex, void* unadjusted_pointer, record& tracking) {
(void)unadjusted_pointer;
int index = lua_absindex(L, relindex);
if (!userdata_checker<extensible<T>>::check(L, index, type::userdata, no_panic, tracking)) {
return { false, nullptr };
}
T* corrected = luabridge::Userdata::get<T>(L, index, true);
return { true, corrected };
}
};
template <typename T, typename Handler>
inline bool sol_lua_interop_check(sol::types<T>, 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<T>(L, index, true);
return corrected != nullptr;
}
template <typename T>
inline std::pair<bool, T*> sol_lua_interop_get(sol::types<T> 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<T>(L, index, true);
return { true, corrected };
}
} // namespace sol::stack
void register_sol_stuff(lua_State* L) {
// grab raw state and put into state_view

View File

@ -1,7 +1,7 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -24,27 +24,45 @@
find_package(KaguyaBuild)
function (make_kaguya_interop_example target_library is_single)
function (make_kaguya_interop_example target_library example_suffix)
set(example_name kaguya_interop_example)
if (is_single)
set(example_name "${example_name}.single")
endif(is_single)
add_executable(${example_name} kaguya.cpp)
target_link_libraries(${example_name} PUBLIC ${LUA_LIBRARIES} PRIVATE ${KAGUYA_LIBRARIES} ${target_library})
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} sol2::assert)
if (MSVC)
target_compile_options(${example_name}
PRIVATE /W1 /std:c++latest /EHsc "$<$<CONFIG:Debug>:/MDd>"
"$<$<CONFIG:Release>:/MD>"
"$<$<CONFIG:RelWithDebInfo>:/MD>"
"$<$<CONFIG:MinSizeRel>:/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 (CMAKE_DL_LIBS)
target_link_libraries(${example_name} PRIVATE ${CMAKE_DL_LIBS})
endif()
if (MSVC)
target_compile_options(${example_name} PRIVATE /W1)
else()
target_compile_options(${example_name} PRIVATE -w)
endif()
if (TESTS_INTEROP_EXAMPLES)
if (SOL2_TESTS_INTEROP_EXAMPLES)
add_test(NAME ${example_name} COMMAND ${example_name})
endif()
endfunction()
make_kaguya_interop_example(sol2 FALSE)
if (SOL2_SINGLE_FOUND AND INTEROP_EXAMPLES_SINGLE)
make_kaguya_interop_example(sol2_single TRUE)
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()
if (SOL2_INTEROP_EXAMPLES_SINGLE_GENERATED)
make_kaguya_interop_example(sol2::sol2_single_generated ".single.generated")
endif()

View File

@ -2,10 +2,10 @@
#define SOL_CHECK_ARGUMENTS 1
#define SOL_ENABLE_INTEROP 1 // MUST be defined to use interop features
#include <sol.hpp>
#include <sol/sol.hpp>
#include <iostream>
#include "../../assert.hpp"
#include <assert.hpp>
// kaguya code lifted from README.md,
// written by satoren:
@ -39,46 +39,37 @@ private:
int v_;
};
namespace sol {
namespace stack {
template <typename T>
struct userdata_checker<extensible<T>> {
template <typename Handler>
static bool check(lua_State* L, int relindex, type index_type, Handler&& handler, 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 <typename T>
struct userdata_getter<extensible<T>> {
static std::pair<bool, T*> get(lua_State* L, int relindex, void* unadjusted_pointer, 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<T*>(base->get()) };
}
};
template <typename T, typename Handler>
inline bool sol_lua_interop_check(sol::types<T>, 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 <typename T>
inline std::pair<bool, T*> 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
// 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<T*>(base->get()) };
}
} // namespace sol::stack
void register_sol_stuff(lua_State* L) {
// grab raw state and put into state_view

View File

@ -1,7 +1,7 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -24,27 +24,45 @@
find_package(LuwraBuild)
function (make_luwra_interop_example target_library is_single)
function (make_luwra_interop_example target_library example_suffix)
set(example_name luwra_interop_example)
if (is_single)
set(example_name "${example_name}.single")
endif(is_single)
add_executable(${example_name} luwra.cpp)
target_link_libraries(${example_name} PUBLIC ${LUA_LIBRARIES} PRIVATE ${LUWRA_LIBRARIES} ${target_library})
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} sol2::assert)
if (MSVC)
target_compile_options(${example_name}
PRIVATE /std:c++latest /EHsc "$<$<CONFIG:Debug>:/MDd>"
"$<$<CONFIG:Release>:/MD>"
"$<$<CONFIG:RelWithDebInfo>:/MD>"
"$<$<CONFIG:MinSizeRel>:/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 (CMAKE_DL_LIBS)
target_link_libraries(${example_name} PRIVATE ${CMAKE_DL_LIBS})
endif()
if (MSVC)
target_compile_options(${example_name} PRIVATE /W1)
else()
target_compile_options(${example_name} PRIVATE -w)
endif()
if (TESTS_EXAMPLES)
if (SOL2_TESTS_INTEROP_EXAMPLES)
add_test(NAME ${example_name} COMMAND ${example_name})
endif()
endfunction()
make_luwra_interop_example(sol2 FALSE)
if (SOL2_SINGLE_FOUND AND INTEROP_EXAMPLES_SINGLE)
make_luwra_interop_example(sol2_single TRUE)
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()
if (SOL2_INTEROP_EXAMPLES_SINGLE_GENERATED)
make_luwra_interop_example(sol2::sol2_single_generated ".single.generated")
endif()

View File

@ -1,11 +1,11 @@
#define SOL_CHECK_ARGUMENTS 1
#define SOL_ENABLE_INTEROP 1 // MUST be defined to use interop features
#include <sol.hpp>
#include <sol/sol.hpp>
#include <luwra.hpp>
#include <iostream>
#include "../../assert.hpp"
#include <assert.hpp>
// luwra,
// another C++ wrapper library:
@ -35,42 +35,33 @@ private:
int v_;
};
namespace sol {
namespace stack {
template <typename T>
struct userdata_checker<extensible<T>> {
template <typename Handler>
static bool check(lua_State* L, int relindex, type index_type, Handler&& handler, 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<T>::name.c_str());
bool is_correct_type = lua_rawequal(L, -2, -1) == 1;
lua_pop(L, 2);
return is_correct_type;
}
return false;
}
};
template <typename T>
struct userdata_getter<extensible<T>> {
static std::pair<bool, T*> get(lua_State* L, int relindex, void* unadjusted_pointer, 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 (!userdata_checker<extensible<T>>::check(L, index, type::userdata, no_panic, tracking)) {
return { false, nullptr };
}
return { true, static_cast<T*>(unadjusted_pointer) };
}
};
template <typename T, typename Handler>
inline bool sol_lua_interop_check(sol::types<T>, 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<T>::name.c_str());
bool is_correct_type = lua_rawequal(L, -2, -1) == 1;
lua_pop(L, 2);
return is_correct_type;
}
return false;
}
template <typename T>
inline std::pair<bool, T*> sol_lua_interop_get(sol::types<T> 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<T*>(unadjusted_pointer) };
}
} // namespace sol::stack
void register_sol_stuff(lua_State* L) {
// grab raw state and put into state_view

View File

@ -1,7 +1,7 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -24,27 +24,45 @@
find_package(ToLuappBuild REQUIRED)
function(make_tolua_interop_example target_library is_single)
function(make_tolua_interop_example target_library example_suffix)
set(example_name tolua_interop_example)
if (is_single)
set(example_name "${example_name}.single")
set(example_name "${example_name}${example_suffix}")
add_executable(${example_name} source/tolua.cpp)
target_link_libraries(${example_name}
PRIVATE sol2::assert
${LUA_LIBRARIES} ${TOLUAPP_LIBRARIES} ${target_library})
if (MSVC)
target_compile_options(${example_name}
PRIVATE /std:c++latest /EHsc "$<$<CONFIG:Debug>:/MDd>"
"$<$<CONFIG:Release>:/MD>"
"$<$<CONFIG:RelWithDebInfo>:/MD>"
"$<$<CONFIG:MinSizeRel>:/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()
add_executable(${example_name} tolua.cpp)
target_link_libraries(${example_name} PUBLIC ${LUA_LIBRARIES} PRIVATE ${TOLUAPP_LIBRARIES} ${target_library})
if (CMAKE_DL_LIBS)
target_link_libraries(${example_name} PRIVATE ${CMAKE_DL_LIBS})
endif()
if (MSVC)
target_compile_options(${example_name} PRIVATE /W1)
else()
target_compile_options(${example_name} PRIVATE -w)
endif()
if (TESTS_EXAMPLES)
if (SOL2_TESTS_INTEROP_EXAMPLES)
add_test(NAME ${example_name} COMMAND ${example_name})
endif()
endfunction()
make_tolua_interop_example(sol2 FALSE)
if (SOL2_SINGLE_FOUND AND INTEROP_EXAMPLES_SINGLE)
make_tolua_interop_example(sol2_single TRUE)
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()
if (SOL2_INTEROP_EXAMPLES_SINGLE_GENERATED)
make_tolua_interop_example(sol2::sol2_single_generated ".single.generated")
endif()

View File

@ -1,6 +1,6 @@
#define SOL_CHECK_ARGUMENTS 1
#define SOL_ENABLE_INTEROP 1 // MUST be defined to use interop features
#include <sol.hpp>
#include <sol/sol.hpp>
#include "Player.h"
#include <tolua++.h>
@ -9,30 +9,37 @@
#include "tolua_Player.h"
#include <iostream>
#include "../../assert.hpp"
#include <assert.hpp>
// tolua code lifted from some blog, if the link dies
// I don't know where else you're gonna find the reference,
// http://usefulgamedev.weebly.com/tolua-example.html
namespace sol {
namespace stack {
template <typename T>
struct userdata_checker<extensible<T>> {
template <typename Handler>
static bool check(lua_State* L, int relindex, type index_type, Handler&& handler, 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<T>();
tolua_Error tolua_err;
return tolua_isusertype(L, index, name.c_str(), 0, &tolua_err);
}
};
/* 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 <typename T, typename Handler>
inline bool sol_lua_interop_check(sol::types<T>, 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<T>();
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;
}
} // namespace sol::stack
void register_sol_stuff(lua_State* L) {
// grab raw state and put into state_view

View File

@ -1,7 +1,7 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2018 Rapptz, ThePhD, and contributors
# Copyright (c) 2013-2019 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
@ -24,84 +24,122 @@
# # Reusable function to call for single target
# # Also hides variables from directory/global scope
function(make_require_from_dll_example target_lib is_single)
function(make_require_from_dll_example target_lib example_lib_name_suffix)
# define sources
set(my_object_sources my_object.cpp my_object.hpp my_object_api.hpp)
set(require_from_dll_sources require_from_dll.cpp)
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)
if (is_single)
set(example_lib_name "${example_lib_name}.single")
set(example_name "${example_name}.single")
endif()
# is the lua library a shared or static library?
list(GET LUA_LIBRARIES 0 lua_lib_target)
get_target_property(lua_lib_type ${lua_lib_target} TYPE)
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}")
target_compile_features(${example_lib_name} PRIVATE ${CXX_FEATURES})
target_compile_definitions(${example_lib_name} PUBLIC MY_OBJECT_DLL PRIVATE MY_OBJECT_BUILD)
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} sol2::assert)
target_include_directories(${example_lib_name}
PUBLIC "${LUA_INCLUDE_DIRS}")
if (MSVC)
target_compile_options(${example_lib_name}
PRIVATE /std:c++latest /EHsc "$<$<CONFIG:Debug>:/MDd>"
"$<$<CONFIG:Release>:/MD>"
"$<$<CONFIG:RelWithDebInfo>:/MD>"
"$<$<CONFIG:MinSizeRel>:/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()
if(CMAKE_DL_LIBS)
target_link_libraries(${example_lib_name} PUBLIC ${CMAKE_DL_LIBS})
endif()
if (CI)
target_compile_definitions(${example_lib_name} PRIVATE SOL2_CI)
endif()
if (NOT MSVC)
target_compile_options(${example_lib_name} PRIVATE -Wno-noexcept-type)
if (lua_lib_type MATCHES "STATIC")
# ensure that the whole archive is input into the linker
# this ensure static builds are included properly
target_link_libraries(${example_lib_name} PRIVATE
-Wl,-whole-archive ${LUA_LIBRARIES} -Wl,-no-whole-archive)
else()
target_link_libraries(${example_lib_name} PRIVATE ${LUA_LIBRARIES})
endif()
else()
target_link_libraries(${example_lib_name} PRIVATE ${LUA_LIBRARIES})
endif()
if (IS_X86)
target_compile_options(${example_lib_name} BEFORE PRIVATE -m32)
endif()
target_link_libraries(${example_lib_name} PRIVATE ${target_lib})
target_include_directories(${example_lib_name} PUBLIC "${LUA_INCLUDE_DIRS}")
# add executable target that represents require_from_dll program
add_executable(${example_name} ${require_from_dll_sources})
target_compile_features(${example_name} PRIVATE ${CXX_FEATURES})
target_link_libraries(${example_name}
PRIVATE my_object ${LUA_LIBRARIES} ${target_lib})
target_include_directories(${example_name}
PRIVATE ${LUA_INCLUDE_DIRS})
if (MSVC)
target_compile_options(${example_name}
PRIVATE /std:c++latest /EHsc "$<$<CONFIG:Debug>:/MDd>"
"$<$<CONFIG:Release>:/MD>"
"$<$<CONFIG:RelWithDebInfo>:/MD>"
"$<$<CONFIG:MinSizeRel>:/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(CMAKE_DL_LIBS)
target_link_libraries(${example_name} PRIVATE ${CMAKE_DL_LIBS})
endif()
if (CI)
target_compile_definitions(${example_name} PRIVATE SOL2_CI)
endif()
if (NOT MSVC)
target_compile_options(${example_name} PRIVATE -Wno-noexcept-type)
endif()
target_link_libraries(${example_name} PRIVATE my_object ${target_lib})
# avoid multiply defined references due to linking in the same static library
# twice over, and get "multiple definition" errors during linking
if (NOT lua_lib_type MATCHES "STATIC")
target_link_libraries(${example_name} PRIVATE ${LUA_LIBRARIES})
endif()
target_include_directories(${example_name} PRIVATE ${LUA_INCLUDE_DIRS})
if (TESTS_DYNAMIC_LOADING_EXAMPLES)
if ((NOT is_single) OR (is_single AND DYNAMIC_LOADING_EXAMPLES_SINGLE))
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()
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()
make_require_from_dll_example(sol2 FALSE)
if (SOL2_SINGLE_FOUND AND DYNAMIC_LOADING_EXAMPLES_SINGLE)
make_require_from_dll_example(sol2_single TRUE)
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()
if (SOL2_DYNAMIC_LOADING_EXAMPLES_SINGLE_GENERATED)
make_require_from_dll_example(sol2::sol2_single_generated ".single.generated")
endif()

View File

@ -1,6 +1,6 @@
#pragma once
#include "my_object_api.hpp"
#include <my_object/my_object_api.hpp>
// forward declare as a C struct
// so a pointer to lua_State can be part of a signature

View File

@ -1,7 +1,7 @@
#include "my_object.hpp"
#include <my_object/my_object.hpp>
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
namespace my_object {
@ -10,8 +10,7 @@ namespace my_object {
sol::table module = lua.create_table();
module.new_usertype<test>("test",
sol::constructors<test(), test(int)>(),
"value", &test::value
);
"value", &test::value);
return module;
}

View File

@ -1,8 +1,8 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include "my_object.hpp"
#include "../assert.hpp"
#include <my_object/my_object.hpp>
#include <assert.hpp>
#include <iostream>

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include <iostream>
#include "assert.hpp"
@ -44,4 +44,6 @@ int main() {
std::cout << "result2: " << result2 << std::endl;
std::cout << "result3: " << result3 << std::endl;
std::cout << std::endl;
return 0;
}

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include <iostream>
#include <vector>

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include "assert.hpp"

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include <iostream>
#include "assert.hpp"

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include "assert.hpp"

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include "assert.hpp"

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include <iostream>

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include "assert.hpp"
#include <string>

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include <vector>
#include <numeric>

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include "assert.hpp"

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include <vector>
#include <iostream>

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include <vector>
#include <map>
@ -14,7 +14,7 @@
// where someone wants to handle a nested table
void demo(sol::nested<std::map<std::string, std::vector<std::string>>> src) {
std::cout << "demo, sol::nested<...>" << std::endl;
const auto& listmap = src.source;
const auto& listmap = src.value();
c_assert(listmap.size() == 2);
for (const auto& kvp : listmap) {
const std::vector<std::string>& strings = kvp.second;
@ -38,11 +38,11 @@ void demo(sol::nested<std::map<std::string, std::vector<std::string>>> src) {
void demo_explicit (sol::as_table_t<std::map<std::string, sol::as_table_t<std::vector<std::string>>>> 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.source;
const auto& listmap = src.value();
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<std::string>& strings = kvp.second.source;
const std::vector<std::string>& strings = kvp.second.value();
c_assert(strings.size() == 3);
std::cout << "\t" << kvp.first << " = ";
for (const auto& s : strings) {

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include <string>
#include <iostream>

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
#include "assert.hpp"
#include <iostream>

View File

@ -0,0 +1,95 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol/sol.hpp>
#include "assert.hpp"
#include <iostream>
#include <exception>
#include <fstream>
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<custom_reader*>(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
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;
}

View File

@ -0,0 +1,54 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol/sol.hpp>
#include <iostream>
#include <iomanip>
#include "assert.hpp"
struct number_shim {
double num = 0;
};
template <typename Handler>
bool sol_lua_check(sol::types<number_shim>, 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<number_shim>(L, index)
&& !sol::stack::check<double>(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<number_shim>, lua_State* L, int index, sol::stack::record& tracking) {
if (sol::stack::check_usertype<number_shim>(L, index)) {
number_shim& ns = sol::stack::get_usertype<number_shim>(L, index, tracking);
return ns;
}
number_shim ns{};
ns.num = sol::stack::get<double>(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"];
c_assert(thingsf.num == 25);
c_assert(thingsg.num == 35);
return 0;
}

View File

@ -0,0 +1,63 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol/sol.hpp>
// Something that can't be collided with
static const auto& script_key = "GlobalResource.MySpecialIdentifier123";
struct GlobalResource {
int value = 2;
};
template <typename Handler>
bool sol_lua_check(sol::types<GlobalResource*>, 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<true>(L, script_key);
// verify type
sol::type t = static_cast<sol::type>(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<GlobalResource*>, 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<true>(L, script_key);
GlobalResource* ls = static_cast<GlobalResource*>(lua_touserdata(L, -1));
// clean up stack value returned by `get_field`
lua_pop(L, 1);
return ls;
}
int sol_lua_push(sol::types<GlobalResource*>, lua_State* L, GlobalResource* ls) {
// push light userdata
return sol::stack::push(L, static_cast<void*>(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;
}

View File

@ -0,0 +1,70 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol/sol.hpp>
#include <iostream>
#include "assert.hpp"
struct two_things {
int a;
bool b;
};
template <typename Handler>
bool sol_lua_check(sol::types<two_things>, 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<int>(L, absolute_index, handler) && sol::stack::check<bool>(L, absolute_index + 1, handler);
tracking.use(2);
return success;
}
two_things sol_lua_get(sol::types<two_things>, 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<int>(L, absolute_index);
// Get the second element,
// in the +1 position from the first
bool b = sol::stack::get<bool>(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(sol::types<two_things>, 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 });
c_assert(things.a == 24);
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;
}

View File

@ -1,10 +1,10 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
int main () {
struct callable {
int operator()( int a, bool b ) {
return a + b ? 10 : 20;
return a + (b ? 10 : 20);
}
};

View File

@ -1,5 +1,5 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <sol/sol.hpp>
int main () {
class B {

Some files were not shown because too many files have changed in this diff Show More