add all examples for all interop types

Implements #578
This commit is contained in:
ThePhD 2018-02-10 16:24:17 -05:00
parent af7b46864a
commit 1d0683a53e
41 changed files with 925 additions and 163 deletions

View File

@ -0,0 +1,35 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2017 Rapptz, ThePhD, and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
if(_common_core_included)
return()
endif(_common_core_included)
set(_common_core_included true)
# # Prepend function (is there an equivalent in CMake somewhere...?)
function(prepend var prefix)
set(l "")
foreach(f ${ARGN})
list(APPEND l "${prefix}${f}")
endforeach(f)
SET(${var} "${l}" PARENT_SCOPE)
ENDFUNCTION(prepend)

View File

@ -0,0 +1,74 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2017 Rapptz, ThePhD, and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
include(ExternalProject)
# # Base variables
set(kaguya_version 1.3.2)
set(kaguya_lib kaguya_lib_${kaguya_version})
# # Useful locations
set(kaguya_build_toplevel "${CMAKE_BINARY_DIR}/vendor/kaguya_${kaguya_version}")
set(kaguya_include_dirs "${kaguya_build_toplevel}/include")
# # kaguya library sources
set(kaguya_sources kaguya/kaguya.hpp)
prepend(kaguya_sources "${kaguya_build_toplevel}/include/" ${kaguya_sources})
# # External project to get sources
ExternalProject_Add(KAGUYA_BUILD_SOURCE
BUILD_IN_SOURCE TRUE
BUILD_ALWAYS FALSE
# # Use Git to get what we need
GIT_SHALLOW TRUE
GIT_SUBMODULES ""
GIT_REPOSITORY https://github.com/satoren/kaguya.git
PREFIX ${kaguya_build_toplevel}
SOURCE_DIR ${kaguya_build_toplevel}
DOWNLOAD_DIR ${kaguya_build_toplevel}
TMP_DIR "${kaguya_build_toplevel}-tmp"
STAMP_DIR "${kaguya_build_toplevel}-stamp"
INSTALL_DIR "${kaguya_build_toplevel}/local"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
BUILD_BYPRODUCTS "${kaguya_sources}")
add_library(${kaguya_lib} INTERFACE)
add_dependencies(${kaguya_lib} KAGUYA_BUILD_SOURCE)
target_include_directories(${kaguya_lib} INTERFACE ${kaguya_include_dirs})
target_link_libraries(${kaguya_lib} INTERFACE ${LUA_LIBRARIES})
if (NOT MSVC)
target_compile_options(${kaguya_lib} INTERFACE
-Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter)
endif()
set(KAGUYABUILD_FOUND TRUE)
set(KAGUYA_LIBRARIES ${kaguya_lib})
set(KAGUYA_INCLUDE_DIRS ${kaguya_include_dirs})
FIND_PACKAGE_HANDLE_STANDARD_ARGS(KaguyaBuild
FOUND_VAR KAGUYABUILD_FOUND
REQUIRED_VARS KAGUYA_LIBRARIES KAGUYA_INCLUDE_DIRS
VERSION_VAR kaguya_version)

View File

@ -0,0 +1,74 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2017 Rapptz, ThePhD, and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
include(ExternalProject)
# # Base variables
set(luabridge_version 1.0.2)
set(luabridge_lib luabridge_lib_${luabridge_version})
# # Useful locations
set(luabridge_build_toplevel "${CMAKE_BINARY_DIR}/vendor/luabridge_${luabridge_version}")
set(luabridge_include_dirs "${luabridge_build_toplevel}/Source")
# # luabridge library sources
set(luabridge_sources LuaBridge/LuaBridge.h)
prepend(luabridge_sources "${luabridge_build_toplevel}/Source/" ${luabridge_sources})
# # External project to get sources
ExternalProject_Add(LUABRIDGE_BUILD_SOURCE
BUILD_IN_SOURCE TRUE
BUILD_ALWAYS FALSE
# # Use Git to get what we need
GIT_SHALLOW TRUE
GIT_SUBMODULES ""
GIT_REPOSITORY https://github.com/vinniefalco/LuaBridge.git
PREFIX ${luabridge_build_toplevel}
SOURCE_DIR ${luabridge_build_toplevel}
DOWNLOAD_DIR ${luabridge_build_toplevel}
TMP_DIR "${luabridge_build_toplevel}-tmp"
STAMP_DIR "${luabridge_build_toplevel}-stamp"
INSTALL_DIR "${luabridge_build_toplevel}/local"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
BUILD_BYPRODUCTS "${luabridge_sources}")
add_library(${luabridge_lib} INTERFACE)
add_dependencies(${luabridge_lib} LUABRIDGE_BUILD_SOURCE)
target_include_directories(${luabridge_lib} INTERFACE ${luabridge_include_dirs})
target_link_libraries(${luabridge_lib} INTERFACE ${LUA_LIBRARIES})
if (NOT MSVC)
target_compile_options(${luabridge_lib} INTERFACE
-Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter)
endif()
set(LUABRIDGEBUILD_FOUND TRUE)
set(LUABRIDGE_LIBRARIES ${luabridge_lib})
set(LUABRIDGE_INCLUDE_DIRS ${luabridge_include_dirs})
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuabridgeBuild
FOUND_VAR LUABRIDGEBUILD_FOUND
REQUIRED_VARS LUABRIDGE_LIBRARIES LUABRIDGE_INCLUDE_DIRS
VERSION_VAR luabridge_version)

View File

@ -243,9 +243,9 @@ if (LUA_JIT_GIT_COMMIT OR LUA_JIT_PULL_LATEST)
endif()
ExternalProject_Add(LUA_JIT
BUILD_IN_SOURCE TRUE
BUILD_ALWAYS TRUE
BUILD_ALWAYS FALSE
# LuaJIT does not offer a TLS/SSL port
# TLS_VERIFY TRUE
TLS_VERIFY FALSE
PREFIX "${LUA_BUILD_TOPLEVEL}"
SOURCE_DIR "${LUA_BUILD_TOPLEVEL}"
DOWNLOAD_DIR "${LUA_BUILD_TOPLEVEL}"

View File

@ -28,6 +28,8 @@ set(_lua_vanilla_build_included true)
# import necessary standard modules
include(ExternalProject)
# import other modules
include(Common/Core)
# Latest versions for specific sub-versions of Lua
set(LUA_VANILLA_5.1_LATEST_VERSION 5.1.5)
@ -103,15 +105,6 @@ set(LUA_VANILLA_SHA1_1.1 67209701eec5cc633e829d023fbff62d5d6c8e5e)
set(LUA_VANILLA_MD5_1.0 96e8399fc508d128badd8ac3aa8f2119)
set(LUA_VANILLA_SHA1_1.0 6a82d2ae7ce9ad98c7b4824a325b91522c0d6ebb)
# # Prepend function (is there an equivalent in CMake somewhere...?)
function(prepend var prefix)
set(l "")
foreach(f ${ARGN})
list(APPEND l "${prefix}${f}")
endforeach(f)
SET(${var} "${l}" PARENT_SCOPE)
ENDFUNCTION(prepend)
# Clean up some variables
if (LUA_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$")
# probably okay!
@ -220,7 +213,7 @@ prepend(LUA_VANILLA_LUAC_SOURCES "${LUA_VANILLA_SOURCE_DIR}/" ${LUA_VANILLA_LUAC
ExternalProject_Add(LUA_VANILLA
BUILD_IN_SOURCE TRUE
BUILD_ALWAYS TRUE
BUILD_ALWAYS FALSE
TLS_VERIFY TRUE
PREFIX ${LUA_BUILD_TOPLEVEL}
SOURCE_DIR ${LUA_BUILD_TOPLEVEL}

View File

@ -0,0 +1,73 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2017 Rapptz, ThePhD, and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
include(ExternalProject)
# # Base variables
set(luwra_version 0.5.0)
set(luwra_lib luwra_lib_${luwra_version})
# # Useful locations
set(luwra_build_toplevel "${CMAKE_BINARY_DIR}/vendor/luwra_${luwra_version}")
set(luwra_include_dirs "${luwra_build_toplevel}/lib")
# # luwra library sources
set(luwra_sources luwra.hpp)
prepend(luwra_sources "${luwra_build_toplevel}/lib/" ${luwra_sources})
# # External project to get sources
ExternalProject_Add(LUWRA_BUILD_SOURCE
BUILD_IN_SOURCE TRUE
BUILD_ALWAYS FALSE
# # Use Git to get what we need
GIT_SHALLOW TRUE
#GIT_TAG e513907fc8c2d59ebd91cd5992eddf54f7e23e21
GIT_REPOSITORY https://github.com/vapourismo/luwra.git
PREFIX ${luwra_build_toplevel}
SOURCE_DIR ${luwra_build_toplevel}
DOWNLOAD_DIR ${luwra_build_toplevel}
TMP_DIR "${luwra_build_toplevel}-tmp"
STAMP_DIR "${luwra_build_toplevel}-stamp"
INSTALL_DIR "${luwra_build_toplevel}/local"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
BUILD_BYPRODUCTS "${luwra_sources}")
add_library(${luwra_lib} INTERFACE)
add_dependencies(${luwra_lib} LUWRA_BUILD_SOURCE)
target_include_directories(${luwra_lib} INTERFACE ${luwra_include_dirs})
target_link_libraries(${luwra_lib} INTERFACE ${LUA_LIBRARIES})
if (NOT MSVC)
target_compile_options(${luwra_lib} INTERFACE
-Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter)
endif()
set(LUWRABUILD_FOUND TRUE)
set(LUWRA_LIBRARIES ${luwra_lib})
set(LUWRA_INCLUDE_DIRS ${luwra_include_dirs})
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuwraBuild
FOUND_VAR LUWRABUILD_FOUND
REQUIRED_VARS LUWRA_LIBRARIES LUWRA_INCLUDE_DIRS
VERSION_VAR luwra_version)

View File

@ -0,0 +1,88 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2017 Rapptz, ThePhD, and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# # Standard CMake Libraries
include(ExternalProject)
include(FindPackageHandleStandardArgs)
# # Base variables
set(toluapp_version 1.0.93)
# # Useful locations
set(toluapp_build_toplevel "${CMAKE_BINARY_DIR}/vendor/toluapp_${toluapp_version}")
set(toluapp_include_dirs "${toluapp_build_toplevel}/include")
# # ToLua library sources
set(toluapp_sources tolua_event.c tolua_event.h tolua_is.c tolua_map.c tolua_push.c tolua_to.c)
prepend(toluapp_sources "${toluapp_build_toplevel}/src/lib/" ${toluapp_sources})
list(APPEND toluapp_sources "${toluapp_build_toplevel}/include/tolua++.h")
# # External project to get sources
ExternalProject_Add(TOLUAPP_BUILD_SOURCE
BUILD_IN_SOURCE TRUE
BUILD_ALWAYS FALSE
# # Use Git to get what we need
#GIT_SUBMODULES ""
GIT_SHALLOW TRUE
GIT_REPOSITORY https://github.com/waltervn/toluapp.git
PREFIX ${toluapp_build_toplevel}
SOURCE_DIR ${toluapp_build_toplevel}
DOWNLOAD_DIR ${toluapp_build_toplevel}
TMP_DIR "${toluapp_build_toplevel}-tmp"
STAMP_DIR "${toluapp_build_toplevel}-stamp"
INSTALL_DIR "${toluapp_build_toplevel}/local"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
BUILD_BYPRODUCTS "${toluapp_sources}")
set(toluapp_lib toluapp_lib_5.2.4)
add_library(${toluapp_lib} SHARED ${toluapp_sources})
add_dependencies(${toluapp_lib} TOLUAPP_BUILD_SOURCE)
set_target_properties(${toluapp_lib} PROPERTIES
OUTPUT_NAME toluapp-${toluapp_version}
POSITION_INDEPENDENT_CODE TRUE)
target_include_directories(${toluapp_lib}
PUBLIC ${toluapp_include_dirs})
target_link_libraries(${toluapp_lib} ${LUA_LIBRARIES})
if (MSVC)
target_compile_options(${toluapp_lib}
PRIVATE /W1)
target_compile_definitions(${toluapp_lib}
PRIVATE TOLUA_API=__declspec(dllexport))
else()
target_compile_options(${toluapp_lib}
PRIVATE -w
INTERFACE -Wno-noexcept-type
PUBLIC -Wno-ignored-qualifiers -Wno-unused-parameter)
endif()
# # Variables required by ToLuaBuild
set(TOLUAPP_LIBRARIES ${toluapp_lib})
set(TOLUAPP_INCLUDE_DIRS ${toluapp_include_dirs})
set(TOLUAPPBUILD_FOUND TRUE)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ToLuappBuild
FOUND_VAR TOLUAPPBUILD_FOUND
REQUIRED_VARS TOLUAPP_LIBRARIES TOLUAPP_INCLUDE_DIRS
VERSION_VAR toluapp_version)

View File

@ -27,10 +27,10 @@
add_subdirectory(require_dll_example)
# # interop examples
#add_subdirectory(interop/kaguya)
#add_subdirectory(interop/tolua)
#add_subdirectory(interop/LuaBridge)
#add_subdirectory(interop/luwra)
add_subdirectory(interop/kaguya)
add_subdirectory(interop/tolua)
add_subdirectory(interop/LuaBridge)
add_subdirectory(interop/luwra)
# # single-source compilable examples

View File

@ -1,11 +1,6 @@
#ifndef EXAMPLES_ASSERT_HPP
#define EXAMPLES_ASSERT_HPP
#ifndef NDEBUG
#include <exception>
#include <iostream>
#include <cstdlib>
#ifdef SOL2_CI
struct pre_main {
pre_main() {
@ -16,6 +11,11 @@ struct pre_main {
} pm;
#endif // Prevent lockup when doing Continuous Integration
#ifndef NDEBUG
#include <exception>
#include <iostream>
#include <cstdlib>
# define m_assert(condition, message) \
do { \
if (! (condition)) { \

View File

@ -0,0 +1,45 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2017 Rapptz, ThePhD, and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# # # sol2 interop Examples - luabridge
find_package(LuaBridgeBuild)
function (make_luabridge_interop_example target_library is_single)
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})
if (NOT MSVC)
target_compile_options(${example_name} PRIVATE -Wno-noexcept-type -Wignored-qualifiers -Wunused-parameter)
endif()
if (TESTS_EXAMPLES)
add_test(NAME ${example_name} COMMAND ${example_name})
endif()
endfunction()
make_luabridge_interop_example(sol2 FALSE)
if (TESTS_SINGLE)
make_luabridge_interop_example(sol2_single TRUE)
endif()

View File

@ -5,7 +5,7 @@
#include <LuaBridge/LuaBridge.h>
#include <iostream>
#include "../assert.hpp"
#include "../../assert.hpp"
// LuaBridge,
// no longer maintained, by VinnieFalco:
@ -53,7 +53,6 @@ namespace stack {
if (!userdata_checker<extensible<T>>::check(L, index, type::userdata, no_panic, tracking)) {
return { false, nullptr };
}
tracking.use(1);
T* corrected = luabridge::Userdata::get<T>(L, index, true);
return { true, corrected };
}
@ -68,10 +67,13 @@ void register_sol_stuff(lua_State* L) {
// bind and set up your things: everything is entirely self-contained
lua["f"] = sol::overload(
[](A& from_luabridge) {
std::cout << "calling 1-argument version with luabridge-created A {" << from_luabridge.value() << "}" << std::endl;
std::cout << "calling 1-argument version with luabridge-created A { " << from_luabridge.value() << " }" << std::endl;
c_assert(from_luabridge.value() == 24);
},
[](A& from_luabridge, int second_arg) {
std::cout << "calling 2-argument version with luabridge-created A {" << from_luabridge.value() << "} and integer argument of " << second_arg << std::endl;
std::cout << "calling 2-argument version with luabridge-created A { " << from_luabridge.value() << " } and integer argument of " << second_arg << std::endl;
c_assert(from_luabridge.value() == 24);
c_assert(second_arg == 5);
});
}
@ -95,7 +97,8 @@ int main(int, char* []) {
std::unique_ptr<lua_State, closer> state(luaL_newstate());
lua_State* L = state.get();
luaL_openlibs(L);
luabridge::getGlobalNamespace(L)
.beginNamespace("test")
.beginClass<A>("A")

View File

@ -0,0 +1,45 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2017 Rapptz, ThePhD, and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# # # sol2 interop Examples - kaguya
find_package(KaguyaBuild)
function (make_kaguya_interop_example target_library is_single)
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})
if (NOT MSVC)
target_compile_options(${example_name} PRIVATE -Wno-noexcept-type)
endif()
if (TESTS_EXAMPLES)
add_test(NAME ${example_name} COMMAND ${example_name})
endif()
endfunction()
make_kaguya_interop_example(sol2 FALSE)
if (TESTS_SINGLE)
make_kaguya_interop_example(sol2_single TRUE)
endif()

View File

@ -5,7 +5,7 @@
#include <kaguya/kaguya.hpp>
#include <iostream>
#include "../assert.hpp"
#include "../../assert.hpp"
// kaguya code lifted from README.md,
// written by satoren:
@ -87,10 +87,13 @@ void register_sol_stuff(lua_State* L) {
// bind and set up your things: everything is entirely self-contained
lua["f"] = sol::overload(
[](ABC& from_kaguya) {
std::cout << "calling 1-argument version with kaguya-created ABC {" << from_kaguya.value() << "}" << std::endl;
std::cout << "calling 1-argument version with kaguya-created ABC { " << from_kaguya.value() << " }" << std::endl;
c_assert(from_kaguya.value() == 24);
},
[](ABC& from_kaguya, int second_arg) {
std::cout << "calling 2-argument version with kaguya-created ABC {" << from_kaguya.value() << "} and integer argument of " << second_arg << std::endl;
std::cout << "calling 2-argument version with kaguya-created ABC { " << from_kaguya.value() << " } and integer argument of " << second_arg << std::endl;
c_assert(from_kaguya.value() == 24);
c_assert(second_arg == 5);
});
}

View File

@ -0,0 +1,45 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2017 Rapptz, ThePhD, and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# # # sol2 interop Examples - luwra
find_package(LuwraBuild)
function (make_luwra_interop_example target_library is_single)
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})
if (NOT MSVC)
target_compile_options(${example_name} PRIVATE -Wno-noexcept-type)
endif()
if (TESTS_EXAMPLES)
add_test(NAME ${example_name} COMMAND ${example_name})
endif()
endfunction()
make_luwra_interop_example(sol2 FALSE)
if (TESTS_SINGLE)
make_luwra_interop_example(sol2_single TRUE)
endif()

View File

@ -5,7 +5,7 @@
#include <luwra.hpp>
#include <iostream>
#include "../assert.hpp"
#include "../../assert.hpp"
// luwra,
// another C++ wrapper library:
@ -66,7 +66,6 @@ namespace stack {
if (!userdata_checker<extensible<T>>::check(L, index, type::userdata, no_panic, tracking)) {
return { false, nullptr };
}
tracking.use(1);
return { true, static_cast<T*>(unadjusted_pointer) };
}
};
@ -80,10 +79,13 @@ void register_sol_stuff(lua_State* L) {
// bind and set up your things: everything is entirely self-contained
lua["f"] = sol::overload(
[](ABC& from_luwra) {
std::cout << "calling 1-argument version with luwra-created ABC {" << from_luwra.value() << "}" << std::endl;
std::cout << "calling 1-argument version with luwra-created ABC { " << from_luwra.value() << " }" << std::endl;
c_assert(from_luwra.value() == 24);
},
[](ABC& from_luwra, int second_arg) {
std::cout << "calling 2-argument version with luwra-created ABC {" << from_luwra.value() << "} and integer argument of " << second_arg << std::endl;
std::cout << "calling 2-argument version with luwra-created ABC { " << from_luwra.value() << " } and integer argument of " << second_arg << std::endl;
c_assert(from_luwra.value() == 24);
c_assert(second_arg == 5);
});
}

View File

@ -0,0 +1,45 @@
# # # # sol2
# The MIT License (MIT)
#
# Copyright (c) 2013-2017 Rapptz, ThePhD, and contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# # # sol2 interop Examples - tolua
find_package(ToLuappBuild REQUIRED)
function(make_tolua_interop_example target_library is_single)
set(example_name tolua_interop_example)
if (is_single)
set(example_name "${example_name}.single")
endif()
add_executable(${example_name} tolua.cpp)
target_link_libraries(${example_name} PUBLIC ${LUA_LIBRARIES} PRIVATE ${TOLUAPP_LIBRARIES} ${target_library})
if (NOT MSVC)
target_compile_options(${example_name} PRIVATE -Wno-noexcept-type -Wno-unused-function -Wno-pedantic)
endif()
if (TESTS_EXAMPLES)
add_test(NAME ${example_name} COMMAND ${example_name})
endif()
endfunction()
make_tolua_interop_example(sol2 FALSE)
if (TESTS_SINGLE)
make_tolua_interop_example(sol2_single TRUE)
endif()

View File

@ -10,7 +10,7 @@ public:
: m_health(0) {
}
void setHealth(int health) {
m_health - health;
m_health = health;
}
int getHealth() const {
return m_health;

View File

@ -3,13 +3,13 @@
#include <sol.hpp>
#include "Player.h"
// pick or replace the includes
// with whatever generated file you've created
#include <tolua++.h>
// pick or replace the include
// with whatever generated file you've created
#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,
@ -20,8 +20,8 @@ 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) {
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;
@ -41,10 +41,13 @@ void register_sol_stuff(lua_State* L) {
// bind and set up your things: everything is entirely self-contained
lua["f"] = sol::overload(
[](Player& from_tolua) {
std::cout << "calling 1-argument version with tolua-created Player { health:" << from_tolua.getHealth() << "}" << std::endl;
std::cout << "calling 1-argument version with tolua-created Player { health:" << from_tolua.getHealth() << " }" << std::endl;
c_assert(from_tolua.getHealth() == 4);
},
[](Player& from_tolua, int second_arg) {
std::cout << "calling 2-argument version with tolua-created Player { health: " << from_tolua.getHealth() << "} and integer argument of " << second_arg << std::endl;
std::cout << "calling 2-argument version with tolua-created Player { health: " << from_tolua.getHealth() << " } and integer argument of " << second_arg << std::endl;
c_assert(from_tolua.getHealth() == 4);
c_assert(second_arg == 5);
});
}

View File

@ -0,0 +1,217 @@
/*
** Lua binding: Player
** Generated automatically by tolua++-1.0.93-lua53 on Sat Feb 10 08:48:53 2018.
*/
#ifndef __cplusplus
#include "stdlib.h"
#endif
#include "string.h"
#include "tolua++.h"
/* Exported function */
TOLUA_API int tolua_Player_open (lua_State* tolua_S);
#include "Player.h"
/* function to release collected object via destructor */
#ifdef __cplusplus
static int tolua_collect_Player (lua_State* tolua_S)
{
Player* self = (Player*) tolua_tousertype(tolua_S,1,0);
Mtolua_delete(self);
return 0;
}
#endif
/* function to register type */
static void tolua_reg_types (lua_State* tolua_S)
{
tolua_usertype(tolua_S,"Player");
}
/* method: new of class Player */
#ifndef TOLUA_DISABLE_tolua_Player_Player_new00
static int tolua_Player_Player_new00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertable(tolua_S,1,"Player",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
{
Player* tolua_ret = (Player*) Mtolua_new((Player)());
tolua_pushusertype(tolua_S,(void*)tolua_ret,"Player");
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: new_local of class Player */
#ifndef TOLUA_DISABLE_tolua_Player_Player_new00_local
static int tolua_Player_Player_new00_local(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertable(tolua_S,1,"Player",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
{
Player* tolua_ret = (Player*) Mtolua_new((Player)());
tolua_pushusertype(tolua_S,(void*)tolua_ret,"Player");
tolua_register_gc(tolua_S,lua_gettop(tolua_S));
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'new'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: delete of class Player */
#ifndef TOLUA_DISABLE_tolua_Player_Player_delete00
static int tolua_Player_Player_delete00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"Player",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Player* self = (Player*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'delete'", NULL);
#endif
Mtolua_delete(self);
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'delete'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: setHealth of class Player */
#ifndef TOLUA_DISABLE_tolua_Player_Player_setHealth00
static int tolua_Player_Player_setHealth00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"Player",0,&tolua_err) ||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Player* self = (Player*) tolua_tousertype(tolua_S,1,0);
int _health = ((int) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'setHealth'", NULL);
#endif
{
self->setHealth(_health);
}
}
return 0;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'setHealth'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* method: getHealth of class Player */
#ifndef TOLUA_DISABLE_tolua_Player_Player_getHealth00
static int tolua_Player_Player_getHealth00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"Player",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Player* self = (Player*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'getHealth'", NULL);
#endif
{
int tolua_ret = (int) self->getHealth();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'getHealth'.",&tolua_err);
return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE
/* Open function */
TOLUA_API int tolua_Player_open (lua_State* tolua_S)
{
tolua_open(tolua_S);
tolua_reg_types(tolua_S);
tolua_module(tolua_S,NULL,0);
tolua_beginmodule(tolua_S,NULL);
#ifdef __cplusplus
tolua_cclass(tolua_S,"Player","Player","",tolua_collect_Player);
#else
tolua_cclass(tolua_S,"Player","Player","",NULL);
#endif
tolua_beginmodule(tolua_S,"Player");
tolua_function(tolua_S,"new",tolua_Player_Player_new00);
tolua_function(tolua_S,"new_local",tolua_Player_Player_new00_local);
tolua_function(tolua_S,".call",tolua_Player_Player_new00_local);
tolua_function(tolua_S,"delete",tolua_Player_Player_delete00);
tolua_function(tolua_S,"setHealth",tolua_Player_Player_setHealth00);
tolua_function(tolua_S,"getHealth",tolua_Player_Player_getHealth00);
tolua_endmodule(tolua_S);
tolua_endmodule(tolua_S);
return 1;
}
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
TOLUA_API int luaopen_Player (lua_State* tolua_S) {
return tolua_Player_open(tolua_S);
};
#endif

View File

@ -0,0 +1,42 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include <iostream>
int main() {
std::cout << "=== override-able member functions ===" << std::endl;
struct thingy {
sol::function paint;
thingy(sol::this_state L) : paint(sol::make_reference<sol::function>(L.lua_state(), &thingy::default_paint)) {
}
void default_paint() {
std::cout << "p" << std::endl;
}
};
sol::state lua;
lua.open_libraries(sol::lib::base);
lua.new_usertype<thingy>("thingy",
sol::constructors<thingy(sol::this_state)>(),
"paint", &thingy::paint);
sol::string_view code = R"(
obj = thingy.new()
obj:paint()
obj.paint = function (self) print("g") end
obj:paint()
function obj:paint () print("s") end
obj:paint()
)";
lua.safe_script(code);
std::cout << std::endl;
return 0;
}

View File

@ -26,7 +26,7 @@
# # Also hides variables from directory/global scope
function(make_require_from_dll_example target_lib is_single)
# define sources
set(my_object_sources my_object.cpp my_object.hpp my_object_api.hpp assert.hpp)
set(my_object_sources my_object.cpp my_object.hpp my_object_api.hpp)
set(require_from_dll_sources require_from_dll.cpp)
# define names

View File

@ -1,41 +0,0 @@
#ifndef EXAMPLES_ASSERT_HPP
#define EXAMPLES_ASSERT_HPP
#ifndef NDEBUG
#include <exception>
#include <iostream>
#include <cstdlib>
#ifdef SOL2_CI
struct pre_main {
pre_main() {
#ifdef _MSC_VER
_set_abort_behavior(0, _WRITE_ABORT_MSG);
#endif
}
} pm;
#endif // Prevent lockup when doing Continuous Integration
# define m_assert(condition, message) \
do { \
if (! (condition)) { \
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
<< " line " << __LINE__ << ": " << message << std::endl; \
std::terminate(); \
} \
} while (false)
# define c_assert(condition) \
do { \
if (! (condition)) { \
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
<< " line " << __LINE__ << std::endl; \
std::terminate(); \
} \
} while (false)
#else
# define m_assert(condition, message) do { if (false) { (void)(condition); (void)sizeof(message); } } while (false)
# define c_assert(condition) do { if (false) { (void)(condition); } } while (false)
#endif
#endif // EXAMPLES_ASSERT_HPP

View File

@ -1,41 +0,0 @@
#ifndef EXAMPLES_ASSERT_HPP
#define EXAMPLES_ASSERT_HPP
#ifndef NDEBUG
#include <exception>
#include <iostream>
#include <cstdlib>
#ifdef SOL2_CI
struct pre_main {
pre_main() {
#ifdef _MSC_VER
_set_abort_behavior(0, _WRITE_ABORT_MSG);
#endif
}
} pm;
#endif // Prevent lockup when doing Continuous Integration
# define m_assert(condition, message) \
do { \
if (! (condition)) { \
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
<< " line " << __LINE__ << ": " << message << std::endl; \
std::terminate(); \
} \
} while (false)
# define c_assert(condition) \
do { \
if (! (condition)) { \
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
<< " line " << __LINE__ << std::endl; \
std::terminate(); \
} \
} while (false)
#else
# define m_assert(condition, message) do { if (false) { (void)(condition); (void)sizeof(message); } } while (false)
# define c_assert(condition) do { if (false) { (void)(condition); } } while (false)
#endif
#endif // EXAMPLES_ASSERT_HPP

View File

@ -1,7 +1,7 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "assert.hpp"
#include "../../assert.hpp"
#include <iostream>
void some_function() {

View File

@ -1,7 +1,7 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "assert.hpp"
#include "../../assert.hpp"
int main(int, char*[]) {
sol::state lua;

View File

@ -1,7 +1,7 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "assert.hpp"
#include "../../assert.hpp"
int main(int, char* []) {
sol::state lua;

View File

@ -1,7 +1,7 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "assert.hpp"
#include "../../assert.hpp"
int main(int, char* []) {
sol::state lua;

View File

@ -1,7 +1,7 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "assert.hpp"
#include "../../assert.hpp"
int main(int, char* []) {
sol::state lua;

View File

@ -2,7 +2,7 @@
#include <sol.hpp>
#include <iostream>
#include "assert.hpp"
#include "../../assert.hpp"
int main() {
std::cout << "=== namespacing example ===" << std::endl;

View File

@ -2,7 +2,7 @@
#include <sol.hpp>
#include <iostream>
#include "assert.hpp"
#include "../../assert.hpp"
int main(int, char*[]) {
std::cout << "=== opening a state example ===" << std::endl;

View File

@ -3,7 +3,7 @@
#include <fstream>
#include <iostream>
#include "assert.hpp"
#include "../../assert.hpp"
int main(int, char*[]) {
std::cout << "=== running lua code example ===" << std::endl;

View File

@ -4,7 +4,7 @@
#include <fstream>
#include <iostream>
#include <cstdio>
#include "assert.hpp"
#include "../../assert.hpp"
int main(int, char*[]) {
std::cout << "=== running lua code (low level) example ===" << std::endl;

View File

@ -1,7 +1,7 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "assert.hpp"
#include "../../assert.hpp"
int main(int, char*[]) {
sol::state lua;

View File

@ -1,7 +1,7 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "assert.hpp"
#include "../../assert.hpp"
int main(int, char*[]) {
sol::state lua;

View File

@ -1,7 +1,7 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "assert.hpp"
#include "../../assert.hpp"
int main(int, char*[]) {

View File

@ -1,7 +1,7 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "assert.hpp"
#include "../../assert.hpp"
#include <iostream>
struct Doge {

View File

@ -1,7 +1,7 @@
#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "assert.hpp"
#include "../../assert.hpp"
#include <iostream>
struct Doge {

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script.
// Generated 2018-02-05 00:55:01.557255 UTC
// This header was generated with sol v2.19.0 (revision c9980bf)
// Generated 2018-02-10 21:24:10.124152 UTC
// This header was generated with sol v2.19.0 (revision af7b468)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP
@ -5097,7 +5097,7 @@ namespace sol {
};
inline const std::string& to_string(call_status c) {
static const std::array<std::string, 8> names{ {
static const std::array<std::string, 10> names{ {
"ok",
"yielded",
"runtime",
@ -5106,6 +5106,8 @@ namespace sol {
"gc",
"syntax",
"file",
"CRITICAL_EXCEPTION_FAILURE",
"CRITICAL_INDETERMINATE_STATE_FAILURE"
} };
switch (c) {
case call_status::ok:
@ -5125,16 +5127,37 @@ namespace sol {
case call_status::file:
return names[7];
}
return names[0];
if (static_cast<std::ptrdiff_t>(c) == -1) {
// One of the many cases where a critical exception error has occurred
return names[8];
}
return names[9];
}
inline bool is_indeterminate_call_failure(call_status c) {
switch (c) {
case call_status::ok:
case call_status::yielded:
case call_status::runtime:
case call_status::memory:
case call_status::handler:
case call_status::gc:
case call_status::syntax:
case call_status::file:
return false;
}
return true;
}
inline const std::string& to_string(load_status c) {
static const std::array<std::string, 8> names{ {
static const std::array<std::string, 7> names{ {
"ok",
"memory",
"gc",
"syntax",
"file",
"CRITICAL_EXCEPTION_FAILURE",
"CRITICAL_INDETERMINATE_STATE_FAILURE"
} };
switch (c) {
case load_status::ok:
@ -5148,7 +5171,11 @@ namespace sol {
case load_status::file:
return names[4];
}
return names[0];
if (static_cast<int>(c) == -1) {
// One of the many cases where a critical exception error has occurred
return names[5];
}
return names[6];
}
inline const std::string& to_string(load_mode c) {
@ -8334,31 +8361,31 @@ namespace sol {
er.error = error_code::ok;
if (codepoint <= unicode_detail::last_1byte_value) {
er.code_units_size = 1;
er.code_units = std::array<char, 4>{ static_cast<char>(codepoint) };
er.code_units = std::array<char, 4>{ { static_cast<char>(codepoint) } };
}
else if (codepoint <= unicode_detail::last_2byte_value) {
er.code_units_size = 2;
er.code_units = std::array<char, 4>{
er.code_units = std::array<char, 4>{{
static_cast<char>(0xC0 | ((codepoint & 0x7C0) >> 6)),
static_cast<char>(0x80 | (codepoint & 0x3F)),
};
}};
}
else if (codepoint <= unicode_detail::last_3byte_value) {
er.code_units_size = 3;
er.code_units = std::array<char, 4>{
er.code_units = std::array<char, 4>{{
static_cast<char>(0xE0 | ((codepoint & 0xF000) >> 12)),
static_cast<char>(0x80 | ((codepoint & 0xFC0) >> 6)),
static_cast<char>(0x80 | (codepoint & 0x3F)),
};
}};
}
else {
er.code_units_size = 4;
er.code_units = std::array<char, 4>{
er.code_units = std::array<char, 4>{ {
static_cast<char>(0xF0 | ((codepoint & 0x1C0000) >> 18)),
static_cast<char>(0x80 | ((codepoint & 0x3F000) >> 12)),
static_cast<char>(0x80 | ((codepoint & 0xFC0) >> 6)),
static_cast<char>(0x80 | (codepoint & 0x3F)),
};
} };
}
return er;
}
@ -8375,10 +8402,10 @@ namespace sol {
auto normal = codepoint - unicode_detail::normalizing_value;
auto lead = unicode_detail::first_lead_surrogate + ((normal & unicode_detail::lead_surrogate_bitmask) >> unicode_detail::lead_shifted_bits);
auto trail = unicode_detail::first_trail_surrogate + (normal & unicode_detail::trail_surrogate_bitmask);
er.code_units = std::array<char16_t, 4>{
er.code_units = std::array<char16_t, 4>{ {
static_cast<char16_t>(lead),
static_cast<char16_t>(trail)
};
} };
er.code_units_size = 2;
er.error = error_code::ok;
}
@ -9155,7 +9182,6 @@ namespace stack {
template <typename T>
struct getter<detail::as_value_tag<T>> {
static T* get_no_lua_nil(lua_State* L, int index, record& tracking) {
tracking.use(1);
void* memory = lua_touserdata(L, index);
#ifdef SOL_ENABLE_INTEROP
userdata_getter<extensible<T>> ug;
@ -9165,6 +9191,7 @@ namespace stack {
return ugr.second;
}
#endif // interop extensibility
tracking.use(1);
void* rawdata = detail::align_usertype_pointer(memory);
void** pudata = static_cast<void**>(rawdata);
void* udata = *pudata;
@ -17056,7 +17083,7 @@ namespace sol {
namespace sol {
namespace usertype_detail {
#ifdef SOL_USE_BOOST
template <typename K, typename V, typename H = std::hash<K>, typename E = std::equal_to<>>
template <typename K, typename V, typename H = boost::hash<K>, typename E = std::equal_to<>>
using map_t = boost::unordered_map<K, V, H, E>;
#else
template <typename K, typename V, typename H = std::hash<K>, typename E = std::equal_to<>>
@ -19607,18 +19634,48 @@ namespace sol {
type t = type_of(L, result.stack_index());
std::string err = "sol: ";
err += to_string(result.status());
err += " error:";
err += " error";
#ifndef SOL_NO_EXCEPTIONS
std::exception_ptr eptr = std::current_exception();
if (eptr) {
err += " with a ";
try {
std::rethrow_exception(eptr);
}
catch (const std::exception& ex) {
err += "std::exception -- ";
err.append(ex.what());
}
catch (const std::string& message) {
err += "thrown message -- ";
err.append(message);
}
catch (const char* message) {
err += "thrown message -- ";
err.append(message);
}
catch (...) {
err.append("thrown but unknown type, cannot serialize into error message");
}
}
#endif // serialize exception information if possible
if (t == type::string) {
err += " ";
err += ": ";
string_view serr = stack::get<string_view>(L, result.stack_index());
err.append(serr.data(), serr.size());
}
#ifdef SOL_NO_EXCEPTIONS
// replacing information of stack error into pfr
if (t != type::none) {
lua_pop(L, 1);
int target = result.stack_index();
if (result.pop_count() > 0) {
stack::remove(L, target, result.pop_count());
}
int pushed = stack::push(L, err);
int top = lua_gettop(L);
int towards = top - target;
if (towards != 0) {
lua_rotate(L, top, towards);
}
stack::push(L, err);
#else
// just throw our error
throw error(detail::direct_error, err);

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script.
// Generated 2018-02-05 00:55:01.877796 UTC
// This header was generated with sol v2.19.0 (revision c9980bf)
// Generated 2018-02-10 21:24:10.349205 UTC
// This header was generated with sol v2.19.0 (revision af7b468)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP

View File

@ -667,7 +667,6 @@ namespace stack {
template <typename T>
struct getter<detail::as_value_tag<T>> {
static T* get_no_lua_nil(lua_State* L, int index, record& tracking) {
tracking.use(1);
void* memory = lua_touserdata(L, index);
#ifdef SOL_ENABLE_INTEROP
userdata_getter<extensible<T>> ug;
@ -677,6 +676,7 @@ namespace stack {
return ugr.second;
}
#endif // interop extensibility
tracking.use(1);
void* rawdata = detail::align_usertype_pointer(memory);
void** pudata = static_cast<void**>(rawdata);
void* udata = *pudata;