├── .clang-format ├── .gitignore ├── .gitmodules ├── .style.yapf ├── .vscode ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── CMakeLists.txt ├── CMakeSettings.json ├── README.md ├── benchmark_results ├── base derived.png ├── c function through lua in c.png ├── c function.png ├── implicit inheritance.png ├── lua function in c.png ├── lua_bindings_shootout.json ├── member function call.png ├── multi return lua.png ├── multi return.png ├── optional failure.png ├── optional half failure.png ├── optional success.png ├── return userdata.png ├── stateful function object.png ├── table chained get.png ├── table chained set.png ├── table get.png ├── table global string get.png ├── table global string set.png ├── table set.png ├── userdata variable access large.png ├── userdata variable access last.png └── userdata variable access.png ├── cmake └── Modules │ ├── Common │ └── core.cmake │ ├── FindKaguyaDev.cmake │ ├── FindLuaApippDev.cmake │ ├── FindLuaBridgeDev.cmake │ ├── FindLuaDev.cmake │ ├── FindLuaDev │ ├── LuaJIT.cmake │ └── LuaVanilla.cmake │ ├── FindLuaIntfDev.cmake │ ├── FindLuabindDev.cmake │ ├── FindLuacppInterface.cmake │ ├── FindLuawrapper.cmake │ ├── FindLuwraDev.cmake │ ├── FindOOLuaDev.cmake │ ├── FindSeleneDev.cmake │ └── FindToLuappDev.cmake ├── source ├── benchmark.hpp ├── kaguya.cpp ├── lbs_lib.hpp ├── lbs_lua.hpp ├── lua-api-pp.cpp ├── lua-intf.cpp ├── lua_bindings_shootout.cpp ├── luabind.cpp ├── luabridge.cpp ├── luacppinterface.cpp ├── luawrapper.cpp ├── luwra.cpp ├── old_sol.cpp ├── oolua.cpp ├── plain_c.cpp ├── selene.cpp ├── sol2.cpp ├── sol3.cpp ├── swig.cpp ├── swig_lib.gen.hpp ├── swig_lib.i ├── toluapp.cpp ├── toluapp_lib.gen.hpp └── toluapp_lib.pkg ├── tools └── generate_graphs.py └── vendor ├── old_sol └── old_sol │ └── old_sol.hpp └── sol2 └── sol2 ├── sol2.hpp └── sol2_forward.hpp /.clang-format: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright (c) 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | --- 24 | BasedOnStyle: WebKit 25 | IndentWidth: 5 26 | TabWidth: 5 27 | ContinuationIndentWidth: 5 28 | UseTab: Always 29 | 30 | # Namespaces 31 | NamespaceIndentation: All 32 | CompactNamespaces: true 33 | FixNamespaceComments: true 34 | 35 | # Overall Alignment 36 | ColumnLimit: 0 37 | AlignAfterOpenBracket: DontAlign # uses ContinuationIndentWidth for this instead 38 | AccessModifierOffset: -5 # do not push public: or private: around 39 | #AlignConsecutiveAssignments: true # affects more than what's expected: do not use 40 | #AlignConsecutiveDeclarations: true # affects more than what's expected: do not use 41 | 42 | # Type Alignment 43 | DerivePointerAlignment: false 44 | PointerAlignment: Left 45 | AlwaysBreakTemplateDeclarations: true 46 | AlwaysBreakBeforeMultilineStrings: true 47 | 48 | # Comments 49 | AlignTrailingComments: true 50 | ReflowComments: true 51 | 52 | # Macros 53 | AlignEscapedNewlines: Left 54 | #IndentPPDirectives: None 55 | 56 | # Functions 57 | AllowShortFunctionsOnASingleLine: None 58 | AlwaysBreakAfterReturnType: None 59 | BreakConstructorInitializers: BeforeComma 60 | ConstructorInitializerIndentWidth: 0 61 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 62 | BinPackArguments: true 63 | BinPackParameters: true 64 | 65 | # Classes 66 | BreakBeforeInheritanceComma: false 67 | 68 | # Braces 69 | Cpp11BracedListStyle: false 70 | BreakBeforeBraces: Custom 71 | BraceWrapping: 72 | AfterEnum: false 73 | AfterStruct: false 74 | AfterControlStatement: false 75 | AfterClass: false 76 | AfterNamespace: false 77 | AfterStruct: false 78 | AfterUnion: false 79 | BeforeElse: true 80 | BeforeCatch: true 81 | IndentBraces: false 82 | SplitEmptyFunction: false 83 | SplitEmptyRecord: false 84 | SplitEmptyNamespace: true 85 | 86 | # Control Statements 87 | AllowShortIfStatementsOnASingleLine: false 88 | AllowShortLoopsOnASingleLine: false 89 | AllowShortCaseLabelsOnASingleLine: false 90 | IndentCaseLabels: false 91 | 92 | # Spaces 93 | SpaceAfterCStyleCast: false 94 | SpacesInCStyleCastParentheses: false 95 | SpaceAfterTemplateKeyword: true 96 | SpaceBeforeAssignmentOperators: true 97 | SpaceBeforeParens: ControlStatements 98 | SpaceInEmptyParentheses: false 99 | SpacesInAngles: false 100 | SpacesInParentheses: false 101 | SpacesInSquareBrackets: false 102 | MaxEmptyLinesToKeep: 3 103 | 104 | # OCD 105 | SortUsingDeclarations: true 106 | SortIncludes: false 107 | 108 | --- 109 | Language: Cpp 110 | Standard: Cpp11 111 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .vs/ 3 | .mypy_cache/ 4 | benchmark_results/lua_bindings_shootout.test.json 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendor/benchmark"] 2 | path = vendor/benchmark 3 | url = https://github.com/BaaMeow/benchmark 4 | [submodule "vendor/sol3/sol3"] 5 | path = vendor/sol3/sol3 6 | url = https://github.com/ThePhD/sol2.git 7 | -------------------------------------------------------------------------------- /.style.yapf: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright (c) 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | [style] 24 | based_on_style = pep8 25 | use_tabs = true 26 | indent_width = 5 27 | 28 | spaces_before_comment = 1 29 | spaces_around_power_operator = true 30 | space_between_ending_comma_and_closing_bracket = true 31 | 32 | continuation_align_style = SPACE 33 | split_before_first_argument = false 34 | split_complex_comprehension = true 35 | dedent_closing_brackets = false 36 | coalesce_brackets = true 37 | align_closing_bracket_with_visual_indent = false 38 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Mac", 5 | "compileCommands": "${workspaceFolder}/build/compile_commands.json", 6 | "includePath": [ 7 | "/usr/include", 8 | "/usr/local/include", 9 | "${workspaceFolder}" 10 | ], 11 | "defines": [], 12 | "intelliSenseMode": "clang-x64", 13 | "browse": { 14 | "path": [ 15 | "/usr/include", 16 | "/usr/local/include", 17 | "${workspaceFolder}" 18 | ], 19 | "limitSymbolsToIncludedHeaders": true, 20 | "databaseFilename": "" 21 | }, 22 | "macFrameworkPath": [ 23 | "/System/Library/Frameworks", 24 | "/Library/Frameworks" 25 | ] 26 | }, 27 | { 28 | "name": "Linux", 29 | "compileCommands": "${workspaceFolder}/build/compile_commands.json", 30 | "includePath": [ 31 | "/usr/include", 32 | "/usr/local/include", 33 | "${workspaceFolder}" 34 | ], 35 | "defines": [], 36 | "intelliSenseMode": "clang-x64", 37 | "browse": { 38 | "path": [ 39 | "/usr/include", 40 | "/usr/local/include", 41 | "${workspaceFolder}" 42 | ], 43 | "limitSymbolsToIncludedHeaders": true, 44 | "databaseFilename": "" 45 | } 46 | }, 47 | { 48 | "name": "Win32", 49 | "compileCommands": "${workspaceFolder}/build/compile_commands.json", 50 | "includePath": [ 51 | "${workspaceFolder}", 52 | "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/include/*", 53 | "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/atlmfc/include/*", 54 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/um", 55 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/ucrt", 56 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/shared", 57 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/winrt" 58 | ], 59 | "defines": [ 60 | "_DEBUG", 61 | "UNICODE", 62 | "_UNICODE" 63 | ], 64 | "intelliSenseMode": "msvc-x64", 65 | "browse": { 66 | "path": [ 67 | "${workspaceFolder}", 68 | "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/include/*", 69 | "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/atlmfc/include/*", 70 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/um", 71 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/ucrt", 72 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/shared", 73 | "C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/winrt" 74 | ], 75 | "limitSymbolsToIncludedHeaders": true, 76 | "databaseFilename": "" 77 | }, 78 | "cStandard": "c11", 79 | "cppStandard": "c++17", 80 | "configurationProvider": "vector-of-bool.cmake-tools" 81 | } 82 | ], 83 | "version": 4 84 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "graphs", 9 | "type": "python", 10 | "request": "launch", 11 | "program": "${workspaceFolder}/tools/generate_graphs.py", 12 | "console": "integratedTerminal", 13 | "args": [ 14 | "--input=benchmark_results/new/lua_bindings_shootout.new.json", 15 | "--input_format=json", 16 | "--output_dir=benchmark_results/new", 17 | "--scale=50", 18 | "--scale_categories", 19 | "c_function_measure", 20 | "member_function_call_measure", 21 | "userdata_variable_access_measure", 22 | "userdata_variable_access_large_measure", 23 | "userdata_variable_access_last_measure", 24 | "multi_return_lua_measure", 25 | "return_userdata_measure", 26 | "implicit_inheritance_measure", 27 | "--categories", 28 | "table_global_string_get_measure", 29 | "table_global_string_set_measure", 30 | "table_get_measure", 31 | "table_set_measure", 32 | "table_chained_get_measure", 33 | "table_chained_set_measure", 34 | "c_function_measure", 35 | "c_function_through_lua_in_c_measure", 36 | "lua_function_in_c_measure", 37 | "member_function_call_measure", 38 | "userdata_variable_access_measure", 39 | "userdata_variable_access_large_measure", 40 | "userdata_variable_access_last_measure", 41 | "multi_return_lua_measure", 42 | "multi_return_measure", 43 | "stateful_function_object_measure", 44 | "base_derived_measure", 45 | "return_userdata_measure", 46 | "optional_success_measure", 47 | "optional_half_failure_measure", 48 | "optional_failure_measure", 49 | "implicit_inheritance_measure", 50 | ] 51 | }, 52 | { 53 | "name": "lua_bindings_shootout", 54 | "type": "cppvsdbg", 55 | "request": "launch", 56 | "preLaunchTask": "cmake build", 57 | "program": "${command:cmake.launchTargetPath}", 58 | "args": [ 59 | "--benchmark_out=${workspaceFolder}/benchmark_results/lua_bindings_shootout.test.json", 60 | "--benchmark_out_format=json", 61 | "--benchmark_repetitions=5", 62 | "--benchmark_report_aggregates_only=false", 63 | ], 64 | "stopAtEntry": false, 65 | "cwd": "${workspaceFolder}", 66 | "environment": [], 67 | "internalConsoleOptions": "openOnSessionStart", 68 | } 69 | ] 70 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cmake.configureSettings": { 3 | "BUILD_SHARED_LIBS": true, 4 | "BOOST_ROOT": "D:\\local\\boost_1_65_1", 5 | }, 6 | "python.linting.mypyEnabled": true, 7 | "python.formatting.provider": "yapf", 8 | "C_Cpp.intelliSenseEngineFallback": "Disabled", 9 | "C_Cpp.errorSquiggles": "Disabled", 10 | "files.associations": { 11 | "tuple": "cpp", 12 | "regex": "cpp", 13 | "system_error": "cpp", 14 | "xfunctional": "cpp", 15 | "xlocmon": "cpp", 16 | "xtr1common": "cpp", 17 | "bitset": "cpp", 18 | "set": "cpp", 19 | "xlocale": "cpp", 20 | "xstring": "cpp", 21 | "xutility": "cpp", 22 | "array": "cpp", 23 | "istream": "cpp", 24 | "memory": "cpp", 25 | "type_traits": "cpp", 26 | "utility": "cpp", 27 | "variant": "cpp", 28 | "xlocmes": "cpp", 29 | "xlocnum": "cpp", 30 | "xloctime": "cpp", 31 | "stack": "cpp", 32 | "iostream": "cpp" 33 | }, 34 | "C_Cpp.configurationWarnings": "Disabled", 35 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "Cmake Build (Debug)", 8 | "type": "shell", 9 | "identifier": "cmake build", 10 | "command": "cmake", 11 | "args": [ 12 | "--build", 13 | "${workspaceFolder}/build", 14 | "--config", 15 | "Debug", 16 | "--target", 17 | "all", 18 | //"--", 19 | //"-j", 20 | //"10" 21 | ], 22 | "presentation": { 23 | "echo": true, 24 | "reveal": "always", 25 | "focus": true, 26 | "panel": "new" 27 | }, 28 | "options": { 29 | "cwd": "${workspaceFolder}/build" 30 | }, 31 | "group": { 32 | "kind": "build", 33 | "isDefault": true 34 | } 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright � 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | cmake_minimum_required(VERSION 3.10.0) 24 | 25 | project("lua bindings shootout" 26 | VERSION 1.0.0 27 | DESCRIPTION "A library for benchmarking the runtime of various different Lua bindings, since there are so many of them" 28 | LANGUAGES C CXX 29 | ) 30 | 31 | add_compile_options($<$,$>:/std:c++latest>) 32 | 33 | # # CMake Modules 34 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") 35 | 36 | # # Options 37 | # whether or not we should build as 32-bit 38 | if (CMAKE_SIZEOF_VOID_P EQUAL 4 OR LB_SHOOTOUT_BUILD_32_BITS) 39 | set(LB_SHOOTOUT_BUILD_32_BITS ON CACHE BOOL "Enable a 32-bit build.") 40 | set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CFG_INT_DIR}/lib") 41 | set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CFG_INT_DIR}/lib") 42 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CFG_INT_DIR}/bin") 43 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CFG_INT_DIR}/bin") 44 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x86/${CFG_INT_DIR}/lib") 45 | else() 46 | set(LB_SHOOTOUT_BUILD_32_BITS OFF CACHE BOOL "Enable a 32-bit build.") 47 | set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CFG_INT_DIR}/lib") 48 | set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CFG_INT_DIR}/lib") 49 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CFG_INT_DIR}/bin") 50 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CFG_INT_DIR}/bin") 51 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/x64/${CFG_INT_DIR}/lib") 52 | endif(CMAKE_SIZEOF_VOID_P EQUAL 4 OR LB_SHOOTOUT_BUILD_32_BITS) 53 | 54 | # # Get Lua Build through find_package 55 | # Wrap it in shared specifiers... 56 | set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS}) 57 | set(BUILD_SHARED_LIBS TRUE) 58 | find_package(LuaDev 5.3.4 REQUIRED) 59 | set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED}) 60 | set(BUILD_SHARED_LIBS_SAVED "") 61 | 62 | find_package(Threads REQUIRED) 63 | 64 | # # Get all dependent packages 65 | find_package(KaguyaDev REQUIRED) 66 | find_package(SeleneDev REQUIRED) 67 | find_package(LuwraDev REQUIRED) 68 | find_package(LuaIntfDev REQUIRED) 69 | find_package(ToLuappDev REQUIRED) 70 | find_package(LuaApippDev REQUIRED) 71 | find_package(LuaBridgeDev REQUIRED) 72 | find_package(LuabindDev REQUIRED) 73 | find_package(OOLuaDev REQUIRED) 74 | find_package(LuaCppInterface REQUIRED) 75 | find_package(Luawrapper REQUIRED) 76 | 77 | # Subdirectory Google Benchmark, after setting all cache variables 78 | set(BENCHMARK_ENABLE_EXCEPTIONS ON CACHE INTERNAL "Enable the use of exceptions in the benchmark library." FORCE) 79 | set(BENCHMARK_ENABLE_TESTING OFF CACHE INTERNAL "Enable testing of the benchmark library." FORCE) 80 | set(BENCHMARK_ENABLE_LTO OFF CACHE INTERNAL "Enable link time optimisation of the benchmark library." FORCE) 81 | set(BENCHMARK_USE_LIBCXX OFF CACHE INTERNAL "Build and test using libc++ as the standard library." FORCE) 82 | set(BENCHMARK_BUILD_32_BITS ${LB_SHOOTOUT_BUILD_32_BITS} CACHE INTERNAL "Build a 32 bit version of the library." FORCE) 83 | set(BENCHMARK_ENABLE_INSTALL OFF CACHE INTERNAL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" FORCE) 84 | set(BENCHMARK_DOWNLOAD_DEPENDENCIES OFF CACHE INTERNAL "Allow the downloading and in-tree building of unmet dependencies" FORCE) 85 | set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE INTERNAL "Enable building the unit tests which depend on gtest" FORCE) 86 | # Google bnechmark must be built as a static library, 87 | # it doesn't contain export definitions 88 | set(BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS}) 89 | set(BUILD_SHARED_LIBS FALSE) 90 | add_subdirectory(vendor/benchmark) 91 | set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVED}) 92 | set(BUILD_SHARED_LIBS_SAVED "") 93 | 94 | add_subdirectory(vendor/sol3/sol3) 95 | 96 | set(lua_bindings_shootout_sources 97 | "source/benchmark.hpp" 98 | "source/lbs_lib.hpp" 99 | "source/lbs_lua.hpp" 100 | 101 | "source/luawrapper.cpp" 102 | "source/luacppinterface.cpp" 103 | 104 | "source/swig.cpp" 105 | "source/toluapp.cpp" 106 | "source/luabind.cpp" 107 | "source/lua-api-pp.cpp" 108 | "source/oolua.cpp" 109 | "source/luabridge.cpp" 110 | "source/lua-intf.cpp" 111 | "source/luwra.cpp" 112 | "source/plain_c.cpp" 113 | "source/selene.cpp" 114 | "source/kaguya.cpp" 115 | "source/old_sol.cpp" 116 | "source/sol2.cpp" 117 | "source/sol3.cpp" 118 | 119 | "source/lua_bindings_shootout.cpp" 120 | ) 121 | 122 | set(LB_SHOOTOUT_LUA_REPETITIONS 50 123 | CACHE STRING "Number of times to re-run a block of Lua code in the benchmarks" 124 | ) 125 | 126 | add_executable(lua_bindings_shootout ${lua_bindings_shootout_sources}) 127 | target_link_libraries(lua_bindings_shootout 128 | PRIVATE 129 | # lua library 130 | ${LUA_LIBRARIES} 131 | # binding libraries 132 | ${LUACPPINTERFACE_LIBRARIES} 133 | ${LUAWRAPPER_LIBRARIES} 134 | ${TOLUAPP_LIBRARIES} 135 | ${LUABIND_LIBRARIES} 136 | ${LUAAPIPP_LIBRARIES} 137 | ${LUABRIDGE_LIBRARIES} 138 | ${KAGUYA_LIBRARIES} 139 | ${SELENE_LIBRARIES} 140 | ${LUWRA_LIBRARIES} 141 | ${LUAINTF_LIBRARIES} 142 | ${OOLUA_LIBRARIES} 143 | sol2::sol2 144 | # benchmarking library and utilities 145 | Threads::Threads 146 | benchmark 147 | ) 148 | target_compile_definitions(lua_bindings_shootout 149 | PRIVATE 150 | _CRT_SECURE_NO_WARNINGS 151 | _SCL_SECURE_NO_WARNINGS 152 | SLB_EXTERNAL_LUA 153 | SLB_DYNAMIC_LIBRARY 154 | LUA_COMPAT_ALL 155 | LUA_COMPAT_52 156 | LUA_COMPAT_51 157 | LUA_COMPAT_APIINTCASTS 158 | "LUA_BINDINGS_SHOOTOUT_LUA_REPETITIONS=${LB_SHOOTOUT_LUA_REPETITIONS}" 159 | ) 160 | target_include_directories(lua_bindings_shootout 161 | PRIVATE 162 | "${CMAKE_CURRENT_SOURCE_DIR}/vendor/sol2" 163 | "${CMAKE_CURRENT_SOURCE_DIR}/vendor/old_sol" 164 | ) 165 | if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") 166 | target_compile_options(lua_bindings_shootout 167 | PRIVATE -ftemplate-depth=2048 168 | ) 169 | endif() 170 | 171 | set(LB_SHOOTOUT_REPETITIONS 150 172 | CACHE STRING "The number of times to re-rerun the benchmarks to gather additional data" 173 | ) 174 | set(LB_SHOOTOUT_FORMAT json 175 | CACHE STRING "The output format of the data. Must be json or csv") 176 | string(TOLOWER ${LB_SHOOTOUT_FORMAT} LB_SHOOTOUT_FORMAT_LOWER) 177 | set(LB_SHOOTOUT_FORMAT ${LB_SHOOTOUT_FORMAT_LOWER} 178 | CACHE STRING "The output format of the data. Must be json or csv" FORCE) 179 | 180 | file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/benchmark_results") 181 | set(LB_SHOOTOUT_OUTFILE "${CMAKE_SOURCE_DIR}/benchmark_results/lua_bindings_shootout.${LB_SHOOTOUT_FORMAT}") 182 | set(LB_SHOOTOUT_GRAPH_OUTFILE "${CMAKE_SOURCE_DIR}/benchmark_results/") 183 | 184 | add_custom_target(shootout 185 | COMMAND lua_bindings_shootout "--benchmark_out=${LB_SHOOTOUT_OUTFILE}" 186 | "--benchmark_out_format=${LB_SHOOTOUT_FORMAT}" 187 | "--benchmark_repetitions=${LB_SHOOTOUT_REPETITIONS}" 188 | COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/tools/generate_graphs.py" 189 | "--input=${LB_SHOOTOUT_OUTFILE}" 190 | "--input_format=${LB_SHOOTOUT_FORMAT}" 191 | "--output_dir=${LB_SHOOTOUT_GRAPH_OUTFILE}" 192 | "--categories=${lb_shootout_categories}" 193 | "--scale_categories=${lb_shootout_scale_categories}" 194 | "--scale=${LB_SHOOTOUT_LUA_REPETITIONS}" 195 | DEPENDS lua_bindings_shootout 196 | BYPRODUCTS ${LB_SHOOTOUT_OUTFILE} 197 | COMMENT "Executing Benchmarks and outputting to '${LB_SHOOTOUT_OUTFILE}' then running graphs for '${LB_SHOOTOUT_GRAPH_OUTFILE}'" 198 | ) 199 | 200 | set(lb_shootout_categories table_global_string_get_measure,table_global_string_set_measure,table_get_measure,table_set_measure,table_chained_get_measure,table_chained_set_measure,c_function_measure,c_function_through_lua_in_c_measure,lua_function_in_c_measure,member_function_call_measure,userdata_variable_access_measure,userdata_variable_access_large_measure,userdata_variable_access_last_measure,multi_return_lua_measure,multi_return_measure,stateful_function_object_measure,base_derived_measure,return_userdata_measure,optional_success_measure,optional_half_failure_measure,optional_failure_measure,implicit_inheritance_measure) 201 | set(lb_shootout_scale_categories c_function_measure,member_function_call_measure,userdata_variable_access_measure,userdata_variable_access_large_measure,userdata_variable_access_last_measure,multi_return_lua_measure,return_userdata_measure,implicit_inheritance_measure) 202 | 203 | add_custom_target(graphs 204 | COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/tools/generate_graphs.py" 205 | "--input=${LB_SHOOTOUT_OUTFILE}" 206 | "--input_format=${LB_SHOOTOUT_FORMAT}" 207 | "--output_dir=${LB_SHOOTOUT_GRAPH_OUTFILE}" 208 | "--categories=${lb_shootout_categories}" 209 | "--scale_categories=${lb_shootout_scale_categories}" 210 | "--scale=${LB_SHOOTOUT_LUA_REPETITIONS}" 211 | DEPENDS lua_bindings_shootout shootout 212 | COMMENT "Generating graphs for '${LB_SHOOTOUT_OUTFILE}'" 213 | ) 214 | -------------------------------------------------------------------------------- /CMakeSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com//fwlink//?linkid=834763 for more information about this file. 3 | "configurations": [ 4 | { 5 | "name": "x64-Debug", 6 | "generator": "Ninja", 7 | "configurationType": "Debug", 8 | "inheritEnvironments": [ "msvc_x64_x64" ], 9 | "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", 10 | "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", 11 | "cmakeCommandArgs": "-DBOOST_ROOT=D:\\local\\boost_1_65_1", 12 | "buildCommandArgs": "-v", 13 | "ctestCommandArgs": "" 14 | }, 15 | { 16 | "name": "x64-Release", 17 | "generator": "Ninja", 18 | "configurationType": "Release", 19 | "inheritEnvironments": [ "msvc_x64_x64" ], 20 | "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", 21 | "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", 22 | "cmakeCommandArgs": "-DBOOST_ROOT=D:\\local\\boost_1_65_1", 23 | "buildCommandArgs": "-v", 24 | "ctestCommandArgs": "" 25 | }, 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Benchmark Shootout: Lua Bindings 2 | 3 | A benchmarking many of the canonical/best/popular lua bindings for their performance and feature support, but mostly for their performance. 4 | 5 | ## Current Contenders 6 | 7 | The following bindings are benchmarked or are being aimed to be benchmarked. All are built on top of plain C: 8 | 9 | * [x] Plain C (PUC-RIO Lua, 5.3.4) 10 | * [x] sol1 (Rapptz, v1.1.0) 11 | * [x] sol2 (ThePhD, v2.20.0) 12 | * [x] sol3 (ThePhD, latest) 13 | * [x] luabridge (Vinnie Falco, latest) 14 | * [x] OOLua (LiamDevine, forked at v2.0.1 (latest) from elite-lang since website is down (May 1st, 2018)) 15 | * [x] Lua-Intf (Steve K. Chiu, latest) 16 | * [x] Selene (Jeremy Ong, forked at latest + patches) 17 | * [x] Kaguya (satoren, latest) 18 | * [x] Luwra (Ole Krüger, latest) 19 | * [x] lua-api-pp (OldFisher, latest + patches) 20 | * [x] tolua++ (Ariel Manzur, Waldemar Celes, latest) 21 | * [x] SWIG (Maintained by various, latest as of May 4th, 2018) 22 | * [x] luawrapper (Tomaka, maintained by Bert Hubert, latest) 23 | * [x] luacppinterface (David Siaw, latest) 24 | * [x] luabind (Rasterbar, latest + patches) 25 | 26 | ## "Can you Benchmark X?" 27 | 28 | If you feel there is a binding that needs to be benchmarked, please either make a pull request for that library or make an issue request. Please note that I am not particularly thrilled to benchmark libraries that cannot compile on Visual C++'s/g++'s/clang++'s latest compiler versions and have had quite my fill of hacking older, unmaintained libraries to make them compile for recent compilers. 29 | 30 | If the library you suggest has no documentation and fills my terminal with errors I am likely going to throw it out the window. 31 | 32 | I want _working_, _halfway decent_ libraries, not more things I need to make personal forks of in order for them to compile properly only to muck around in an undocumented mess. If you want something benchmarked, point me to some examples / documentation or just make a ready-made pull request. Follow any of the `{library-name-here}.cpp` files in the source folder to see an example. Some are hairy, so using `sol2.cpp` or `sol3.cpp` or `plain_c.cpp` as an example of what we are benchmark is a good idea to get you started. 33 | -------------------------------------------------------------------------------- /benchmark_results/base derived.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/base derived.png -------------------------------------------------------------------------------- /benchmark_results/c function through lua in c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/c function through lua in c.png -------------------------------------------------------------------------------- /benchmark_results/c function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/c function.png -------------------------------------------------------------------------------- /benchmark_results/implicit inheritance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/implicit inheritance.png -------------------------------------------------------------------------------- /benchmark_results/lua function in c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/lua function in c.png -------------------------------------------------------------------------------- /benchmark_results/member function call.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/member function call.png -------------------------------------------------------------------------------- /benchmark_results/multi return lua.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/multi return lua.png -------------------------------------------------------------------------------- /benchmark_results/multi return.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/multi return.png -------------------------------------------------------------------------------- /benchmark_results/optional failure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/optional failure.png -------------------------------------------------------------------------------- /benchmark_results/optional half failure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/optional half failure.png -------------------------------------------------------------------------------- /benchmark_results/optional success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/optional success.png -------------------------------------------------------------------------------- /benchmark_results/return userdata.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/return userdata.png -------------------------------------------------------------------------------- /benchmark_results/stateful function object.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/stateful function object.png -------------------------------------------------------------------------------- /benchmark_results/table chained get.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/table chained get.png -------------------------------------------------------------------------------- /benchmark_results/table chained set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/table chained set.png -------------------------------------------------------------------------------- /benchmark_results/table get.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/table get.png -------------------------------------------------------------------------------- /benchmark_results/table global string get.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/table global string get.png -------------------------------------------------------------------------------- /benchmark_results/table global string set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/table global string set.png -------------------------------------------------------------------------------- /benchmark_results/table set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/table set.png -------------------------------------------------------------------------------- /benchmark_results/userdata variable access large.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/userdata variable access large.png -------------------------------------------------------------------------------- /benchmark_results/userdata variable access last.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/userdata variable access last.png -------------------------------------------------------------------------------- /benchmark_results/userdata variable access.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/benchmark_results/userdata variable access.png -------------------------------------------------------------------------------- /cmake/Modules/Common/core.cmake: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright � 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | if(_common_core_included) 24 | return() 25 | endif(_common_core_included) 26 | set(_common_core_included true) 27 | 28 | # # Prepend function (is there an equivalent in CMake somewhere...?) 29 | function(prepend var prefix) 30 | set(l "") 31 | foreach(f ${ARGN}) 32 | list(APPEND l "${prefix}${f}") 33 | endforeach(f) 34 | SET(${var} "${l}" PARENT_SCOPE) 35 | ENDFUNCTION(prepend) 36 | -------------------------------------------------------------------------------- /cmake/Modules/FindKaguyaDev.cmake: -------------------------------------------------------------------------------- 1 | 2 | # # lua bindings shootout 3 | # The MIT License (MIT) 4 | # 5 | # Copyright � 2018 ThePhD 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | # this software and associated documentation files (the "Software"), to deal in 9 | # the Software without restriction, including without limitation the rights to 10 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | # the Software, and to permit persons to whom the Software is furnished to do so, 12 | # subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | include(ExternalProject) 25 | include(FindPackageHandleStandardArgs) 26 | include(Common/Core) 27 | 28 | # # Base variables 29 | set(kaguya_version 1.3.2) 30 | set(kaguya_lib kaguya_lib_${kaguya_version}) 31 | 32 | # # Useful locations 33 | set(kaguya_dev_toplevel "${CMAKE_BINARY_DIR}/vendor/kaguya_${kaguya_version}") 34 | set(kaguya_include_dirs "${kaguya_dev_toplevel}/include") 35 | 36 | # # kaguya library sources 37 | set(kaguya_sources kaguya/kaguya.hpp) 38 | prepend(kaguya_sources "${kaguya_dev_toplevel}/include/" ${kaguya_sources}) 39 | 40 | # # External project to get sources 41 | ExternalProject_Add(KAGUYADEV_SOURCE 42 | BUILD_IN_SOURCE TRUE 43 | BUILD_ALWAYS FALSE 44 | # # Use Git to get what we need 45 | GIT_SHALLOW TRUE 46 | GIT_SUBMODULES "" 47 | GIT_REPOSITORY https://github.com/satoren/kaguya.git 48 | PREFIX ${kaguya_dev_toplevel} 49 | SOURCE_DIR ${kaguya_dev_toplevel} 50 | DOWNLOAD_DIR ${kaguya_dev_toplevel} 51 | TMP_DIR "${kaguya_dev_toplevel}-tmp" 52 | STAMP_DIR "${kaguya_dev_toplevel}-stamp" 53 | INSTALL_DIR "${kaguya_dev_toplevel}/local" 54 | CONFIGURE_COMMAND "" 55 | BUILD_COMMAND "" 56 | INSTALL_COMMAND "" 57 | TEST_COMMAND "" 58 | BUILD_BYPRODUCTS "${kaguya_sources}") 59 | 60 | add_library(${kaguya_lib} INTERFACE) 61 | add_dependencies(${kaguya_lib} KAGUYADEV_SOURCE) 62 | target_include_directories(${kaguya_lib} INTERFACE ${kaguya_include_dirs}) 63 | target_link_libraries(${kaguya_lib} INTERFACE ${LUA_LIBRARIES}) 64 | if (NOT MSVC) 65 | target_compile_options(${kaguya_lib} INTERFACE 66 | -Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter) 67 | endif() 68 | 69 | set(KAGUYADEV_FOUND TRUE) 70 | set(KAGUYA_LIBRARIES ${kaguya_lib}) 71 | set(KAGUYA_INCLUDE_DIRS ${kaguya_include_dirs}) 72 | 73 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(KaguyaDev 74 | FOUND_VAR KAGUYADEV_FOUND 75 | REQUIRED_VARS KAGUYA_LIBRARIES KAGUYA_INCLUDE_DIRS 76 | VERSION_VAR kaguya_version) -------------------------------------------------------------------------------- /cmake/Modules/FindLuaApippDev.cmake: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright � 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | # # Standard CMake Libraries 24 | include(ExternalProject) 25 | include(FindPackageHandleStandardArgs) 26 | include(Common/Core) 27 | 28 | # # Base variables 29 | set(luaapipp_version v2015-02-12-3) 30 | 31 | # # Useful locations 32 | set(luaapipp_dev_toplevel "${CMAKE_BINARY_DIR}/vendor/luaapipp_${luaapipp_version}") 33 | set(luaapipp_include_dirs "${luaapipp_dev_toplevel}/") 34 | 35 | # # LuaApipp library sources 36 | set(luaapipp_sources 37 | impl.cpp 38 | lua.hpp 39 | ) 40 | #prepend(luaapipp_sources "${luaapipp_dev_toplevel}/luapp/" ${luaapipp_sources}) 41 | 42 | # # External project to get sources 43 | ExternalProject_Add(LUAAPIPP_DEV_SOURCE 44 | BUILD_IN_SOURCE TRUE 45 | BUILD_ALWAYS FALSE 46 | # # Use Git to get what we need 47 | #GIT_SUBMODULES "" 48 | GIT_SHALLOW TRUE 49 | GIT_REPOSITORY https://github.com/ThePhD/lua-api-pp.git 50 | PREFIX ${luaapipp_dev_toplevel} 51 | SOURCE_DIR ${luaapipp_dev_toplevel} 52 | DOWNLOAD_DIR ${luaapipp_dev_toplevel} 53 | TMP_DIR "${luaapipp_dev_toplevel}-tmp" 54 | STAMP_DIR "${luaapipp_dev_toplevel}-stamp" 55 | INSTALL_DIR "${luaapipp_dev_toplevel}/local" 56 | CONFIGURE_COMMAND "" 57 | BUILD_COMMAND "" 58 | INSTALL_COMMAND "" 59 | TEST_COMMAND "" 60 | BUILD_BYPRODUCTS "${luaapipp_sources}") 61 | 62 | set(luaapipp_lib luaapipp_lib_${luaapipp_version}) 63 | add_library(${luaapipp_lib} INTERFACE) 64 | add_dependencies(${luaapipp_lib} LUAAPIPP_DEV_SOURCE) 65 | target_include_directories(${luaapipp_lib} 66 | INTERFACE ${luaapipp_include_dirs} 67 | ) 68 | target_link_libraries(${luaapipp_lib} 69 | INTERFACE ${LUA_LIBRARIES} 70 | ) 71 | target_compile_definitions(${luaapipp_lib} 72 | INTERFACE "LUAPP_HEADER_ONLY=1" 73 | ) 74 | # # Variables required by LuaApipp 75 | set(LUAAPIPP_LIBRARIES ${luaapipp_lib}) 76 | set(LUAAPIPP_INCLUDE_DIRS ${luaapipp_include_dirs}) 77 | set(LUAAPIPPDEV_FOUND TRUE) 78 | 79 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaApippDev 80 | FOUND_VAR LUAAPIPPDEV_FOUND 81 | REQUIRED_VARS LUAAPIPP_LIBRARIES LUAAPIPP_INCLUDE_DIRS 82 | VERSION_VAR luaapipp_version) 83 | -------------------------------------------------------------------------------- /cmake/Modules/FindLuaBridgeDev.cmake: -------------------------------------------------------------------------------- 1 | 2 | # # lua bindings shootout 3 | # The MIT License (MIT) 4 | # 5 | # Copyright � 2018 ThePhD 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | # this software and associated documentation files (the "Software"), to deal in 9 | # the Software without restriction, including without limitation the rights to 10 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | # the Software, and to permit persons to whom the Software is furnished to do so, 12 | # subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | include(ExternalProject) 25 | include(FindPackageHandleStandardArgs) 26 | include(Common/Core) 27 | 28 | # # Base variables 29 | set(luabridge_version 1.0.2) 30 | set(luabridge_lib luabridge_lib_${luabridge_version}) 31 | 32 | # # Useful locations 33 | set(luabridge_build_toplevel "${CMAKE_BINARY_DIR}/vendor/luabridge_${luabridge_version}") 34 | set(luabridge_include_dirs "${luabridge_build_toplevel}/Source") 35 | 36 | # # luabridge library sources 37 | set(luabridge_sources LuaBridge/LuaBridge.h) 38 | prepend(luabridge_sources "${luabridge_build_toplevel}/Source/" ${luabridge_sources}) 39 | 40 | # # External project to get sources 41 | ExternalProject_Add(LUABRIDGE_BUILD_SOURCE 42 | BUILD_IN_SOURCE TRUE 43 | BUILD_ALWAYS FALSE 44 | # # Use Git to get what we need 45 | GIT_SHALLOW TRUE 46 | GIT_SUBMODULES "" 47 | GIT_REPOSITORY https://github.com/vinniefalco/LuaBridge.git 48 | PREFIX ${luabridge_build_toplevel} 49 | SOURCE_DIR ${luabridge_build_toplevel} 50 | DOWNLOAD_DIR ${luabridge_build_toplevel} 51 | TMP_DIR "${luabridge_build_toplevel}-tmp" 52 | STAMP_DIR "${luabridge_build_toplevel}-stamp" 53 | INSTALL_DIR "${luabridge_build_toplevel}/local" 54 | CONFIGURE_COMMAND "" 55 | BUILD_COMMAND "" 56 | INSTALL_COMMAND "" 57 | TEST_COMMAND "" 58 | BUILD_BYPRODUCTS "${luabridge_sources}") 59 | 60 | add_library(${luabridge_lib} INTERFACE) 61 | add_dependencies(${luabridge_lib} LUABRIDGE_BUILD_SOURCE) 62 | target_include_directories(${luabridge_lib} INTERFACE ${luabridge_include_dirs}) 63 | target_link_libraries(${luabridge_lib} INTERFACE ${LUA_LIBRARIES}) 64 | if (NOT MSVC) 65 | target_compile_options(${luabridge_lib} INTERFACE 66 | -Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter) 67 | endif() 68 | 69 | set(LUABRIDGEDEV_FOUND TRUE) 70 | set(LUABRIDGE_LIBRARIES ${luabridge_lib}) 71 | set(LUABRIDGE_INCLUDE_DIRS ${luabridge_include_dirs}) 72 | 73 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaBridgeDev 74 | FOUND_VAR LUABRIDGEDEV_FOUND 75 | REQUIRED_VARS LUABRIDGE_LIBRARIES LUABRIDGE_INCLUDE_DIRS 76 | VERSION_VAR luabridge_version) -------------------------------------------------------------------------------- /cmake/Modules/FindLuaDev.cmake: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright � 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | # # Standard CMake Libraries 24 | include(FindPackageHandleStandardArgs) 25 | 26 | # Contain literally everything inside of this function to prevent spillage 27 | function(find_lua_dev lua_version) 28 | # # # Variables 29 | # # Core Paths 30 | string(TOLOWER ${lua_version} LUA_DEV_NORMALIZED_LUA_VERSION) 31 | if (LUA_DEV_NORMALIZED_LUA_VERSION MATCHES "luajit") 32 | set(LUA_DEV_LIBNAME ${lua_version}) 33 | elseif (BUILD_LUAJIT) 34 | set(LUA_DEV_LIBNAME luajit-${lua_version}) 35 | elseif (LUA_DEV_NORMALIZED_LUA_VERSION MATCHES "lua") 36 | set(LUA_DEV_LIBNAME ${lua_version}) 37 | elseif (BUILD_LUA) 38 | set(LUA_DEV_LIBNAME lua-${lua_version}) 39 | else() 40 | set(LUA_DEV_LIBNAME lua-${lua_version}) 41 | endif() 42 | set(LUA_DEV_TOPLEVEL "${CMAKE_BINARY_DIR}/vendor/${LUA_DEV_LIBNAME}") 43 | set(LUA_DEV_INSTALL_DIR "${LUA_DEV_TOPLEVEL}") 44 | # # Misc needed variables 45 | set(LUA_DEV_LIBRARY_DESCRIPTION "The base name of the library to build either the static or the dynamic library") 46 | 47 | # Object file suffixes 48 | if (MSVC) 49 | set(LUA_DEV_BUILD_DLL_DEFAULT ON) 50 | set(LUA_DEV_OBJECT_FILE_SUFFIX .obj) 51 | else() 52 | set(LUA_DEV_BUILD_DLL_DEFAULT OFF) 53 | set(LUA_DEV_OBJECT_FILE_SUFFIX .o) 54 | endif() 55 | 56 | STRING(TOLOWER ${LUA_DEV_LIBNAME} LUA_DEV_NORMALIZED_LIBNAME) 57 | if (NOT LUA_LIBRARY_NAME) 58 | if (LUA_DEV_NORMALIZED_LIBNAME MATCHES "luajit") 59 | set(LUA_LIBRARY luajit) 60 | else() 61 | set(LUA_LIBRARY ${LUA_DEV_LIBNAME}) 62 | endif() 63 | else() 64 | set(LUA_LIBRARY_NAME ${LUA_LIBRARY_NAME} 65 | CACHE STRING 66 | ${LUA_DEV_LIBRARY_DESCRIPTION}) 67 | endif() 68 | 69 | # # # Build Lua 70 | # # Select either LuaJIT or Vanilla Lua here, based on what we discover 71 | set(LUA_VERSION ${lua_version}) 72 | if (BUILD_LUAJIT OR LUA_DEV_NORMALIZED_LUA_VERSION MATCHES "luajit") 73 | include(${CMAKE_CURRENT_LIST_DIR}/FindLuaDev/LuaJIT.cmake) 74 | set(LUA_VERSION_STRING ${LUA_JIT_VERSION}) 75 | else() 76 | include(${CMAKE_CURRENT_LIST_DIR}/FindLuaDev/LuaVanilla.cmake) 77 | set(LUA_VERSION_STRING ${LUA_VANILLA_VERSION}) 78 | endif() 79 | 80 | # # Export variables to the parent scope 81 | set(LUA_LIBRARIES ${LUA_LIBRARIES} PARENT_SCOPE) 82 | set(LUA_INTERPRETER ${LUA_INTERPRETER} PARENT_SCOPE) 83 | set(LUA_INCLUDE_DIRS ${LUA_INCLUDE_DIRS} PARENT_SCOPE) 84 | set(LUA_VERSION_STRING ${LUA_VERSION_STRING} PARENT_SCOPE) 85 | set(LUADEV_FOUND TRUE PARENT_SCOPE) 86 | endfunction(find_lua_dev) 87 | 88 | if (LuaDev_FIND_COMPONENTS) 89 | list(GET LuaDev_FIND_COMPONENTS 0 lua_version) 90 | endif(LuaDev_FIND_COMPONENTS) 91 | if (LuaDev_FIND_VERSION) 92 | if (lua_version) 93 | set(lua_version "${lua_version}-${LuaDev_FIND_VERSION}") 94 | else() 95 | set(lua_version ${LuaDev_FIND_VERSION}) 96 | endif(lua_version) 97 | endif(LuaDev_FIND_VERSION) 98 | if (BUILD_SHARED_LIBS) 99 | set(LUA_DEV_LIBRARY_TYPE SHARED) 100 | else() 101 | set(LUA_DEV_LIBRARY_TYPE STATIC) 102 | endif(BUILD_SHARED_LIBS) 103 | if (NOT lua_version) 104 | set(lua_version 5.3.4) 105 | endif(NOT lua_version) 106 | 107 | # Call... 108 | find_lua_dev(${lua_version}) 109 | # and then immediately undefine to avoid polluting the current scope 110 | unset(find_lua_dev) 111 | 112 | # handle the QUIETLY and REQUIRED arguments and set LuaDev_FOUND to TRUE if 113 | # all listed variables are TRUE 114 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaDev 115 | FOUND_VAR LUADEV_FOUND 116 | REQUIRED_VARS LUA_LIBRARIES LUA_INTERPRETER LUA_INCLUDE_DIRS 117 | VERSION_VAR LUA_VERSION_STRING) 118 | -------------------------------------------------------------------------------- /cmake/Modules/FindLuaDev/LuaVanilla.cmake: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright � 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | # Include guard 24 | if(_lua_vanilla_dev_included) 25 | return() 26 | endif(_lua_vanilla_dev_included) 27 | set(_lua_vanilla_dev_included true) 28 | 29 | # import necessary standard modules 30 | include(ExternalProject) 31 | # import other modules 32 | include(Common/Core) 33 | 34 | # Latest versions for specific sub-versions of Lua 35 | set(LUA_VANILLA_5.1_LATEST_VERSION 5.1.5) 36 | set(LUA_VANILLA_5.2_LATEST_VERSION 5.2.4) 37 | set(LUA_VANILLA_5.3_LATEST_VERSION 5.3.4) 38 | 39 | # exact version, coming from CI: pull directly from Lua and use external project to build 40 | # list of known md5 / sha1: must update when there are changes 41 | set(LUA_VANILLA_MD5_5.3.4 53a9c68bcc0eda58bdc2095ad5cdfc63) 42 | set(LUA_VANILLA_SHA1_5.3.4 79790cfd40e09ba796b01a571d4d63b52b1cd950) 43 | set(LUA_VANILLA_MD5_5.3.3 703f75caa4fdf4a911c1a72e67a27498) 44 | set(LUA_VANILLA_SHA1_5.3.3 a0341bc3d1415b814cc738b2ec01ae56045d64ef) 45 | set(LUA_VANILLA_MD5_5.3.2 33278c2ab5ee3c1a875be8d55c1ca2a1) 46 | set(LUA_VANILLA_SHA1_5.3.2 7a47adef554fdca7d0c5536148de34579134a973) 47 | set(LUA_VANILLA_MD5_5.3.1 797adacada8d85761c079390ff1d9961) 48 | set(LUA_VANILLA_SHA1_5.3.1 1676c6a041d90b6982db8cef1e5fb26000ab6dee) 49 | set(LUA_VANILLA_MD5_5.3.0 a1b0a7e92d0c85bbff7a8d27bf29f8af) 50 | set(LUA_VANILLA_SHA1_5.3.0 1c46d1c78c44039939e820126b86a6ae12dadfba) 51 | set(LUA_VANILLA_MD5_5.2.4 913fdb32207046b273fdb17aad70be13) 52 | set(LUA_VANILLA_SHA1_5.2.4 ef15259421197e3d85b7d6e4871b8c26fd82c1cf) 53 | set(LUA_VANILLA_MD5_5.2.3 dc7f94ec6ff15c985d2d6ad0f1b35654) 54 | set(LUA_VANILLA_SHA1_5.2.3 926b7907bc8d274e063d42804666b40a3f3c124c) 55 | set(LUA_VANILLA_MD5_5.2.2 efbb645e897eae37cad4344ce8b0a614) 56 | set(LUA_VANILLA_SHA1_5.2.2 0857e41e5579726a4cb96732e80d7aa47165eaf5) 57 | set(LUA_VANILLA_MD5_5.2.1 ae08f641b45d737d12d30291a5e5f6e3) 58 | set(LUA_VANILLA_SHA1_5.2.1 6bb1b0a39b6a5484b71a83323c690154f86b2021) 59 | set(LUA_VANILLA_MD5_5.2.0 f1ea831f397214bae8a265995ab1a93e) 60 | set(LUA_VANILLA_SHA1_5.2.0 08f84c355cdd646f617f09cebea48bd832415829) 61 | set(LUA_VANILLA_MD5_5.1.5 2e115fe26e435e33b0d5c022e4490567) 62 | set(LUA_VANILLA_SHA1_5.1.5 b3882111ad02ecc6b972f8c1241647905cb2e3fc) 63 | set(LUA_VANILLA_MD5_5.1.4 d0870f2de55d59c1c8419f36e8fac150) 64 | set(LUA_VANILLA_SHA1_5.1.4 2b11c8e60306efb7f0734b747588f57995493db7) 65 | set(LUA_VANILLA_MD5_5.1.3 a70a8dfaa150e047866dc01a46272599) 66 | set(LUA_VANILLA_SHA1_5.1.3 89bc9f5a351402565b8077e8123327e7cd15f004) 67 | set(LUA_VANILLA_MD5_5.1.2 687ce4c2a1ddff18f1008490fdc4e5e0) 68 | set(LUA_VANILLA_SHA1_5.1.2 8a460d2d7e70e93cb72bf3d584405464763cb5f0) 69 | set(LUA_VANILLA_MD5_5.1.1 22f4f912f20802c11006fe9b84d5c461) 70 | set(LUA_VANILLA_SHA1_5.1.1 be13878ceef8e1ee7a4201261f0adf09f89f1005) 71 | set(LUA_VANILLA_MD5_5.1 3e8dfe8be00a744cec2f9e766b2f2aee) 72 | set(LUA_VANILLA_SHA1_5.1 1ae9ec317511d525c7999c842ca0b1ddde84e374) 73 | set(LUA_VANILLA_MD5_5.0.3 feee27132056de2949ce499b0ef4c480) 74 | set(LUA_VANILLA_SHA1_5.0.3 e7e91f78b8a8deb09b13436829bed557a46af8ae) 75 | set(LUA_VANILLA_MD5_5.0.2 dea74646b7e5c621fef7174df83c34b1) 76 | set(LUA_VANILLA_SHA1_5.0.2 a200cfd20a9a4c7da1206ae45dddf26186a9e0e7) 77 | set(LUA_VANILLA_MD5_5.0.1 e0a450d84971a3f4563b98172d1e382c) 78 | set(LUA_VANILLA_SHA1_5.0.1 03b47b4785178aca583333f01d8726a8ab9f7ae7) 79 | set(LUA_VANILLA_MD5_5.0 6f14803fad389fb1cb15d17edfeddd91) 80 | set(LUA_VANILLA_SHA1_5.0 88b1bc057857c0db5ace491c4af2c917a2b803bf) 81 | set(LUA_VANILLA_MD5_4.0.1 a31d963dbdf727f9b34eee1e0d29132c) 82 | set(LUA_VANILLA_SHA1_4.0.1 12f1864a7ecd4b8011862a07fa3f177b2e80e7d3) 83 | set(LUA_VANILLA_MD5_4.0 be11522d46d33a931868c03694aaeeef) 84 | set(LUA_VANILLA_SHA1_4.0 8d432c73ef6e98b81d252114be1a83182cc9607a) 85 | set(LUA_VANILLA_MD5_3.2.2 374ba5c4839709922de40b8d10382705) 86 | set(LUA_VANILLA_SHA1_3.2.2 fa50ff14c00d8523c8a3d1d3f4887ecc4400d0c3) 87 | set(LUA_VANILLA_MD5_3.2.1 47264a1978df49fc1dea6ffcddb05b21) 88 | set(LUA_VANILLA_SHA1_3.2.1 d43af5a1c7a65c0ddb4b0ac06c29ecf4cdd22367) 89 | set(LUA_VANILLA_MD5_3.2 a6552da3d40ae9b04489a788262279e8) 90 | set(LUA_VANILLA_SHA1_3.2 84cf9f0e7d00eed3ea8b4ac2b84254b714510b34) 91 | set(LUA_VANILLA_MD5_3.1 d677f3827167eefdefc7b211397cfdfb) 92 | set(LUA_VANILLA_SHA1_3.1 509485e3baafd946f4ffe2a984f8a63746adc32a) 93 | set(LUA_VANILLA_MD5_3.0 997558ae76c2f1cd1e10fd3835c45c6a) 94 | set(LUA_VANILLA_SHA1_3.0 5c8c910353f717ba29b4fe7d538994454229b335) 95 | set(LUA_VANILLA_MD5_2.5 da915d58904e75b9b0fc18147e19b0bb) 96 | set(LUA_VANILLA_SHA1_2.5 7920e12c40242932c22fa261ff114cc485a39d99) 97 | set(LUA_VANILLA_MD5_2.4 5d035cc244285c1dbbcaaa0908b58965) 98 | set(LUA_VANILLA_SHA1_2.4 74036935b36e6ae4ed17bd7a9408154f9a4a6b17) 99 | set(LUA_VANILLA_MD5_2.2 a298b58e197ff8168ec907d6145252ef) 100 | set(LUA_VANILLA_SHA1_2.2 2d8b1df94b2fb76f0f16ca1ddc54d5186b10df4b) 101 | set(LUA_VANILLA_MD5_2.1 053a9f6728cc56f6a23716a6a1ede595) 102 | set(LUA_VANILLA_SHA1_2.1 b9a797547f480bcb58b5d3da846c8ac8d2201df0) 103 | set(LUA_VANILLA_MD5_1.1 9f83141cc8ea362497e272071eda5cf6) 104 | set(LUA_VANILLA_SHA1_1.1 67209701eec5cc633e829d023fbff62d5d6c8e5e) 105 | set(LUA_VANILLA_MD5_1.0 96e8399fc508d128badd8ac3aa8f2119) 106 | set(LUA_VANILLA_SHA1_1.0 6a82d2ae7ce9ad98c7b4824a325b91522c0d6ebb) 107 | 108 | # Clean up some variables 109 | if (LUA_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$") 110 | # probably okay! 111 | set(LUA_VANILLA_VERSION ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}) 112 | elseif (LUA_VERSION MATCHES "([0-9]+)\\.([0-9]+)") 113 | # extend version number with prefix 114 | if (${CMAKE_MATCH_1} EQUAL 5) 115 | if (${CMAKE_MATCH_2} EQUAL 1) 116 | set(LUA_VANILLA_VERSION ${LUA_VANILLA_5.1_LATEST_VERSION}) 117 | elseif (${CMAKE_MATCH_2} EQUAL 2) 118 | set(LUA_VANILLA_VERSION ${LUA_VANILLA_5.2_LATEST_VERSION}) 119 | elseif (${CMAKE_MATCH_2} EQUAL 3) 120 | set(LUA_VANILLA_VERSION ${LUA_VANILLA_5.3_LATEST_VERSION}) 121 | else() 122 | # default to whatever the first two 123 | # numbers happen to be, plus build 0 124 | set(LUA_VANILLA_VERSION ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.0) 125 | endif() 126 | endif() 127 | if(NOT LUA_VANILLA_VERSION) 128 | # default to whatever the first two 129 | # numbers happen to be, plus build 0 130 | set(LUA_VANILLA_VERSION ${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.0) 131 | endif() 132 | else() 133 | message(FATAL_ERROR "Cannot deduce the proper Lua version from ${LUA_VERSION}") 134 | endif() 135 | 136 | #FIND_PACKAGE_MESSAGE(LuaDev 137 | # "Selecting PUC-RIO Lua ${LUA_VANILLA_VERSION} from '${LUA_VERSION}' and building a ${LUA_DEV_LIBRARY_TYPE} library..." 138 | # "[${LUA_VANILLA_VERSION}][${LUA_VERSION}][${LUA_DEV_LIBRARY_TYPE}]") 139 | 140 | # Get Hashes to use for download 141 | set(LUA_VANILLA_SHA1 ${LUA_VANILLA_SHA1_${LUA_VANILLA_VERSION}}) 142 | set(LUA_VANILLA_MD5 ${LUA_VANILLA_MD5_${LUA_VANILLA_VERSION}}) 143 | 144 | if (LUA_VANILLA_MD5) 145 | set(LUA_VANILLA_DOWNLOAD_MD5_COMMAND URL_MD5 ${LUA_VANILLA_MD5}) 146 | else () 147 | set(LUA_VANILLA_DOWNLOAD_MD5_COMMAND "") 148 | endif() 149 | if (LUA_VANILLA_SHA1) 150 | set(LUA_VANILLA_DOWNLOAD_SHA1_COMMAND URL_HASH SHA1=${LUA_VANILLA_SHA1}) 151 | else () 152 | set(LUA_VANILLA_DOWNLOAD_SHA1_COMMAND "") 153 | endif() 154 | 155 | # # # Makefile and self-build configurations 156 | 157 | # # Source files for natural build, if we have to go that far 158 | # retrieve source files 159 | if (LUA_VANILLA_VERSION MATCHES "^5\\.1") 160 | set(LUA_VANILLA_LIB_SOURCES lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c 161 | lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c 162 | lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c 163 | lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c ltablib.c 164 | lstrlib.c loadlib.c linit.c) 165 | set(LUA_VANILLA_LUA_SOURCES lua.c ) 166 | set(LUA_VANILLA_LUAC_SOURCES luac.c print.c ) 167 | set(LUA_VANILLA_GENERATE_LUA_HPP true) 168 | elseif (LUA_VANILLA_VERSION MATCHES "^5\\.2") 169 | set(LUA_VANILLA_LIB_SOURCES lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c 170 | lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c 171 | lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c 172 | lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c 173 | lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c) 174 | set(LUA_VANILLA_LUA_SOURCES lua.c ) 175 | set(LUA_VANILLA_LUAC_SOURCES luac.c ) 176 | set(LUA_VANILLA_GENERATE_LUA_HPP false) 177 | else() 178 | if (NOT LUA_VANILLA_VERSION MATCHES "^5\\.3") 179 | 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") 180 | endif() 181 | set(LUA_VANILLA_LIB_SOURCES lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c 182 | lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c 183 | lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c 184 | lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c lmathlib.c 185 | loslib.c lstrlib.c ltablib.c lutf8lib.c loadlib.c linit.c) 186 | set(LUA_VANILLA_LUA_SOURCES lua.c ) 187 | set(LUA_VANILLA_LUAC_SOURCES luac.c ) 188 | set(LUA_VANILLA_GENERATE_LUA_HPP false) 189 | endif() 190 | 191 | set(LUA_VANILLA_SOURCE_DIR "${LUA_DEV_TOPLEVEL}/src") 192 | prepend(LUA_VANILLA_LIB_SOURCES "${LUA_VANILLA_SOURCE_DIR}/" ${LUA_VANILLA_LIB_SOURCES}) 193 | prepend(LUA_VANILLA_LUA_SOURCES "${LUA_VANILLA_SOURCE_DIR}/" ${LUA_VANILLA_LUA_SOURCES}) 194 | prepend(LUA_VANILLA_LUAC_SOURCES "${LUA_VANILLA_SOURCE_DIR}/" ${LUA_VANILLA_LUAC_SOURCES}) 195 | 196 | # download, just for the sake of download + extract 197 | # have to use 2 different commands just to have an empty command 198 | # that results in nothing being run 199 | # TODO: talk to smarter CMake people...? 200 | 201 | ExternalProject_Add(LUA_VANILLA 202 | BUILD_IN_SOURCE TRUE 203 | BUILD_ALWAYS FALSE 204 | TLS_VERIFY TRUE 205 | PREFIX ${LUA_DEV_TOPLEVEL} 206 | SOURCE_DIR ${LUA_DEV_TOPLEVEL} 207 | DOWNLOAD_DIR ${LUA_DEV_TOPLEVEL} 208 | TMP_DIR "${LUA_DEV_TOPLEVEL}-tmp" 209 | STAMP_DIR "${LUA_DEV_TOPLEVEL}-stamp" 210 | INSTALL_DIR "${LUA_DEV_INSTALL_DIR}" 211 | URL https://www.lua.org/ftp/lua-${LUA_VANILLA_VERSION}.tar.gz 212 | URL_MD5 ${LUA_VANILLA_MD5} 213 | URL_HASH SHA1=${LUA_VANILLA_SHA1} 214 | CONFIGURE_COMMAND "" 215 | BUILD_COMMAND "" 216 | INSTALL_COMMAND "" 217 | TEST_COMMAND "" 218 | BUILD_BYPRODUCTS "${LUA_VANILLA_LIB_SOURCES}" "${LUA_VANILLA_LUA_SOURCES}" "${LUA_VANILLA_LUAC_SOURCES}") 219 | 220 | # make a quick lua.hpp for 5.1 targets that don't have it 221 | if (LUA_VANILLA_GENERATE_LUA_HPP) 222 | set(LUA_VANILLA_LUA_HPP_CONTENT "// lua.hpp 223 | // Lua header files for C++ 224 | // <> not supplied automatically because Lua also compiles as C++ 225 | 226 | extern \"C\" { 227 | #include \"lua.h\" 228 | #include \"lualib.h\" 229 | #include \"lauxlib.h\" 230 | } 231 | ") 232 | set(LUA_VANILLA_SOURCE_LUA_HPP "${LUA_DEV_TOPLEVEL}-tmp/lua.hpp") 233 | set(LUA_VANILLA_DESTINATION_LUA_HPP "${LUA_VANILLA_SOURCE_DIR}/lua.hpp") 234 | file(WRITE "${LUA_VANILLA_SOURCE_LUA_HPP}" "${LUA_VANILLA_LUA_HPP_CONTENT}") 235 | file(TO_NATIVE_PATH "${LUA_VANILLA_SOURCE_LUA_HPP}" LUA_VANILLA_SOURCE_LUA_HPP) 236 | file(TO_NATIVE_PATH "${LUA_VANILLA_DESTINATION_LUA_HPP}" LUA_VANILLA_DESTINATION_LUA_HPP) 237 | ExternalProject_Add_Step(LUA_VANILLA 238 | prebuild 239 | # after download, before build 240 | DEPENDEES download 241 | DEPENDERS build 242 | BYPRODUCTS "${LUA_VANILLA_DESTINATION_LUA_HPP}" 243 | COMMENT "Moving \"${LUA_VANILLA_SOURCE_LUA_HPP}\" to \"${LUA_VANILLA_DESTINATION_LUA_HPP}\"..." 244 | COMMAND "${CMAKE_COMMAND}" -E copy "${LUA_VANILLA_SOURCE_LUA_HPP}" "${LUA_VANILLA_DESTINATION_LUA_HPP}") 245 | endif() 246 | 247 | # # Target names 248 | set(liblua "liblua-${LUA_VANILLA_VERSION}") 249 | set(luainterpreter "lua-${LUA_VANILLA_VERSION}") 250 | set(luacompiler "luac-${LUA_VANILLA_VERSION}") 251 | 252 | # Lua does not out-of-the-box support building 253 | # a shared library: http://lua-users.org/lists/lua-l/2006-10/msg00098.html 254 | # in this case, we essentially need to 255 | # build Lua for our purposes, which is annoying 256 | # the external project is just a dummy to get and extract the file: 257 | # after that, we define actual targets...! 258 | 259 | # make an actual, buildable target 260 | # that other parts of the code can depend on 261 | add_library(${liblua} ${LUA_DEV_LIBRARY_TYPE} "${LUA_VANILLA_LIB_SOURCES}") 262 | set_target_properties(${liblua} 263 | PROPERTIES 264 | LANGUAGE C 265 | LINKER_LANGUAGE C 266 | C_STANDARD 99 267 | C_EXTENSIONS TRUE 268 | POSITION_INDEPENDENT_CODE TRUE 269 | INCLUDE_DIRECTORIES ${LUA_VANILLA_SOURCE_DIR} 270 | OUTPUT_NAME ${LUA_DEV_LIBNAME} 271 | RUNTIME_OUTPUT_NAME ${LUA_DEV_LIBNAME} 272 | LIBRARY_OUTPUT_NAME ${LUA_DEV_LIBNAME} 273 | ARCHIVE_OUTPUT_NAME ${LUA_DEV_LIBNAME}) 274 | target_include_directories(${liblua} 275 | PUBLIC ${LUA_VANILLA_SOURCE_DIR}) 276 | target_compile_definitions(${liblua} 277 | PUBLIC LUA_COMPAT_ALL) 278 | get_target_property(lualib_target_type ${liblua} TYPE) 279 | if (lualib_target_type STREQUAL "SHARED_LIBRARY") 280 | if (WIN32) 281 | target_compile_definitions(${liblua} 282 | PUBLIC LUA_BUILD_AS_DLL) 283 | endif() 284 | endif () 285 | if (WIN32) 286 | #target_compile_definitions(${liblua} 287 | # PRIVATE LUA_USE_WINDOWS) 288 | else() 289 | target_compile_definitions(${liblua} 290 | PRIVATE LUA_USE_LINUX) 291 | endif() 292 | target_compile_options(${liblua} 293 | PRIVATE ${LUA_VANILLA_LUALIB_COMPILER_OPTIONS}) 294 | add_dependencies(${liblua} LUA_VANILLA) 295 | if (CMAKE_DL_LIBS) 296 | target_link_libraries(${liblua} ${CMAKE_DL_LIBS}) 297 | endif() 298 | if (UNIX) 299 | target_link_libraries(${liblua} m) 300 | endif() 301 | 302 | # we don't really need this section... 303 | # Lua Interpreter 304 | add_executable(${luainterpreter} ${LUA_VANILLA_LUA_SOURCES}) 305 | set_target_properties(${luainterpreter} 306 | PROPERTIES 307 | LANGUAGE C 308 | LINKER_LANGUAGE C 309 | C_STANDARD 99 310 | C_EXTENSIONS TRUE 311 | OUTPUT_NAME lua-${LUA_VANILLA_VERSION}) 312 | target_include_directories(${luainterpreter} 313 | PRIVATE ${LUA_VANILLA_SOURCE_DIR}) 314 | target_compile_definitions(${luainterpreter} 315 | PUBLIC LUA_COMPAT_ALL ${LUA_VANILLA_DLL_DEFINE} 316 | PRIVATE LUA_COMPAT_ALL ${LUA_VANILLA_DLL_DEFINE}) 317 | if (WIN32) 318 | #target_compile_definitions(${luainterpreter} 319 | # PRIVATE LUA_USE_WINDOWS) 320 | else() 321 | target_compile_definitions(${luainterpreter} 322 | PRIVATE LUA_USE_LINUX) 323 | endif() 324 | target_link_libraries(${luainterpreter} ${liblua}) 325 | if (CMAKE_DL_LIBS) 326 | target_link_libraries(${luainterpreter} ${CMAKE_DL_LIBS}) 327 | endif() 328 | if (UNIX) 329 | target_link_libraries(${luainterpreter} m readline) 330 | endif() 331 | 332 | # LuaC Compiler 333 | add_executable(${luacompiler} ${LUA_VANILLA_LUAC_SOURCES}) 334 | if (lualib_target_type STREQUAL "SHARED_LIBRARY") 335 | # TODO: figure out how to make DLL internal symbols for lua public so we don't have to do this 336 | target_sources(${luacompiler} PRIVATE ${LUA_VANILLA_LIB_SOURCES}) 337 | endif() 338 | set_target_properties(${luacompiler} 339 | PROPERTIES 340 | LANGUAGE C 341 | LINKER_LANGUAGE C 342 | C_STANDARD 99 343 | C_EXTENSIONS TRUE 344 | OUTPUT_NAME luac-${LUA_VANILLA_VERSION}) 345 | target_include_directories(${luacompiler} 346 | PRIVATE ${LUA_VANILLA_SOURCE_DIR}) 347 | target_compile_definitions(${luacompiler} 348 | PUBLIC LUA_COMPAT_ALL ${LUA_VANILLA_DLL_DEFINE} 349 | PRIVATE LUA_COMPAT_ALL ${LUA_VANILLA_DLL_DEFINE}) 350 | if (WIN32) 351 | #target_compile_definitions(${luacompiler} 352 | # PRIVATE LUA_USE_WINDOWS) 353 | else() 354 | target_compile_definitions(${luacompiler} 355 | PRIVATE LUA_USE_LINUX) 356 | endif() 357 | target_link_libraries(${luacompiler} ${liblua}) 358 | if (CMAKE_DL_LIBS) 359 | target_link_libraries(${luacompiler} ${CMAKE_DL_LIBS}) 360 | endif() 361 | if (UNIX) 362 | # TODO: make readline optional? 363 | target_link_libraries(${luacompiler} m readline) 364 | endif() 365 | 366 | # set externally-visible target indicator 367 | set(LUA_LIBRARIES ${liblua}) 368 | set(LUA_INTERPRETER ${luainterpreter}) 369 | set(LUA_COMPILER ${luacompiler}) 370 | set(LUA_INCLUDE_DIRS "${LUA_VANILLA_SOURCE_DIR}") 371 | -------------------------------------------------------------------------------- /cmake/Modules/FindLuaIntfDev.cmake: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright � 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | include(ExternalProject) 24 | include(FindPackageHandleStandardArgs) 25 | include(Common/Core) 26 | 27 | # # Base variables 28 | set(luaintf_version 1.0.0) 29 | set(luaintf_lib luaintf_lib_${luaintf_version}) 30 | 31 | # # Useful locations 32 | set(luaintf_dev_toplevel "${CMAKE_BINARY_DIR}/vendor/luaintf_${luaintf_version}") 33 | set(luaintf_include_dirs "${luaintf_dev_toplevel}/") 34 | 35 | # # luaintf library sources 36 | set(luaintf_sources LuaIntf.h) 37 | prepend(luaintf_sources "${luaintf_dev_toplevel}/LuaIntf/" ${luaintf_sources}) 38 | 39 | # # External project to get sources 40 | ExternalProject_Add(LUAINTFDEV_SOURCE 41 | BUILD_IN_SOURCE TRUE 42 | BUILD_ALWAYS FALSE 43 | # # Use Git to get what we need 44 | GIT_SHALLOW TRUE 45 | #GIT_TAG e513907fc8c2d59ebd91cd5992eddf54f7e23e21 46 | GIT_REPOSITORY https://github.com/SteveKChiu/lua-intf.git 47 | PREFIX ${luaintf_dev_toplevel} 48 | SOURCE_DIR ${luaintf_dev_toplevel} 49 | DOWNLOAD_DIR ${luaintf_dev_toplevel} 50 | TMP_DIR "${luaintf_dev_toplevel}-tmp" 51 | STAMP_DIR "${luaintf_dev_toplevel}-stamp" 52 | INSTALL_DIR "${luaintf_dev_toplevel}/local" 53 | CONFIGURE_COMMAND "" 54 | BUILD_COMMAND "" 55 | INSTALL_COMMAND "" 56 | TEST_COMMAND "" 57 | BUILD_BYPRODUCTS "${luaintf_sources}") 58 | 59 | add_library(${luaintf_lib} INTERFACE) 60 | add_dependencies(${luaintf_lib} LUAINTFDEV_SOURCE) 61 | target_include_directories(${luaintf_lib} INTERFACE ${luaintf_include_dirs}) 62 | target_link_libraries(${luaintf_lib} INTERFACE ${LUA_LIBRARIES}) 63 | target_compile_definitions(${luaintf_lib} 64 | INTERFACE 65 | "LUAINTF_HEADERS_ONLY=1" 66 | "LUAINTF_LINK_LUA_COMPILED_IN_CXX=0" 67 | ) 68 | if (NOT MSVC) 69 | target_compile_options(${luaintf_lib} INTERFACE 70 | -Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter) 71 | endif() 72 | 73 | set(LUAINTFDEV_FOUND TRUE) 74 | set(LUAINTF_LIBRARIES ${luaintf_lib}) 75 | set(LUAINTF_INCLUDE_DIRS ${luaintf_include_dirs}) 76 | 77 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaIntfDev 78 | FOUND_VAR LUAINTFDEV_FOUND 79 | REQUIRED_VARS LUAINTF_LIBRARIES LUAINTF_INCLUDE_DIRS 80 | VERSION_VAR luaintf_version) 81 | -------------------------------------------------------------------------------- /cmake/Modules/FindLuabindDev.cmake: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright � 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | # # Standard CMake Libraries 24 | include(ExternalProject) 25 | include(FindPackageHandleStandardArgs) 26 | include(Common/Core) 27 | 28 | # # Base variables 29 | set(luabind_version 0.9.0) 30 | 31 | # # Useful locations 32 | set(luabind_dev_toplevel "${CMAKE_BINARY_DIR}/vendor/luabind_${luabind_version}") 33 | set(luabind_include_dirs "${luabind_dev_toplevel}/") 34 | 35 | # # Luabind library sources 36 | set(luabind_sources 37 | class.cpp 38 | class_info.cpp 39 | class_registry.cpp 40 | class_rep.cpp 41 | create_class.cpp 42 | error.cpp 43 | exception_handler.cpp 44 | function.cpp 45 | function_introspection.cpp 46 | inheritance.cpp 47 | link_compatibility.cpp 48 | object_rep.cpp 49 | open.cpp 50 | operator.cpp 51 | pcall.cpp 52 | scope.cpp 53 | set_package_preload.cpp 54 | stack_content_by_name.cpp 55 | weak_ref.cpp 56 | wrapper_base.cpp 57 | ) 58 | 59 | prepend(luabind_sources "${luabind_dev_toplevel}/src/" ${luabind_sources}) 60 | 61 | # # External project to get sources 62 | ExternalProject_Add(LUABIND_DEV_SOURCE 63 | BUILD_IN_SOURCE TRUE 64 | BUILD_ALWAYS TRUE 65 | # # Use Git to get what we need 66 | #GIT_SUBMODULES "" 67 | GIT_SHALLOW TRUE 68 | GIT_REPOSITORY https://github.com/WohlSoft/luabind-deboostified.git 69 | PREFIX ${luabind_dev_toplevel} 70 | SOURCE_DIR ${luabind_dev_toplevel} 71 | DOWNLOAD_DIR ${luabind_dev_toplevel} 72 | TMP_DIR "${luabind_dev_toplevel}-tmp" 73 | STAMP_DIR "${luabind_dev_toplevel}-stamp" 74 | INSTALL_DIR "${luabind_dev_toplevel}/local" 75 | CONFIGURE_COMMAND "" 76 | BUILD_COMMAND "" 77 | INSTALL_COMMAND "" 78 | TEST_COMMAND "" 79 | BUILD_BYPRODUCTS "${luabind_sources}") 80 | 81 | set(luabind_lib luabind_lib_${luabind_version}) 82 | add_library(${luabind_lib} "${luabind_sources}") 83 | add_dependencies(${luabind_lib} LUABIND_DEV_SOURCE) 84 | set_target_properties(${luabind_lib} PROPERTIES 85 | OUTPUT_NAME luabind-${luabind_version} 86 | LANGUAGE CXX 87 | LINKER_LANGUAGE CXX 88 | POSITION_INDEPENDENT_CODE TRUE) 89 | target_include_directories(${luabind_lib} 90 | PUBLIC ${luabind_include_dirs}) 91 | target_link_libraries(${luabind_lib} PRIVATE ${LUA_LIBRARIES}) 92 | get_target_property(luabind_lib_shared ${luabind_lib} TYPE) 93 | #target_compile_definitions(${luabind_lib} 94 | # PRIVATE 95 | # "LUABIND_BUILDING=1" 96 | #) 97 | if (luabind_lib_shared MATCHES "SHARED") 98 | target_compile_definitions(${luabind_lib} 99 | PUBLIC 100 | "LUABIND_DYNAMIC_LINK=1" 101 | ) 102 | endif() 103 | target_compile_definitions(${luabind_lib} 104 | PUBLIC 105 | $<$:LUABIND_NO_ERROR_CHECKING=1> 106 | $<$:LUABIND_NO_ERROR_CHECKING=1> 107 | $<$:LUABIND_NO_ERROR_CHECKING=1> 108 | ) 109 | 110 | if (CMAKE_DL_LIBS) 111 | target_link_libraries(${luabind_lib} PRIVATE ${CMAKE_DL_LIBS}) 112 | endif() 113 | 114 | # # Variables required by Luabind 115 | set(LUABIND_LIBRARIES ${luabind_lib}) 116 | set(LUABIND_INCLUDE_DIRS ${luabind_include_dirs}) 117 | set(LUABINDDEV_FOUND TRUE) 118 | 119 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuabindDev 120 | FOUND_VAR LUABINDDEV_FOUND 121 | REQUIRED_VARS LUABIND_LIBRARIES LUABIND_INCLUDE_DIRS 122 | VERSION_VAR luabind_version) 123 | -------------------------------------------------------------------------------- /cmake/Modules/FindLuacppInterface.cmake: -------------------------------------------------------------------------------- 1 | 2 | # # lua bindings shootout 3 | # The MIT License (MIT) 4 | # 5 | # Copyright � 2018 ThePhD 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | # this software and associated documentation files (the "Software"), to deal in 9 | # the Software without restriction, including without limitation the rights to 10 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | # the Software, and to permit persons to whom the Software is furnished to do so, 12 | # subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in all 15 | # copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | include(ExternalProject) 25 | include(FindPackageHandleStandardArgs) 26 | include(Common/Core) 27 | 28 | # # Base variables 29 | set(luacppinterface_version 1.3.0) 30 | set(luacppinterface_lib luacppinterface_lib_${luacppinterface_version}) 31 | 32 | # # Useful locations 33 | set(luacppinterface_dev_toplevel "${CMAKE_BINARY_DIR}/vendor/luacppinterface_${luacppinterface_version}") 34 | set(luacppinterface_include_dirs "${luacppinterface_dev_toplevel}") 35 | 36 | # # luacppinterface library sources 37 | set(luacppinterface_sources 38 | "LuaCppInterface/luacoroutine.cpp" 39 | "LuaCppInterface/luacppinterface.cpp" 40 | "LuaCppInterface/luafunction.cpp" 41 | "LuaCppInterface/luareference.cpp" 42 | "LuaCppInterface/luatable.cpp" 43 | "LuaCppInterface/luaerror.cpp" 44 | 45 | "LuaCppInterface/luacoroutine.h" 46 | "LuaCppInterface/luacppinterface.h" 47 | "LuaCppInterface/luafunction.h" 48 | "LuaCppInterface/luafunctionbase.h" 49 | "LuaCppInterface/luageneralgenericfunctions.h" 50 | "LuaCppInterface/luagenericfunction.h" 51 | "LuaCppInterface/lualightuserdata.h" 52 | "LuaCppInterface/luareference.h" 53 | "LuaCppInterface/luatable.h" 54 | "LuaCppInterface/luatype.h" 55 | "LuaCppInterface/luatypetemplates.h" 56 | "LuaCppInterface/luauserdata.h" 57 | "LuaCppInterface/luauserdatabindtemplates.h" 58 | "LuaCppInterface/luauserdataforwards.h" 59 | "LuaCppInterface/luavoidgenericfunctions.h" 60 | ) 61 | prepend(luacppinterface_sources "${luacppinterface_dev_toplevel}/" ${luacppinterface_sources}) 62 | 63 | # # External project to get sources 64 | ExternalProject_Add(LUACPPINTERFACEDEV_SOURCE 65 | BUILD_IN_SOURCE TRUE 66 | BUILD_ALWAYS FALSE 67 | # # Use Git to get what we need 68 | GIT_SHALLOW TRUE 69 | GIT_SUBMODULES "" 70 | GIT_REPOSITORY https://github.com/davidsiaw/luacppinterface.git 71 | PREFIX ${luacppinterface_dev_toplevel} 72 | SOURCE_DIR ${luacppinterface_dev_toplevel} 73 | DOWNLOAD_DIR ${luacppinterface_dev_toplevel} 74 | TMP_DIR "${luacppinterface_dev_toplevel}-tmp" 75 | STAMP_DIR "${luacppinterface_dev_toplevel}-stamp" 76 | INSTALL_DIR "${luacppinterface_dev_toplevel}/local" 77 | CONFIGURE_COMMAND "" 78 | BUILD_COMMAND "" 79 | INSTALL_COMMAND "" 80 | TEST_COMMAND "" 81 | BUILD_BYPRODUCTS "${luacppinterface_sources}") 82 | 83 | add_library(${luacppinterface_lib} STATIC ${luacppinterface_sources}) 84 | add_dependencies(${luacppinterface_lib} LUACPPINTERFACEDEV_SOURCE) 85 | target_include_directories(${luacppinterface_lib} INTERFACE ${luacppinterface_include_dirs}) 86 | if (NOT MSVC) 87 | target_compile_options(${luacppinterface_lib} INTERFACE 88 | -Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter) 89 | endif() 90 | target_link_libraries(${luacppinterface_lib} 91 | PUBLIC ${LUA_LIBRARIES} 92 | ) 93 | if (CMAKE_DL_LIBS) 94 | target_link_libraries(${luacppinterface_lib} 95 | PRIVATE ${CMAKE_DL_LIBS} 96 | ) 97 | endif() 98 | 99 | set(LUACPPINTERFACEDEV_FOUND TRUE) 100 | set(LUACPPINTERFACE_LIBRARIES ${luacppinterface_lib}) 101 | set(LUACPPINTERFACE_INCLUDE_DIRS ${luacppinterface_include_dirs}) 102 | 103 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaCppInterfaceDev 104 | FOUND_VAR LUACPPINTERFACEDEV_FOUND 105 | REQUIRED_VARS LUACPPINTERFACE_LIBRARIES LUACPPINTERFACE_INCLUDE_DIRS 106 | VERSION_VAR luacppinterface_version) -------------------------------------------------------------------------------- /cmake/Modules/FindLuawrapper.cmake: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright � 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | include(ExternalProject) 24 | include(FindPackageHandleStandardArgs) 25 | include(Common/Core) 26 | 27 | # # Base variables 28 | set(luawrapper_version 0.5.0) 29 | set(luawrapper_lib luawrapper_lib_${luawrapper_version}) 30 | 31 | # # Useful locations 32 | set(luawrapper_dev_toplevel "${CMAKE_BINARY_DIR}/vendor/luawrapper_${luawrapper_version}") 33 | set(luawrapper_include_dirs "${luawrapper_dev_toplevel}/include") 34 | 35 | # # luawrapper library sources 36 | set(luawrapper_sources LuaContext.hpp) 37 | prepend(luawrapper_sources "${luawrapper_dev_toplevel}/include/" ${luawrapper_sources}) 38 | 39 | # # External project to get sources 40 | ExternalProject_Add(LUAWRAPPERDEV_SOURCE 41 | BUILD_IN_SOURCE TRUE 42 | BUILD_ALWAYS FALSE 43 | # # Use Git to get what we need 44 | GIT_SHALLOW TRUE 45 | GIT_REPOSITORY https://github.com/ahupowerdns/luawrapper.git 46 | PREFIX ${luawrapper_dev_toplevel} 47 | SOURCE_DIR ${luawrapper_dev_toplevel} 48 | DOWNLOAD_DIR ${luawrapper_dev_toplevel} 49 | TMP_DIR "${luawrapper_dev_toplevel}-tmp" 50 | STAMP_DIR "${luawrapper_dev_toplevel}-stamp" 51 | INSTALL_DIR "${luawrapper_dev_toplevel}/local" 52 | CONFIGURE_COMMAND "" 53 | BUILD_COMMAND "" 54 | INSTALL_COMMAND "" 55 | TEST_COMMAND "" 56 | BUILD_BYPRODUCTS "${luawrapper_sources}") 57 | 58 | find_package(Boost REQUIRED) 59 | 60 | add_library(${luawrapper_lib} INTERFACE) 61 | add_dependencies(${luawrapper_lib} LUAWRAPPERDEV_SOURCE) 62 | target_include_directories(${luawrapper_lib} INTERFACE ${luawrapper_include_dirs}) 63 | target_link_libraries(${luawrapper_lib} INTERFACE ${LUA_LIBRARIES}) 64 | if (NOT MSVC) 65 | target_compile_options(${luawrapper_lib} INTERFACE 66 | -Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter) 67 | endif() 68 | target_link_libraries(${luawrapper_lib} 69 | INTERFACE ${Boost_LIBRARIES} 70 | ) 71 | target_include_directories(${luawrapper_lib} 72 | INTERFACE ${Boost_INCLUDE_DIRS} 73 | ) 74 | 75 | set(LUAWRAPPERDEV_FOUND TRUE) 76 | set(LUAWRAPPER_LIBRARIES ${luawrapper_lib}) 77 | set(LUAWRAPPER_INCLUDE_DIRS ${luawrapper_include_dirs}) 78 | 79 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuawrapperDev 80 | FOUND_VAR LUAWRAPPERDEV_FOUND 81 | REQUIRED_VARS LUAWRAPPER_LIBRARIES LUAWRAPPER_INCLUDE_DIRS 82 | VERSION_VAR luawrapper_version) 83 | -------------------------------------------------------------------------------- /cmake/Modules/FindLuwraDev.cmake: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright � 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | include(ExternalProject) 24 | include(FindPackageHandleStandardArgs) 25 | include(Common/Core) 26 | 27 | # # Base variables 28 | set(luwra_version 0.5.0) 29 | set(luwra_lib luwra_lib_${luwra_version}) 30 | 31 | # # Useful locations 32 | set(luwra_dev_toplevel "${CMAKE_BINARY_DIR}/vendor/luwra_${luwra_version}") 33 | set(luwra_include_dirs "${luwra_dev_toplevel}/lib") 34 | 35 | # # luwra library sources 36 | set(luwra_sources luwra.hpp) 37 | prepend(luwra_sources "${luwra_dev_toplevel}/lib/" ${luwra_sources}) 38 | 39 | # # External project to get sources 40 | ExternalProject_Add(LUWRADEV_SOURCE 41 | BUILD_IN_SOURCE TRUE 42 | BUILD_ALWAYS FALSE 43 | # # Use Git to get what we need 44 | GIT_SHALLOW TRUE 45 | #GIT_TAG e513907fc8c2d59ebd91cd5992eddf54f7e23e21 46 | GIT_REPOSITORY https://github.com/vapourismo/luwra.git 47 | PREFIX ${luwra_dev_toplevel} 48 | SOURCE_DIR ${luwra_dev_toplevel} 49 | DOWNLOAD_DIR ${luwra_dev_toplevel} 50 | TMP_DIR "${luwra_dev_toplevel}-tmp" 51 | STAMP_DIR "${luwra_dev_toplevel}-stamp" 52 | INSTALL_DIR "${luwra_dev_toplevel}/local" 53 | CONFIGURE_COMMAND "" 54 | BUILD_COMMAND "" 55 | INSTALL_COMMAND "" 56 | TEST_COMMAND "" 57 | BUILD_BYPRODUCTS "${luwra_sources}") 58 | 59 | add_library(${luwra_lib} INTERFACE) 60 | add_dependencies(${luwra_lib} LUWRADEV_SOURCE) 61 | target_include_directories(${luwra_lib} INTERFACE ${luwra_include_dirs}) 62 | target_link_libraries(${luwra_lib} INTERFACE ${LUA_LIBRARIES}) 63 | if (NOT MSVC) 64 | target_compile_options(${luwra_lib} INTERFACE 65 | -Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter) 66 | endif() 67 | 68 | set(LUWRADEV_FOUND TRUE) 69 | set(LUWRA_LIBRARIES ${luwra_lib}) 70 | set(LUWRA_INCLUDE_DIRS ${luwra_include_dirs}) 71 | 72 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuwraDev 73 | FOUND_VAR LUWRADEV_FOUND 74 | REQUIRED_VARS LUWRA_LIBRARIES LUWRA_INCLUDE_DIRS 75 | VERSION_VAR luwra_version) 76 | -------------------------------------------------------------------------------- /cmake/Modules/FindOOLuaDev.cmake: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright � 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | # # Standard CMake Libraries 24 | include(ExternalProject) 25 | include(FindPackageHandleStandardArgs) 26 | include(Common/Core) 27 | 28 | # # Base variables 29 | set(oolua_version 2.0.1) 30 | 31 | # # Useful locations 32 | set(oolua_dev_toplevel "${CMAKE_BINARY_DIR}/vendor/oolua_${oolua_version}") 33 | set(oolua_include_dirs "${oolua_dev_toplevel}/include") 34 | 35 | # # OOLua library sources 36 | set(oolua_sources 37 | src/class_from_stack.cpp 38 | src/oolua.cpp 39 | src/oolua_check_result.cpp 40 | src/oolua_chunk.cpp 41 | src/oolua_error.cpp 42 | src/oolua_exception.cpp 43 | src/oolua_function.cpp 44 | src/oolua_helpers.cpp 45 | src/oolua_open.cpp 46 | src/oolua_pull.cpp 47 | src/oolua_push.cpp 48 | src/oolua_ref.cpp 49 | src/oolua_registration.cpp 50 | src/oolua_script.cpp 51 | src/oolua_stack_dump.cpp 52 | src/oolua_string.cpp 53 | src/oolua_table.cpp 54 | src/proxy_storage.cpp 55 | src/push_pointer_internal.cpp 56 | src/stack_get.cpp 57 | ) 58 | prepend(oolua_sources "${oolua_dev_toplevel}/" ${oolua_sources}) 59 | #file(GLOB_RECURSE oolua_sources 60 | # LIST_DIRECTORIES false 61 | # "${oolua_dev_toplevel}/src/*.cpp" 62 | # "${oolua_dev_toplevel}/src/*.c" 63 | #) 64 | #list(APPEND oolua_sources "${oolua_dev_toplevel}/include/oolua.h") 65 | 66 | # # External project to get sources 67 | ExternalProject_Add(OOLUA_DEV_SOURCE 68 | BUILD_IN_SOURCE TRUE 69 | BUILD_ALWAYS TRUE 70 | # # Use Git to get what we need 71 | #GIT_SUBMODULES "" 72 | GIT_SHALLOW TRUE 73 | GIT_REPOSITORY https://github.com/ThePhD/oolua.git 74 | PREFIX ${oolua_dev_toplevel} 75 | SOURCE_DIR ${oolua_dev_toplevel} 76 | DOWNLOAD_DIR ${oolua_dev_toplevel} 77 | TMP_DIR "${oolua_dev_toplevel}-tmp" 78 | STAMP_DIR "${oolua_dev_toplevel}-stamp" 79 | INSTALL_DIR "${oolua_dev_toplevel}/local" 80 | CONFIGURE_COMMAND "" 81 | BUILD_COMMAND "" 82 | INSTALL_COMMAND "" 83 | TEST_COMMAND "" 84 | BUILD_BYPRODUCTS "${oolua_sources}") 85 | 86 | set(oolua_lib oolua_lib_${oolua_version}) 87 | add_library(${oolua_lib} STATIC ${oolua_sources}) 88 | add_dependencies(${oolua_lib} OOLUA_DEV_SOURCE) 89 | set_target_properties(${oolua_lib} PROPERTIES 90 | OUTPUT_NAME oolua-${oolua_version} 91 | LANGUAGE CXX 92 | LINKER_LANGUAGE CXX 93 | POSITION_INDEPENDENT_CODE TRUE) 94 | target_include_directories(${oolua_lib} 95 | PUBLIC ${oolua_include_dirs}) 96 | target_link_libraries(${oolua_lib} PRIVATE ${LUA_LIBRARIES}) 97 | target_compile_definitions(${oolua_lib} 98 | PUBLIC 99 | "OOLUA_USE_EXCEPTIONS=0" 100 | "OOLUA_RUNTIME_CHECKS_ENABLED=0" 101 | ) 102 | if (MSVC) 103 | 104 | else() 105 | target_compile_options(${oolua_lib} 106 | PRIVATE -w 107 | PUBLIC -Wno-unused-parameter 108 | ) 109 | endif() 110 | if (CMAKE_DL_LIBS) 111 | target_link_libraries(${oolua_lib} PRIVATE ${CMAKE_DL_LIBS}) 112 | endif() 113 | 114 | # # Variables required by OOLua 115 | set(OOLUA_LIBRARIES ${oolua_lib}) 116 | set(OOLUA_INCLUDE_DIRS ${oolua_include_dirs}) 117 | set(OOLUADEV_FOUND TRUE) 118 | 119 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(OOLuaDev 120 | FOUND_VAR OOLUADEV_FOUND 121 | REQUIRED_VARS OOLUA_LIBRARIES OOLUA_INCLUDE_DIRS 122 | VERSION_VAR oolua_version) 123 | -------------------------------------------------------------------------------- /cmake/Modules/FindSeleneDev.cmake: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright � 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | include(ExternalProject) 24 | include(FindPackageHandleStandardArgs) 25 | include(Common/Core) 26 | 27 | # # Base variables 28 | set(selene_version 0.4.0) 29 | set(selene_lib selene_lib_${selene_version}) 30 | 31 | # # Useful locations 32 | set(selene_dev_toplevel "${CMAKE_BINARY_DIR}/vendor/selene_${selene_version}") 33 | set(selene_include_dirs "${selene_dev_toplevel}/include") 34 | 35 | # # selene library sources 36 | set(selene_sources selene.h) 37 | prepend(selene_sources "${selene_dev_toplevel}/include/" ${selene_sources}) 38 | 39 | # # External project to get sources 40 | ExternalProject_Add(SELENEDEV_SOURCE 41 | BUILD_IN_SOURCE TRUE 42 | BUILD_ALWAYS FALSE 43 | # # Use Git to get what we need 44 | GIT_SHALLOW TRUE 45 | GIT_REPOSITORY https://github.com/ThePhD/selene 46 | PREFIX ${selene_dev_toplevel} 47 | SOURCE_DIR ${selene_dev_toplevel} 48 | DOWNLOAD_DIR ${selene_dev_toplevel} 49 | TMP_DIR "${selene_dev_toplevel}-tmp" 50 | STAMP_DIR "${selene_dev_toplevel}-stamp" 51 | INSTALL_DIR "${selene_dev_toplevel}/local" 52 | CONFIGURE_COMMAND "" 53 | BUILD_COMMAND "" 54 | INSTALL_COMMAND "" 55 | TEST_COMMAND "" 56 | BUILD_BYPRODUCTS "${selene_sources}") 57 | 58 | add_library(${selene_lib} INTERFACE) 59 | add_dependencies(${selene_lib} SELENEDEV_SOURCE) 60 | target_include_directories(${selene_lib} INTERFACE ${selene_include_dirs}) 61 | target_link_libraries(${selene_lib} INTERFACE ${LUA_LIBRARIES}) 62 | if (NOT MSVC) 63 | target_compile_options(${selene_lib} INTERFACE 64 | -Wno-noexcept-type -Wno-ignored-qualifiers -Wno-unused-parameter) 65 | endif() 66 | 67 | set(SELENEDEV_FOUND TRUE) 68 | set(SELENE_LIBRARIES ${selene_lib}) 69 | set(SELENE_INCLUDE_DIRS ${selene_include_dirs}) 70 | 71 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(SeleneDev 72 | FOUND_VAR SELENEDEV_FOUND 73 | REQUIRED_VARS SELENE_LIBRARIES SELENE_INCLUDE_DIRS 74 | VERSION_VAR selene_version) 75 | -------------------------------------------------------------------------------- /cmake/Modules/FindToLuappDev.cmake: -------------------------------------------------------------------------------- 1 | # # lua bindings shootout 2 | # The MIT License (MIT) 3 | # 4 | # Copyright � 2018 ThePhD 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | # this software and associated documentation files (the "Software"), to deal in 8 | # the Software without restriction, including without limitation the rights to 9 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | # the Software, and to permit persons to whom the Software is furnished to do so, 11 | # subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | # # Standard CMake Libraries 24 | include(ExternalProject) 25 | include(FindPackageHandleStandardArgs) 26 | include(Common/Core) 27 | 28 | # # Base variables 29 | set(toluapp_version 1.0.93) 30 | 31 | # # Useful locations 32 | set(toluapp_dev_toplevel "${CMAKE_BINARY_DIR}/vendor/toluapp_${toluapp_version}") 33 | set(toluapp_include_dirs "${toluapp_dev_toplevel}/include") 34 | 35 | # # ToLua library sources 36 | set(toluapp_sources tolua_event.c tolua_event.h tolua_is.c tolua_map.c tolua_push.c tolua_to.c tolua_compat.h tolua_compat.c) 37 | prepend(toluapp_sources "${toluapp_dev_toplevel}/src/lib/" ${toluapp_sources}) 38 | list(APPEND toluapp_sources "${toluapp_dev_toplevel}/include/tolua++.h") 39 | 40 | # # External project to get sources 41 | ExternalProject_Add(TOLUAPP_DEV_SOURCE 42 | BUILD_IN_SOURCE TRUE 43 | BUILD_ALWAYS TRUE 44 | # # Use Git to get what we need 45 | #GIT_SUBMODULES "" 46 | GIT_SHALLOW TRUE 47 | GIT_REPOSITORY https://github.com/ThePhD/toluapp.git 48 | PREFIX ${toluapp_dev_toplevel} 49 | SOURCE_DIR ${toluapp_dev_toplevel} 50 | DOWNLOAD_DIR ${toluapp_dev_toplevel} 51 | TMP_DIR "${toluapp_dev_toplevel}-tmp" 52 | STAMP_DIR "${toluapp_dev_toplevel}-stamp" 53 | INSTALL_DIR "${toluapp_dev_toplevel}/local" 54 | CONFIGURE_COMMAND "" 55 | BUILD_COMMAND "" 56 | INSTALL_COMMAND "" 57 | TEST_COMMAND "" 58 | BUILD_BYPRODUCTS "${toluapp_sources}") 59 | 60 | set(toluapp_lib toluapp_lib_${toluapp_version}) 61 | add_library(${toluapp_lib} SHARED ${toluapp_sources}) 62 | add_dependencies(${toluapp_lib} TOLUAPP_DEV_SOURCE) 63 | set_target_properties(${toluapp_lib} PROPERTIES 64 | OUTPUT_NAME toluapp-${toluapp_version} 65 | POSITION_INDEPENDENT_CODE TRUE) 66 | target_include_directories(${toluapp_lib} 67 | PUBLIC ${toluapp_include_dirs}) 68 | target_link_libraries(${toluapp_lib} PRIVATE ${LUA_LIBRARIES}) 69 | if (MSVC) 70 | target_compile_definitions(${toluapp_lib} 71 | PRIVATE 72 | "TOLUA_API=__declspec(dllexport)" 73 | "_CRT_SECURE_NO_WARNINGS=1" 74 | INTERFACE 75 | "TOLUA_API=__declspec(dllimport)" 76 | ) 77 | else() 78 | target_compile_definitions(${toluapp_lib} 79 | PRIVATE "TOLUA_API=" 80 | INTERFACE "TOLUA_API=" 81 | ) 82 | endif() 83 | if (CMAKE_DL_LIBS) 84 | target_link_libraries(${toluapp_lib} PRIVATE ${CMAKE_DL_LIBS}) 85 | endif() 86 | # add compatibility define 87 | target_compile_definitions(${toluapp_lib} 88 | PRIVATE COMPAT53_PREFIX=toluapp_compat53) 89 | 90 | # # Variables required by ToLuapp 91 | set(TOLUAPP_LIBRARIES ${toluapp_lib}) 92 | set(TOLUAPP_INCLUDE_DIRS ${toluapp_include_dirs}) 93 | set(TOLUAPPDEV_FOUND TRUE) 94 | 95 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(ToLuappDev 96 | FOUND_VAR TOLUAPPDEV_FOUND 97 | REQUIRED_VARS TOLUAPP_LIBRARIES TOLUAPP_INCLUDE_DIRS 98 | VERSION_VAR toluapp_version) 99 | -------------------------------------------------------------------------------- /source/benchmark.hpp: -------------------------------------------------------------------------------- 1 | // lua bindings shootout 2 | // The MIT License (MIT) 3 | 4 | // Copyright © 2018 ThePhD 5 | 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | // this software and associated documentation files (the "Software"), to deal in 8 | // the Software without restriction, including without limitation the rights to 9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | // the Software, and to permit persons to whom the Software is furnished to do so, 11 | // subject to the following conditions: 12 | 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | #pragma once 24 | 25 | #ifndef LUA_BINDINGS_SHOOTOUT_BENCHMARK_HPP 26 | #define LUA_BINDINGS_SHOOTOUT_BENCHMARK_HPP 27 | 28 | #include 29 | 30 | namespace lbs { 31 | template 32 | inline void expect(benchmark::State& benchmark_state, const T& left, const U& right) { 33 | if (left != right) { 34 | benchmark_state.SkipWithError("unexpected result"); 35 | } 36 | } 37 | 38 | inline void unsupported(benchmark::State& benchmark_state, const char* message) { 39 | benchmark_state.SkipWithError(message); 40 | } 41 | 42 | inline void unsupported(benchmark::State& benchmark_state) { 43 | unsupported(benchmark_state, "unsupported"); 44 | } 45 | 46 | inline const std::size_t repetition() { 47 | #if defined(LUA_BINDINGS_SHOOTOUT_LUA_REPETITIONS) 48 | static const std::size_t value = LUA_BINDINGS_SHOOTOUT_LUA_REPETITIONS; 49 | #else 50 | static const std::size_t value = 50; 51 | #endif 52 | return value; 53 | } 54 | 55 | inline const std::string& repetition_s() { 56 | static const std::string value = std::to_string(repetition()); 57 | return value; 58 | } 59 | 60 | inline std::string repeated_code(std::string code) { 61 | return "for i=0," + repetition_s() + " do " + code + " end"; 62 | } 63 | 64 | } // namespace lbs 65 | 66 | #endif //LUA_BINDINGS_SHOOTOUT_BENCHMARK_HPP 67 | -------------------------------------------------------------------------------- /source/kaguya.cpp: -------------------------------------------------------------------------------- 1 | // lua bindings shootout 2 | // The MIT License (MIT) 3 | 4 | // Copyright © 2018 ThePhD 5 | 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | // this software and associated documentation files (the "Software"), to deal in 8 | // the Software without restriction, including without limitation the rights to 9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | // the Software, and to permit persons to whom the Software is furnished to do so, 11 | // subject to the following conditions: 12 | 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | #include 24 | 25 | #include "benchmark.hpp" 26 | #include "lbs_lib.hpp" 27 | #include "lbs_lua.hpp" 28 | 29 | void kaguya_table_global_string_get_measure(benchmark::State& benchmark_state) { 30 | kaguya::State lua; 31 | lua.setErrorHandler(lbs::kaguya_panic_throw); 32 | 33 | lua["value"] = lbs::magic_value(); 34 | double x = 0; 35 | for (auto _ : benchmark_state) { 36 | double v = lua["value"]; 37 | x += v; 38 | } 39 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 40 | } 41 | 42 | void kaguya_table_global_string_set_measure(benchmark::State& benchmark_state) { 43 | kaguya::State lua; 44 | lua.setErrorHandler(lbs::kaguya_panic_throw); 45 | 46 | double v = 0; 47 | for (auto _ : benchmark_state) { 48 | v += lbs::magic_value(); 49 | lua["value"] = v; 50 | } 51 | double x = lua["value"]; 52 | lbs::expect(benchmark_state, x, v); 53 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 54 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 55 | } 56 | 57 | void kaguya_table_get_measure(benchmark::State& benchmark_state) { 58 | kaguya::State lua; 59 | lua.setErrorHandler(lbs::kaguya_panic_throw); 60 | 61 | lua["warble"] = kaguya::NewTable(); 62 | lua["warble"]["value"] = lbs::magic_value(); 63 | kaguya::LuaTable t = lua["warble"]; 64 | double x = 0; 65 | for (auto _ : benchmark_state) { 66 | double v = t["value"]; 67 | x += v; 68 | } 69 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 70 | } 71 | 72 | void kaguya_table_set_measure(benchmark::State& benchmark_state) { 73 | kaguya::State lua; 74 | lua.setErrorHandler(lbs::kaguya_panic_throw); 75 | 76 | lua["warble"] = kaguya::NewTable(); 77 | kaguya::LuaTable t = lua["warble"]; 78 | double v = 0; 79 | for (auto _ : benchmark_state) { 80 | v += lbs::magic_value(); 81 | t["value"] = v; 82 | } 83 | double x = t["value"]; 84 | lbs::expect(benchmark_state, x, v); 85 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 86 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 87 | } 88 | 89 | void kaguya_table_chained_get_measure(benchmark::State& benchmark_state) { 90 | kaguya::State lua; 91 | lua.setErrorHandler(lbs::kaguya_panic_throw); 92 | 93 | lua["ulahibe"] = kaguya::NewTable(); 94 | lua["ulahibe"]["warble"] = kaguya::NewTable(); 95 | lua["ulahibe"]["warble"]["value"] = lbs::magic_value(); 96 | double x = 0; 97 | for (auto _ : benchmark_state) { 98 | double v = lua["ulahibe"]["warble"]["value"]; 99 | x += v; 100 | } 101 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 102 | } 103 | 104 | void kaguya_table_chained_set_measure(benchmark::State& benchmark_state) { 105 | kaguya::State lua; 106 | lua.setErrorHandler(lbs::kaguya_panic_throw); 107 | 108 | lua["ulahibe"] = kaguya::NewTable(); 109 | lua["ulahibe"]["warble"] = kaguya::NewTable(); 110 | lua["ulahibe"]["warble"]["value"] = lbs::magic_value(); 111 | double v = 0; 112 | for (auto _ : benchmark_state) { 113 | v += lbs::magic_value(); 114 | lua["ulahibe"]["warble"]["value"] = v; 115 | } 116 | double x = lua["ulahibe"]["warble"]["value"]; 117 | lbs::expect(benchmark_state, x, v); 118 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 119 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 120 | } 121 | 122 | void kaguya_c_function_measure(benchmark::State& benchmark_state) { 123 | kaguya::State lua; 124 | lua_State* L = lua.state(); 125 | 126 | lua.setErrorHandler(lbs::kaguya_panic_throw); 127 | lua["f"].setFunction(lbs::basic_call); 128 | 129 | 130 | lbs::lua_bench_do_or_die(L, lbs::c_function_check); 131 | 132 | std::string code = lbs::repeated_code(lbs::c_function_code); 133 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 134 | for (auto _ : benchmark_state) { 135 | lbs::lua_bench_preload_do_or_die(L, code_index); 136 | } 137 | lbs::lua_bench_unload(L, code_index); 138 | } 139 | 140 | void kaguya_lua_function_in_c_measure(benchmark::State& benchmark_state) { 141 | kaguya::State lua; 142 | lua.setErrorHandler(lbs::kaguya_panic_throw); 143 | 144 | lua(R"(function f (i) 145 | return i; 146 | end)"); 147 | kaguya::LuaFunction f = lua["f"]; 148 | double x = 0; 149 | for (auto _ : benchmark_state) { 150 | double v = f(lbs::magic_value()); 151 | x += v; 152 | } 153 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 154 | } 155 | 156 | void kaguya_c_function_through_lua_in_c_measure(benchmark::State& benchmark_state) { 157 | kaguya::State lua; 158 | lua.setErrorHandler(lbs::kaguya_panic_throw); 159 | 160 | lua["f"].setFunction(lbs::basic_call); 161 | kaguya::LuaFunction f = lua["f"]; 162 | double x = 0; 163 | for (auto _ : benchmark_state) { 164 | double v = f(lbs::magic_value()); 165 | x += v; 166 | } 167 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 168 | } 169 | 170 | void kaguya_member_function_call_measure(benchmark::State& benchmark_state) { 171 | kaguya::State lua; 172 | lua_State* L = lua.state(); 173 | 174 | lua.setErrorHandler(lbs::kaguya_panic_throw); 175 | 176 | lua["c"].setClass(kaguya::UserdataMetatable() 177 | .setConstructors() 178 | .addFunction("get", &lbs::basic::get) 179 | .addFunction("set", &lbs::basic::set)); 180 | lua("b = c.new()"); 181 | 182 | lbs::lua_bench_do_or_die(L, lbs::member_function_call_check); 183 | 184 | std::string code = lbs::repeated_code(lbs::member_function_call_code); 185 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 186 | for (auto _ : benchmark_state) { 187 | lbs::lua_bench_preload_do_or_die(L, code_index); 188 | } 189 | lbs::lua_bench_unload(L, code_index); 190 | } 191 | 192 | void kaguya_userdata_variable_access_measure(benchmark::State& benchmark_state) { 193 | // Does not support member variable syntax: 194 | // turns it into a function, unfortunately 195 | //for (auto _ : benchmark_state) { 196 | //} 197 | lbs::unsupported(benchmark_state); 198 | } 199 | 200 | void kaguya_userdata_variable_access_large_measure(benchmark::State& benchmark_state) { 201 | // Does not support member variable syntax: 202 | // turns it into a function, unfortunately 203 | //for (auto _ : benchmark_state) { 204 | //} 205 | lbs::unsupported(benchmark_state); 206 | } 207 | 208 | void kaguya_userdata_variable_access_last_measure(benchmark::State& benchmark_state) { 209 | // Does not support member variable syntax: 210 | // turns it into a function, unfortunately 211 | //for (auto _ : benchmark_state) { 212 | //} 213 | lbs::unsupported(benchmark_state); 214 | } 215 | 216 | void kaguya_stateful_function_object_measure(benchmark::State& benchmark_state) { 217 | kaguya::State lua; 218 | lua.setErrorHandler(lbs::kaguya_panic_throw); 219 | 220 | lua["f"] = kaguya::function(lbs::basic_stateful()); 221 | kaguya::LuaFunction f = lua["f"]; 222 | double x = 0; 223 | for (auto _ : benchmark_state) { 224 | double v = f(lbs::magic_value()); 225 | x += v; 226 | } 227 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 228 | } 229 | 230 | void kaguya_multi_return_lua_measure(benchmark::State& benchmark_state) { 231 | kaguya::State lua; 232 | lua_State* L = lua.state(); 233 | lua.setErrorHandler(lbs::kaguya_panic_throw); 234 | 235 | lua["f"].setFunction(lbs::basic_multi_return); 236 | 237 | lbs::lua_bench_do_or_die(L, lbs::lua_multi_return_check); 238 | 239 | std::string code = lbs::repeated_code(lbs::lua_multi_return_code); 240 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 241 | for (auto _ : benchmark_state) { 242 | lbs::lua_bench_preload_do_or_die(L, code_index); 243 | } 244 | lbs::lua_bench_unload(L, code_index); 245 | } 246 | 247 | void kaguya_multi_return_measure(benchmark::State& benchmark_state) { 248 | kaguya::State lua; 249 | lua.setErrorHandler(lbs::kaguya_panic_throw); 250 | 251 | lua["f"].setFunction(lbs::basic_multi_return); 252 | kaguya::LuaFunction f = lua["f"]; 253 | double x = 0; 254 | for (auto _ : benchmark_state) { 255 | double a, b; 256 | kaguya::tie(a, b) = f(lbs::magic_value()); 257 | x += a; 258 | x += b; 259 | } 260 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * (lbs::magic_value() * 3)); 261 | } 262 | 263 | void kaguya_base_derived_measure(benchmark::State& benchmark_state) { 264 | kaguya::State lua; 265 | lua.setErrorHandler(lbs::kaguya_panic_throw); 266 | 267 | lua["cab"].setClass( 268 | kaguya::UserdataMetatable>() 269 | .setConstructors() 270 | .addFunction("a_func", &lbs::complex_ab::a_func) 271 | .addFunction("b_func", &lbs::complex_ab::b_func) 272 | .addFunction("ab_func", &lbs::complex_ab::ab_func)); 273 | lbs::complex_ab ab; 274 | // Set and verify correctness 275 | lua["b"] = std::ref(ab); 276 | { 277 | lbs::complex_base_a* va = lua["b"]; 278 | lbs::complex_base_b* vb = lua["b"]; 279 | if (lbs::verify_base_correctness(*va, *vb, ab)) { 280 | lbs::unsupported(benchmark_state); 281 | return; 282 | } 283 | } 284 | double x = 0; 285 | for (auto _ : benchmark_state) { 286 | lbs::complex_base_a* va = lua["b"]; 287 | lbs::complex_base_b* vb = lua["b"]; 288 | x += va->a_func(); 289 | x += vb->b_func(); 290 | } 291 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * (lbs::magic_value() * 2)); 292 | } 293 | 294 | void kaguya_return_userdata_measure(benchmark::State& benchmark_state) { 295 | kaguya::State lua; 296 | lua_State* L = lua.state(); 297 | lua.setErrorHandler(lbs::kaguya_panic_throw); 298 | 299 | lua["f"].setFunction(lbs::basic_return); 300 | lua["h"].setFunction(lbs::basic_get_var); 301 | 302 | lbs::lua_bench_do_or_die(L, lbs::return_userdata_check); 303 | 304 | std::string code = lbs::repeated_code(lbs::return_userdata_code); 305 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 306 | for (auto _ : benchmark_state) { 307 | lbs::lua_bench_preload_do_or_die(L, code_index); 308 | } 309 | lbs::lua_bench_unload(L, code_index); 310 | } 311 | 312 | void kaguya_optional_success_measure(benchmark::State& benchmark_state) { 313 | // Almost unsupported 314 | // Converting directly to `optional` fails, 315 | // have to use value_or on the proxy 316 | kaguya::State lua; 317 | lua_State* L = lua.state(); 318 | lua.setErrorHandler(lbs::kaguya_panic_throw); 319 | 320 | lua(lbs::optional_success_precode); 321 | 322 | double x = 0; 323 | for (auto _ : benchmark_state) { 324 | double v = lua["warble"]["value"].value_or(1); 325 | x += v; 326 | } 327 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 328 | } 329 | 330 | void kaguya_optional_half_failure_measure(benchmark::State& benchmark_state) { 331 | // Almost unsupported 332 | // Converting directly to `optional` fails, 333 | // have to use value_or on the proxy 334 | kaguya::State lua; 335 | lua.setErrorHandler(lbs::kaguya_panic_throw); 336 | 337 | lua(lbs::optional_half_failure_precode); 338 | 339 | double x = 0; 340 | for (auto _ : benchmark_state) { 341 | double v = lua["warble"]["value"].value_or(1); 342 | x += v; 343 | } 344 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * 1); 345 | } 346 | 347 | void kaguya_optional_failure_measure(benchmark::State& benchmark_state) { 348 | // Almost unsupported 349 | // Converting directly to `optional` fails, 350 | // have to use value_or on the proxy 351 | kaguya::State lua; 352 | lua.setErrorHandler(lbs::kaguya_panic_throw); 353 | 354 | double x = 0; 355 | for (auto _ : benchmark_state) { 356 | double v = lua["warble"]["value"].value_or(1); 357 | x += v; 358 | } 359 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * 1); 360 | } 361 | 362 | void kaguya_implicit_inheritance_measure(benchmark::State& benchmark_state) { 363 | kaguya::State lua; 364 | lua_State* L = lua.state(); 365 | lua.setErrorHandler(lbs::kaguya_panic_throw); 366 | lua["ca"].setClass( 367 | kaguya::UserdataMetatable() 368 | .setConstructors() 369 | .addFunction("a_func", &lbs::complex_base_a::a_func) 370 | .addFunction("a", &lbs::complex_base_a::a)); 371 | 372 | lua["cb"].setClass( 373 | kaguya::UserdataMetatable() 374 | .setConstructors() 375 | .addFunction("b_func", &lbs::complex_base_b::b_func) 376 | .addFunction("b", &lbs::complex_base_b::b)); 377 | 378 | lua["cab"].setClass( 379 | kaguya::UserdataMetatable>() 380 | .setConstructors() 381 | .addFunction("ab_func", &lbs::complex_ab::ab_func) 382 | .addFunction("ab", &lbs::complex_ab::ab)); 383 | 384 | lua("b = cab.new()"); 385 | 386 | lbs::lua_bench_do_or_die(L, lbs::implicit_inheritance_check); 387 | 388 | std::string code = lbs::repeated_code(lbs::implicit_inheritance_code); 389 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 390 | for (auto _ : benchmark_state) { 391 | lbs::lua_bench_preload_do_or_die(L, code_index); 392 | } 393 | lbs::lua_bench_unload(L, code_index); 394 | } 395 | 396 | BENCHMARK(kaguya_table_global_string_get_measure); 397 | BENCHMARK(kaguya_table_global_string_set_measure); 398 | BENCHMARK(kaguya_table_get_measure); 399 | BENCHMARK(kaguya_table_set_measure); 400 | BENCHMARK(kaguya_table_chained_get_measure); 401 | BENCHMARK(kaguya_table_chained_set_measure); 402 | BENCHMARK(kaguya_c_function_measure); 403 | BENCHMARK(kaguya_c_function_through_lua_in_c_measure); 404 | BENCHMARK(kaguya_lua_function_in_c_measure); 405 | BENCHMARK(kaguya_member_function_call_measure); 406 | BENCHMARK(kaguya_userdata_variable_access_measure); 407 | BENCHMARK(kaguya_userdata_variable_access_large_measure); 408 | BENCHMARK(kaguya_userdata_variable_access_last_measure); 409 | BENCHMARK(kaguya_multi_return_measure); 410 | BENCHMARK(kaguya_multi_return_lua_measure); 411 | BENCHMARK(kaguya_stateful_function_object_measure); 412 | BENCHMARK(kaguya_base_derived_measure); 413 | BENCHMARK(kaguya_base_derived_measure); 414 | BENCHMARK(kaguya_return_userdata_measure); 415 | BENCHMARK(kaguya_optional_success_measure); 416 | BENCHMARK(kaguya_optional_half_failure_measure); 417 | BENCHMARK(kaguya_optional_failure_measure); 418 | BENCHMARK(kaguya_implicit_inheritance_measure); 419 | -------------------------------------------------------------------------------- /source/lbs_lib.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace lbs { 7 | 8 | inline double magic_value() { 9 | static const double v = 3; 10 | return v; 11 | } 12 | 13 | inline const std::string& magic_value_string() { 14 | static const std::string v = std::to_string(magic_value()); 15 | return v; 16 | } 17 | 18 | struct basic { 19 | double var = 499; 20 | int var0 = 501; 21 | int var1 = 502; 22 | int var2 = 503; 23 | int var3 = 504; 24 | int var4 = 505; 25 | 26 | basic() = default; 27 | basic(double x) 28 | : var(x) { 29 | } 30 | 31 | double get() const { 32 | return var; 33 | } 34 | 35 | void set(double x) { 36 | var = x; 37 | } 38 | }; 39 | 40 | struct basic_large { 41 | double var = 499; 42 | int var0 = 500; 43 | int var1 = 501; 44 | int var2 = 502; 45 | int var3 = 503; 46 | int var4 = 504; 47 | int var5 = 505; 48 | int var6 = 506; 49 | int var7 = 507; 50 | int var8 = 508; 51 | int var9 = 509; 52 | int var10 = 510; 53 | int var11 = 511; 54 | int var12 = 512; 55 | int var13 = 513; 56 | int var14 = 514; 57 | int var15 = 515; 58 | int var16 = 516; 59 | int var17 = 517; 60 | int var18 = 518; 61 | int var19 = 519; 62 | int var20 = 520; 63 | int var21 = 521; 64 | int var22 = 522; 65 | int var23 = 523; 66 | int var24 = 524; 67 | int var25 = 525; 68 | int var26 = 526; 69 | int var27 = 527; 70 | int var28 = 528; 71 | int var29 = 529; 72 | int var30 = 530; 73 | int var31 = 531; 74 | int var32 = 532; 75 | int var33 = 533; 76 | int var34 = 534; 77 | int var35 = 535; 78 | int var36 = 536; 79 | int var37 = 537; 80 | int var38 = 538; 81 | int var39 = 539; 82 | int var40 = 540; 83 | int var41 = 541; 84 | int var42 = 542; 85 | int var43 = 543; 86 | int var44 = 544; 87 | int var45 = 545; 88 | int var46 = 546; 89 | int var47 = 547; 90 | int var48 = 548; 91 | int64_t var49 = 549; 92 | 93 | basic_large() = default; 94 | }; 95 | 96 | struct basic_stateful { 97 | double storage; 98 | 99 | basic_stateful() = default; 100 | 101 | double operator()(double i) { 102 | storage = i; 103 | return storage; 104 | } 105 | }; 106 | 107 | struct complex_base_a { 108 | double a = lbs::magic_value() - 2; 109 | 110 | complex_base_a() = default; 111 | 112 | virtual double a_func() const { 113 | return a; 114 | } 115 | }; 116 | 117 | struct complex_base_b { 118 | double b = lbs::magic_value() - 1; 119 | 120 | complex_base_b() = default; 121 | 122 | virtual double b_func() const { 123 | return b; 124 | } 125 | }; 126 | 127 | struct complex_ab : complex_base_a, complex_base_b { 128 | double ab = lbs::magic_value(); 129 | 130 | complex_ab() = default; 131 | 132 | virtual double a_func() const override { 133 | return ab; 134 | } 135 | 136 | virtual double b_func() const override { 137 | return ab; 138 | } 139 | 140 | double ab_func() const { 141 | return ab; 142 | } 143 | }; 144 | 145 | inline double basic_call(double x) { 146 | return x; 147 | } 148 | 149 | inline basic basic_return(double x) { 150 | return basic(x); 151 | } 152 | 153 | inline double basic_get_var(const basic& b) { 154 | return b.var; 155 | } 156 | 157 | inline std::tuple basic_multi_return(double i) { 158 | return { i, i * 2 }; 159 | } 160 | 161 | inline void basic_multi_return_out(double i, double& out_1, double& out_2) { 162 | std::tie(out_1, out_2) = basic_multi_return(i); 163 | } 164 | 165 | } // namespace lbs 166 | -------------------------------------------------------------------------------- /source/lua-api-pp.cpp: -------------------------------------------------------------------------------- 1 | // lua bindings shootout 2 | // The MIT License (MIT) 3 | 4 | // Copyright © 2018 ThePhD 5 | 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | // this software and associated documentation files (the "Software"), to deal in 8 | // the Software without restriction, including without limitation the rights to 9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | // the Software, and to permit persons to whom the Software is furnished to do so, 11 | // subject to the following conditions: 12 | 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | #include 24 | 25 | #include "lbs_lib.hpp" 26 | #include "lbs_lua.hpp" 27 | #include "benchmark.hpp" 28 | 29 | LUAPP_USERDATA(lbs::basic, "c"); 30 | LUAPP_USERDATA(lbs::basic_large, "cl"); 31 | LUAPP_USERDATA(lbs::complex_base_a, "ca"); 32 | LUAPP_USERDATA(lbs::complex_base_b, "cb"); 33 | LUAPP_USERDATA(lbs::complex_ab, "cab"); 34 | 35 | lua::Retval basic_setup(lua::Context& c) { 36 | c.mt() = lua::Table::records(c, 37 | "__index", lua::Table::records(c, "var", &lbs::basic::var, "get", &lbs::basic::get, "set", &lbs::basic::set)); 38 | c.global["basic_new"] = static_cast([]() { 39 | return lbs::basic(); 40 | }); 41 | return c.ret(); 42 | } 43 | 44 | lua::Retval basic_multi_return_setup(lua::Context& c) { 45 | auto r = lbs::basic_multi_return(c.args[0].to()); 46 | return c.ret(std::get<0>(r), std::get<1>(r)); 47 | } 48 | 49 | lua::Retval basic_return_setup(lua::Context& c) { 50 | lbs::basic r = lbs::basic_return(c.args[0].to()); 51 | return c.ret(std::move(r)); 52 | } 53 | 54 | lua::Retval basic_get_setup(lua::Context& c) { 55 | double r = lbs::basic_get_var(c.args[0].to()); 56 | return c.ret(r); 57 | } 58 | 59 | /* 60 | // unsupported: Linker errors?! 61 | lua::Retval basic_stateful_setup(lua::Context& c) { 62 | auto upv = c.upvalues[2]; 63 | lbs::basic_stateful& bs = upv.cast(); 64 | auto r = bs(c.args[1].to()); 65 | return c.ret(r); 66 | } 67 | */ 68 | 69 | void lua_api_pp_table_global_string_get_measure(benchmark::State& benchmark_state) { 70 | lua::State l; 71 | lua_atpanic(l.getRawState(), lbs::panic_throw); 72 | 73 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 74 | L.global.set("value", lbs::magic_value()); 75 | double x = 0; 76 | for (auto _ : benchmark_state) { 77 | double v = L.global["value"]; 78 | x += v; 79 | } 80 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 81 | } 82 | 83 | void lua_api_pp_table_global_string_set_measure(benchmark::State& benchmark_state) { 84 | lua::State l; 85 | lua_atpanic(l.getRawState(), lbs::panic_throw); 86 | 87 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 88 | double v = 0; 89 | for (auto _ : benchmark_state) { 90 | v += lbs::magic_value(); 91 | L.global.set("value", v); 92 | } 93 | double x = L.global["value"]; 94 | lbs::expect(benchmark_state, x, v); 95 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 96 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 97 | } 98 | 99 | void lua_api_pp_table_chained_get_measure(benchmark::State& benchmark_state) { 100 | lua::State l; 101 | lua_atpanic(l.getRawState(), lbs::panic_throw); 102 | 103 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 104 | L.global.set("ulahibe", lua::Table::records(L, "warble", lua::Table::records(L, "value", lbs::magic_value()))); 105 | double x = 0; 106 | for (auto _ : benchmark_state) { 107 | double v = L.global["ulahibe"]["warble"]["value"]; 108 | x += v; 109 | } 110 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 111 | } 112 | 113 | void lua_api_pp_table_chained_set_measure(benchmark::State& benchmark_state) { 114 | lua::State l; 115 | lua_atpanic(l.getRawState(), lbs::panic_throw); 116 | 117 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 118 | L.global.set("ulahibe", lua::Table::records(L, "warble", lua::Table::records(L, "value", lbs::magic_value()))); 119 | double v = 0; 120 | for (auto _ : benchmark_state) { 121 | v += lbs::magic_value(); 122 | L.global["ulahibe"]["warble"]["value"] = v; 123 | } 124 | double x = L.global["ulahibe"]["warble"]["value"]; 125 | lbs::expect(benchmark_state, x, v); 126 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 127 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 128 | } 129 | 130 | void lua_api_pp_table_get_measure(benchmark::State& benchmark_state) { 131 | lua::State l; 132 | lua_atpanic(l.getRawState(), lbs::panic_throw); 133 | 134 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 135 | L.global.set("warble", lua::Table::records(L, "value", lbs::magic_value())); 136 | lua::Table t = L.global["warble"]; 137 | double x = 0; 138 | for (auto _ : benchmark_state) { 139 | double v = t["value"]; 140 | x += v; 141 | } 142 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 143 | } 144 | 145 | void lua_api_pp_table_set_measure(benchmark::State& benchmark_state) { 146 | lua::State l; 147 | lua_atpanic(l.getRawState(), lbs::panic_throw); 148 | 149 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 150 | L.global.set("warble", lua::Table::records(L, "value", lbs::magic_value())); 151 | lua::Table t = L.global["warble"]; 152 | double v = 0; 153 | for (auto _ : benchmark_state) { 154 | v += lbs::magic_value(); 155 | t["value"] = v; 156 | } 157 | double x = t["value"]; 158 | lbs::expect(benchmark_state, x, v); 159 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 160 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 161 | } 162 | 163 | void lua_api_pp_c_function_measure(benchmark::State& benchmark_state) { 164 | lua::State l; 165 | lua_State* L = l.getRawState(); 166 | lua_atpanic(l.getRawState(), lbs::panic_throw); 167 | 168 | lua::Context Lc(l.getRawState(), lua::Context::initializeExplicitly); 169 | Lc.global.set("f", lbs::basic_call); 170 | 171 | lbs::lua_bench_do_or_die(L, lbs::c_function_check); 172 | 173 | std::string code = lbs::repeated_code(lbs::c_function_code); 174 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 175 | for (auto _ : benchmark_state) { 176 | lbs::lua_bench_preload_do_or_die(L, code_index); 177 | } 178 | lbs::lua_bench_unload(L, code_index); 179 | } 180 | 181 | void lua_api_pp_lua_function_in_c_measure(benchmark::State& benchmark_state) { 182 | lua::State l; 183 | lua_atpanic(l.getRawState(), lbs::panic_throw); 184 | 185 | l.runString("function f (i) return i end"); 186 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 187 | double x = 0; 188 | for (auto _ : benchmark_state) { 189 | double v = L.global["f"](lbs::magic_value()); 190 | x += v; 191 | } 192 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 193 | } 194 | 195 | void lua_api_pp_c_function_through_lua_in_c_measure(benchmark::State& benchmark_state) { 196 | lua::State l; 197 | lua_atpanic(l.getRawState(), lbs::panic_throw); 198 | 199 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 200 | L.global.set("f", lbs::basic_call); 201 | double x = 0; 202 | for (auto _ : benchmark_state) { 203 | double v = L.global["f"](lbs::magic_value()); 204 | x += v; 205 | } 206 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 207 | } 208 | 209 | void lua_api_pp_member_function_call_measure(benchmark::State& benchmark_state) { 210 | lua::State l; 211 | lua_State* L = l.getRawState(); 212 | lua_atpanic(l.getRawState(), lbs::panic_throw); 213 | 214 | l.call(lua::mkcf); 215 | l.runString("b = basic_new()"); 216 | 217 | lbs::lua_bench_do_or_die(L, lbs::member_function_call_check); 218 | 219 | std::string code = lbs::repeated_code(lbs::member_function_call_code); 220 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 221 | for (auto _ : benchmark_state) { 222 | lbs::lua_bench_preload_do_or_die(L, code_index); 223 | } 224 | lbs::lua_bench_unload(L, code_index); 225 | } 226 | 227 | void lua_api_pp_userdata_variable_access_measure(benchmark::State& benchmark_state) { 228 | // Unsupported 229 | lbs::unsupported(benchmark_state); 230 | return; 231 | /*lua::State l; 232 | lua_atpanic(l.getRawState(), lbs::panic_throw); 233 | l.call(lua::mkcf); 234 | l.runString("b = basic_new()"); 235 | std::string code = lbs::repeated_code("b.var = i\nx = b.var"); 236 | for (auto _ : benchmark_state ) { 237 | l.runString(code); 238 | }*/ 239 | } 240 | 241 | void lua_api_pp_userdata_variable_access_last_measure(benchmark::State& benchmark_state) { 242 | // Unsupported 243 | lbs::unsupported(benchmark_state); 244 | return; 245 | } 246 | 247 | void lua_api_pp_userdata_variable_access_large_measure(benchmark::State& benchmark_state) { 248 | // Unsupported 249 | lbs::unsupported(benchmark_state); 250 | return; 251 | } 252 | 253 | void lua_api_pp_stateful_function_object_measure(benchmark::State& benchmark_state) { 254 | // Unsupported 255 | // Cannot modify __call directly, it seems?? 256 | // cannot set arbitrary upvalues either... 257 | // L.wrap does not handle it... 258 | lbs::unsupported(benchmark_state); 259 | return; 260 | 261 | /*lua::State l; 262 | lua_atpanic(l.getRawState(), lbs::panic_throw); 263 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 264 | L.global["f"] = L.wrap(lbs::basic_stateful()); 265 | double x = 0; 266 | for (auto _ : benchmark_state ) { 267 | double v = L.global["f"](lbs::magic_value()); 268 | x += v; 269 | } 270 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 271 | */ 272 | } 273 | 274 | void lua_api_pp_multi_return_measure(benchmark::State& benchmark_state) { 275 | lua::State l; 276 | lua_atpanic(l.getRawState(), lbs::panic_throw); 277 | 278 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 279 | L.global.set("f", lua::mkcf); 280 | double x = 0; 281 | for (auto _ : benchmark_state) { 282 | lua::Valset results = L.global["f"](lbs::magic_value()); 283 | double v = results[0]; 284 | double w = results[1]; 285 | x += v; 286 | x += w; 287 | } 288 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * (lbs::magic_value() * 3)); 289 | } 290 | 291 | void lua_api_pp_multi_return_lua_measure(benchmark::State& benchmark_state) { 292 | lua::State l; 293 | lua_atpanic(l.getRawState(), lbs::panic_throw); 294 | 295 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 296 | L.global.set("f", lua::mkcf); 297 | 298 | lbs::lua_bench_do_or_die(L, lbs::lua_multi_return_check); 299 | 300 | std::string code = lbs::repeated_code(lbs::lua_multi_return_code); 301 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 302 | for (auto _ : benchmark_state) { 303 | lbs::lua_bench_preload_do_or_die(L, code_index); 304 | } 305 | lbs::lua_bench_unload(L, code_index); 306 | } 307 | 308 | void lua_api_pp_base_derived_measure(benchmark::State& benchmark_state) { 309 | // Unsupported 310 | lbs::unsupported(benchmark_state); 311 | return; 312 | } 313 | 314 | void lua_api_pp_return_userdata_measure(benchmark::State& benchmark_state) { 315 | lua::State l; 316 | lua_atpanic(l.getRawState(), lbs::panic_throw); 317 | 318 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 319 | L.global.set("f", lua::mkcf); 320 | L.global.set("h", lua::mkcf); 321 | 322 | lbs::lua_bench_do_or_die(L, lbs::return_userdata_check); 323 | 324 | std::string code = lbs::repeated_code(lbs::return_userdata_code); 325 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 326 | for (auto _ : benchmark_state) { 327 | lbs::lua_bench_preload_do_or_die(L, code_index); 328 | } 329 | lbs::lua_bench_unload(L, code_index); 330 | } 331 | 332 | void lua_api_pp_optional_success_measure(benchmark::State& benchmark_state) { 333 | lua::State l; 334 | lua_atpanic(l.getRawState(), lbs::panic_throw); 335 | 336 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 337 | 338 | l.runString(lbs::optional_success_precode); 339 | 340 | double x = 0; 341 | for (auto _ : benchmark_state) { 342 | if (L.global["warble"].type() == lua::ValueType::Table) { 343 | if (L.global["warble"]["value"].is()) { 344 | double v = L.global["warble"]["value"]; 345 | x += v; 346 | } 347 | else { 348 | x += 1; 349 | } 350 | } 351 | else { 352 | x += 1; 353 | } 354 | } 355 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 356 | } 357 | 358 | void lua_api_pp_optional_half_failure_measure(benchmark::State& benchmark_state) { 359 | lua::State l; 360 | lua_atpanic(l.getRawState(), lbs::panic_throw); 361 | 362 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 363 | 364 | l.runString(lbs::optional_half_failure_precode); 365 | 366 | double x = 0; 367 | for (auto _ : benchmark_state) { 368 | if (L.global["warble"].type() == lua::ValueType::Table) { 369 | if (L.global["warble"]["value"].is()) { 370 | double v = L.global["warble"]["value"]; 371 | x += v; 372 | } 373 | else { 374 | x += 1; 375 | } 376 | } 377 | else { 378 | x += 1; 379 | } 380 | } 381 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * 1); 382 | } 383 | 384 | void lua_api_pp_optional_failure_measure(benchmark::State& benchmark_state) { 385 | lua::State l; 386 | lua_atpanic(l.getRawState(), lbs::panic_throw); 387 | 388 | lua::Context L(l.getRawState(), lua::Context::initializeExplicitly); 389 | 390 | double x = 0; 391 | for (auto _ : benchmark_state) { 392 | if (L.global["warble"].type() == lua::ValueType::Table) { 393 | if (L.global["warble"]["value"].is()) { 394 | double v = L.global["warble"]["value"]; 395 | x += v; 396 | } 397 | else { 398 | x += 1; 399 | } 400 | } 401 | else { 402 | x += 1; 403 | } 404 | } 405 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * 1); 406 | } 407 | 408 | void lua_api_pp_implicit_inheritance_measure(benchmark::State& benchmark_state) { 409 | // Unsupported 410 | lbs::unsupported(benchmark_state); 411 | return; 412 | } 413 | 414 | 415 | BENCHMARK(lua_api_pp_table_global_string_get_measure); 416 | BENCHMARK(lua_api_pp_table_global_string_set_measure); 417 | BENCHMARK(lua_api_pp_table_get_measure); 418 | BENCHMARK(lua_api_pp_table_set_measure); 419 | BENCHMARK(lua_api_pp_table_chained_get_measure); 420 | BENCHMARK(lua_api_pp_table_chained_set_measure); 421 | BENCHMARK(lua_api_pp_c_function_measure); 422 | BENCHMARK(lua_api_pp_c_function_through_lua_in_c_measure); 423 | BENCHMARK(lua_api_pp_lua_function_in_c_measure); 424 | BENCHMARK(lua_api_pp_member_function_call_measure); 425 | BENCHMARK(lua_api_pp_userdata_variable_access_measure); 426 | BENCHMARK(lua_api_pp_userdata_variable_access_large_measure); 427 | BENCHMARK(lua_api_pp_userdata_variable_access_last_measure); 428 | BENCHMARK(lua_api_pp_multi_return_lua_measure); 429 | BENCHMARK(lua_api_pp_multi_return_measure); 430 | BENCHMARK(lua_api_pp_stateful_function_object_measure); 431 | BENCHMARK(lua_api_pp_base_derived_measure); 432 | BENCHMARK(lua_api_pp_return_userdata_measure); 433 | BENCHMARK(lua_api_pp_optional_success_measure); 434 | BENCHMARK(lua_api_pp_optional_half_failure_measure); 435 | BENCHMARK(lua_api_pp_optional_failure_measure); 436 | BENCHMARK(lua_api_pp_implicit_inheritance_measure); 437 | -------------------------------------------------------------------------------- /source/lua_bindings_shootout.cpp: -------------------------------------------------------------------------------- 1 | // lua bindings shootout 2 | // The MIT License (MIT) 3 | 4 | // Copyright © 2018 ThePhD 5 | 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | // this software and associated documentation files (the "Software"), to deal in 8 | // the Software without restriction, including without limitation the rights to 9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | // the Software, and to permit persons to whom the Software is furnished to do so, 11 | // subject to the following conditions: 12 | 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | #include 24 | 25 | int main(int argc, char** argv) { 26 | ::benchmark::Initialize(&argc, argv); 27 | if (::benchmark::ReportUnrecognizedArguments(argc, argv)) { 28 | return 1; 29 | } 30 | ::benchmark::RunSpecifiedBenchmarks(); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /source/luacppinterface.cpp: -------------------------------------------------------------------------------- 1 | // lua bindings shootout 2 | // The MIT License (MIT) 3 | 4 | // Copyright � 2018 ThePhD 5 | 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | // this software and associated documentation files (the "Software"), to deal in 8 | // the Software without restriction, including without limitation the rights to 9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | // the Software, and to permit persons to whom the Software is furnished to do so, 11 | // subject to the following conditions: 12 | 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | #include "benchmark.hpp" 24 | #include "lbs_lib.hpp" 25 | #include "lbs_lua.hpp" 26 | 27 | #include 28 | 29 | void luacppinterface_table_global_string_get_measure(benchmark::State& benchmark_state) { 30 | Lua l; 31 | auto lua = l.GetGlobalEnvironment(); 32 | lua_atpanic(lua.GetState().get(), lbs::panic_throw); 33 | 34 | lua.Set("value", lbs::magic_value()); 35 | double x = 0; 36 | for (auto _ : benchmark_state) { 37 | x += lua.Get("value"); 38 | } 39 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 40 | } 41 | 42 | void luacppinterface_table_global_string_set_measure(benchmark::State& benchmark_state) { 43 | Lua l; 44 | auto lua = l.GetGlobalEnvironment(); 45 | lua_atpanic(lua.GetState().get(), lbs::panic_throw); 46 | 47 | double v = 0; 48 | for (auto _ : benchmark_state) { 49 | v += lbs::magic_value(); 50 | lua.Set("value", v); 51 | } 52 | double x = lua.Get("value"); 53 | lbs::expect(benchmark_state, x, v); 54 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 55 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 56 | } 57 | 58 | void luacppinterface_table_get_measure(benchmark::State& benchmark_state) { 59 | Lua l; 60 | auto lua = l.GetGlobalEnvironment(); 61 | lua_atpanic(lua.GetState().get(), lbs::panic_throw); 62 | 63 | lua.Set("warble", l.CreateTable()); 64 | LuaTable t = lua.Get("warble"); 65 | t.Set("value", lbs::magic_value()); 66 | 67 | double x = 0; 68 | for (auto _ : benchmark_state) { 69 | x += t.Get("value"); 70 | } 71 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 72 | } 73 | 74 | void luacppinterface_table_set_measure(benchmark::State& benchmark_state) { 75 | Lua l; 76 | auto lua = l.GetGlobalEnvironment(); 77 | lua_atpanic(lua.GetState().get(), lbs::panic_throw); 78 | 79 | lua.Set("warble", l.CreateTable()); 80 | LuaTable t = lua.Get("warble"); 81 | double v = 0; 82 | for (auto _ : benchmark_state) { 83 | v += lbs::magic_value(); 84 | t.Set("value", v); 85 | } 86 | double x = lua.Get("warble").Get("value"); 87 | lbs::expect(benchmark_state, x, v); 88 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 89 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 90 | } 91 | 92 | void luacppinterface_table_chained_get_measure(benchmark::State& benchmark_state) { 93 | Lua l; 94 | auto lua = l.GetGlobalEnvironment(); 95 | lua_atpanic(lua.GetState().get(), lbs::panic_throw); 96 | 97 | lua.Set("ulahibe", l.CreateTable()); 98 | LuaTable tu = lua.Get("ulahibe"); 99 | tu.Set("warble", l.CreateTable()); 100 | LuaTable tw = tu.Get("warble"); 101 | tw.Set("value", lbs::magic_value()); 102 | double x = 0; 103 | for (auto _ : benchmark_state) { 104 | double v = lua.Get("ulahibe").Get("warble").Get("value"); 105 | x += v; 106 | } 107 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 108 | } 109 | 110 | void luacppinterface_table_chained_set_measure(benchmark::State& benchmark_state) { 111 | Lua l; 112 | auto lua = l.GetGlobalEnvironment(); 113 | lua_atpanic(lua.GetState().get(), lbs::panic_throw); 114 | 115 | lua.Set("ulahibe", l.CreateTable()); 116 | LuaTable tu = lua.Get("ulahibe"); 117 | tu.Set("warble", l.CreateTable()); 118 | LuaTable tw = tu.Get("warble"); 119 | tw.Set("value", lbs::magic_value()); 120 | double v = 0; 121 | for (auto _ : benchmark_state) { 122 | v += lbs::magic_value(); 123 | lua.Get("ulahibe").Get("warble").Set("value", v); 124 | } 125 | double x = lua.Get("ulahibe").Get("warble").Get("value"); 126 | lbs::expect(benchmark_state, x, v); 127 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 128 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 129 | } 130 | 131 | void luacppinterface_c_function_measure(benchmark::State& benchmark_state) { 132 | Lua l; 133 | auto lua = l.GetGlobalEnvironment(); 134 | lua_State* L = lua.GetState().get(); 135 | luaL_openlibs(L); 136 | lua_atpanic(L, lbs::panic_throw); 137 | 138 | lua.Set("f", l.CreateFunction(lbs::basic_call)); 139 | 140 | 141 | lbs::lua_bench_do_or_die(L, lbs::c_function_check); 142 | 143 | std::string code = lbs::repeated_code(lbs::c_function_code); 144 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 145 | for (auto _ : benchmark_state) { 146 | lbs::lua_bench_preload_do_or_die(L, code_index); 147 | } 148 | lbs::lua_bench_unload(L, code_index); 149 | } 150 | 151 | void luacppinterface_lua_function_in_c_measure(benchmark::State& benchmark_state) { 152 | Lua l; 153 | auto lua = l.GetGlobalEnvironment(); 154 | lua_State* L = lua.GetState().get(); 155 | lua_atpanic(L, lbs::panic_throw); 156 | 157 | if (l.RunScript(R"(function f (i) 158 | return i; 159 | end)") 160 | != "No errors") { 161 | lua_error(lua.GetState().get()); 162 | } 163 | 164 | auto f = lua.Get>("f"); 165 | double x = 0; 166 | for (auto _ : benchmark_state) { 167 | double v = f.Invoke(lbs::magic_value()); 168 | x += v; 169 | } 170 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 171 | } 172 | 173 | void luacppinterface_c_function_through_lua_in_c_measure(benchmark::State& benchmark_state) { 174 | Lua l; 175 | auto lua = l.GetGlobalEnvironment(); 176 | lua_State* L = lua.GetState().get(); 177 | lua_atpanic(L, lbs::panic_throw); 178 | 179 | lua.Set("f", l.CreateFunction(lbs::basic_call)); 180 | 181 | auto f = lua.Get>("f"); 182 | double x = 0; 183 | for (auto _ : benchmark_state) { 184 | double v = f.Invoke(lbs::magic_value()); 185 | x += v; 186 | } 187 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 188 | } 189 | 190 | void luacppinterface_member_function_call_measure(benchmark::State& benchmark_state) { 191 | Lua l; 192 | auto lua = l.GetGlobalEnvironment(); 193 | lua_State* L = lua.GetState().get(); 194 | luaL_openlibs(L); 195 | lua_atpanic(L, lbs::panic_throw); 196 | 197 | auto image = l.CreateUserdata(new lbs::basic()); 198 | lua.Set("b", image); 199 | image.Bind("set", &lbs::basic::set); 200 | image.Bind("get", &lbs::basic::get); 201 | 202 | lbs::lua_bench_do_or_die(L, lbs::member_function_call_check); 203 | 204 | std::string code = lbs::repeated_code(lbs::member_function_call_code); 205 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 206 | for (auto _ : benchmark_state) { 207 | lbs::lua_bench_preload_do_or_die(L, code_index); 208 | } 209 | lbs::lua_bench_unload(L, code_index); 210 | } 211 | 212 | void luacppinterface_userdata_variable_access_measure(benchmark::State& benchmark_state) { 213 | // Unsupported 214 | lbs::unsupported(benchmark_state); 215 | return; 216 | } 217 | 218 | void luacppinterface_userdata_variable_access_large_measure(benchmark::State& benchmark_state) { 219 | // Unsupported 220 | lbs::unsupported(benchmark_state); 221 | return; 222 | } 223 | 224 | void luacppinterface_userdata_variable_access_last_measure(benchmark::State& benchmark_state) { 225 | // Unsupported 226 | lbs::unsupported(benchmark_state); 227 | return; 228 | } 229 | 230 | void luacppinterface_stateful_function_object_measure(benchmark::State& benchmark_state) { 231 | Lua l; 232 | auto lua = l.GetGlobalEnvironment(); 233 | lua_State* L = lua.GetState().get(); 234 | lua_atpanic(L, lbs::panic_throw); 235 | 236 | lua.Set("f", l.CreateFunction(lbs::basic_stateful())); 237 | 238 | auto f = lua.Get>("f"); 239 | double x = 0; 240 | for (auto _ : benchmark_state) { 241 | double v = f.Invoke(lbs::magic_value()); 242 | x += v; 243 | } 244 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 245 | } 246 | 247 | void luacppinterface_multi_return_measure(benchmark::State& benchmark_state) { 248 | // Unsupported 249 | lbs::unsupported(benchmark_state); 250 | return; 251 | } 252 | 253 | void luacppinterface_multi_return_lua_measure(benchmark::State& benchmark_state) { 254 | // Unsupported 255 | lbs::unsupported(benchmark_state); 256 | return; 257 | } 258 | 259 | void luacppinterface_base_derived_measure(benchmark::State& benchmark_state) { 260 | // Unsupported 261 | // The userdata pulls out the wrong base class and fails 262 | // with the exceptions below 263 | Lua l; 264 | auto lua = l.GetGlobalEnvironment(); 265 | lua_State* L = lua.GetState().get(); 266 | lua_atpanic(L, lbs::panic_throw); 267 | 268 | auto lud = l.CreateUserdata(new lbs::complex_ab()); 269 | lua.Set("b", lud); 270 | { 271 | LuaUserdata lab = lua.Get>("b"); 272 | LuaUserdata la = lua.Get>("b"); 273 | LuaUserdata lb = lua.Get>("b"); 274 | lbs::complex_ab& ab = *lab.GetPointer(); 275 | lbs::complex_base_a& va = *la.GetPointer(); 276 | lbs::complex_base_b& vb = *lb.GetPointer(); 277 | if (!lbs::verify_base_correctness(va, vb, ab)) { 278 | lbs::unsupported(benchmark_state); 279 | return; 280 | } 281 | } 282 | double x = 0; 283 | for (auto _ : benchmark_state) { 284 | LuaUserdata la = lua.Get>("b"); 285 | LuaUserdata lb = lua.Get>("b"); 286 | lbs::complex_base_a& va = *la.GetPointer(); 287 | lbs::complex_base_b& vb = *lb.GetPointer(); 288 | x += va.a_func(); 289 | x += vb.b_func(); 290 | } 291 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * (lbs::magic_value() * 2)); 292 | } 293 | 294 | void luacppinterface_return_userdata_measure(benchmark::State& benchmark_state) { 295 | Lua l; 296 | auto lua = l.GetGlobalEnvironment(); 297 | lua_State* L = lua.GetState().get(); 298 | luaL_openlibs(L); 299 | lua_atpanic(L, lbs::panic_throw); 300 | 301 | lua.Set("f", l.CreateFunction(double)>([&](double i) -> LuaUserdata { 302 | return l.CreateUserdata(new lbs::basic(lbs::basic_return(i))); 303 | })); 304 | lua.Set("h", l.CreateFunction)>([&](LuaUserdata b) -> double { 305 | return lbs::basic_get_var(*b.RetrieveData()); 306 | })); 307 | lbs::lua_bench_do_or_die(L, lbs::return_userdata_check); 308 | 309 | std::string code = lbs::repeated_code(lbs::return_userdata_code); 310 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 311 | for (auto _ : benchmark_state) { 312 | lbs::lua_bench_preload_do_or_die(L, code_index); 313 | } 314 | lbs::lua_bench_unload(L, code_index); 315 | } 316 | 317 | void luacppinterface_optional_success_measure(benchmark::State& benchmark_state) { 318 | // Unsupported 319 | lbs::unsupported(benchmark_state); 320 | return; 321 | } 322 | 323 | void luacppinterface_optional_half_failure_measure(benchmark::State& benchmark_state) { 324 | // Unsupported 325 | lbs::unsupported(benchmark_state); 326 | return; 327 | } 328 | 329 | void luacppinterface_optional_failure_measure(benchmark::State& benchmark_state) { 330 | // Unsupported 331 | lbs::unsupported(benchmark_state); 332 | return; 333 | } 334 | 335 | void luacppinterface_implicit_inheritance_measure(benchmark::State& benchmark_state) { 336 | // Unsupported 337 | lbs::unsupported(benchmark_state); 338 | return; 339 | } 340 | 341 | BENCHMARK(luacppinterface_table_global_string_get_measure); 342 | BENCHMARK(luacppinterface_table_global_string_set_measure); 343 | BENCHMARK(luacppinterface_table_get_measure); 344 | BENCHMARK(luacppinterface_table_set_measure); 345 | BENCHMARK(luacppinterface_table_chained_get_measure); 346 | BENCHMARK(luacppinterface_table_chained_set_measure); 347 | BENCHMARK(luacppinterface_c_function_measure); 348 | BENCHMARK(luacppinterface_c_function_through_lua_in_c_measure); 349 | BENCHMARK(luacppinterface_lua_function_in_c_measure); 350 | BENCHMARK(luacppinterface_member_function_call_measure); 351 | BENCHMARK(luacppinterface_userdata_variable_access_measure); 352 | BENCHMARK(luacppinterface_userdata_variable_access_large_measure); 353 | BENCHMARK(luacppinterface_userdata_variable_access_last_measure); 354 | BENCHMARK(luacppinterface_multi_return_measure); 355 | BENCHMARK(luacppinterface_multi_return_lua_measure); 356 | BENCHMARK(luacppinterface_stateful_function_object_measure); 357 | BENCHMARK(luacppinterface_base_derived_measure); 358 | BENCHMARK(luacppinterface_return_userdata_measure); 359 | BENCHMARK(luacppinterface_optional_success_measure); 360 | BENCHMARK(luacppinterface_optional_half_failure_measure); 361 | BENCHMARK(luacppinterface_optional_failure_measure); 362 | BENCHMARK(luacppinterface_implicit_inheritance_measure); 363 | -------------------------------------------------------------------------------- /source/luwra.cpp: -------------------------------------------------------------------------------- 1 | // lua bindings shootout 2 | // The MIT License (MIT) 3 | 4 | // Copyright © 2018 ThePhD 5 | 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | // this software and associated documentation files (the "Software"), to deal in 8 | // the Software without restriction, including without limitation the rights to 9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | // the Software, and to permit persons to whom the Software is furnished to do so, 11 | // subject to the following conditions: 12 | 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | #include 24 | 25 | #include "benchmark.hpp" 26 | #include "lbs_lua.hpp" 27 | #include "lbs_lib.hpp" 28 | 29 | void luwra_table_global_string_get_measure(benchmark::State& benchmark_state) { 30 | luwra::StateWrapper lua; 31 | lua_State* L = lua.state.get(); 32 | lua_atpanic(lua, lbs::panic_throw); 33 | 34 | lua["value"] = lbs::magic_value(); 35 | 36 | double x = 0; 37 | for (auto _ : benchmark_state) { 38 | double v = lua["value"]; 39 | x += v; 40 | } 41 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 42 | } 43 | 44 | void luwra_table_global_string_set_measure(benchmark::State& benchmark_state) { 45 | luwra::StateWrapper lua; 46 | lua_State* L = lua.state.get(); 47 | lua_atpanic(lua, lbs::panic_throw); 48 | 49 | double v = 0; 50 | for (auto _ : benchmark_state) { 51 | v += lbs::magic_value(); 52 | lua["value"] = v; 53 | } 54 | double x = lua["value"]; 55 | lbs::expect(benchmark_state, x, v); 56 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 57 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 58 | } 59 | 60 | void luwra_table_chained_get_measure(benchmark::State& benchmark_state) { 61 | luwra::StateWrapper lua; 62 | lua_State* L = lua.state.get(); 63 | lua_atpanic(lua, lbs::panic_throw); 64 | 65 | std::string precode = "ulahibe={warble={value = " + lbs::magic_value_string() + "}}"; 66 | lua.runString(precode.c_str()); 67 | 68 | double x = 0; 69 | for (auto _ : benchmark_state) { 70 | double v = lua["ulahibe"]["warble"]["value"]; 71 | x += v; 72 | } 73 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 74 | } 75 | 76 | void luwra_table_chained_set_measure(benchmark::State& benchmark_state) { 77 | luwra::StateWrapper lua; 78 | lua_State* L = lua.state.get(); 79 | lua_atpanic(lua, lbs::panic_throw); 80 | 81 | std::string precode = "ulahibe={warble={value = " + lbs::magic_value_string() + "}}"; 82 | lua.runString(precode.c_str()); 83 | 84 | double v = 0; 85 | for (auto _ : benchmark_state) { 86 | v += lbs::magic_value(); 87 | lua["ulahibe"]["warble"]["value"] = v; 88 | } 89 | double x = lua["ulahibe"]["warble"]["value"]; 90 | lbs::expect(benchmark_state, x, v); 91 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 92 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 93 | } 94 | 95 | void luwra_table_get_measure(benchmark::State& benchmark_state) { 96 | luwra::StateWrapper lua; 97 | lua_State* L = lua.state.get(); 98 | lua_atpanic(lua, lbs::panic_throw); 99 | 100 | std::string precode = "warble={value = " + lbs::magic_value_string() + "}"; 101 | lua.runString(precode.c_str()); 102 | 103 | double x = 0; 104 | for (auto _ : benchmark_state) { 105 | double v = lua["warble"]["value"]; 106 | x += v; 107 | } 108 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 109 | } 110 | 111 | void luwra_table_set_measure(benchmark::State& benchmark_state) { 112 | luwra::StateWrapper lua; 113 | lua_State* L = lua.state.get(); 114 | lua_atpanic(lua, lbs::panic_throw); 115 | 116 | std::string precode = "warble={value = " + lbs::magic_value_string() + "}"; 117 | lua.runString(precode.c_str()); 118 | 119 | double v = 0; 120 | for (auto _ : benchmark_state) { 121 | v += lbs::magic_value(); 122 | lua["warble"]["value"] = v; 123 | } 124 | double x = lua["warble"]["value"]; 125 | lbs::expect(benchmark_state, x, v); 126 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 127 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 128 | } 129 | 130 | void luwra_c_function_measure(benchmark::State& benchmark_state) { 131 | luwra::StateWrapper lua; 132 | lua_State* L = lua.state.get(); 133 | luaL_openlibs(L); 134 | lua_atpanic(L, lbs::panic_throw); 135 | 136 | lua["f"] = LUWRA_WRAP(lbs::basic_call); 137 | 138 | lbs::lua_bench_do_or_die(L, lbs::c_function_check); 139 | 140 | std::string code = lbs::repeated_code(lbs::c_function_code); 141 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 142 | for (auto _ : benchmark_state) { 143 | lbs::lua_bench_preload_do_or_die(L, code_index); 144 | } 145 | lbs::lua_bench_unload(L, code_index); 146 | } 147 | 148 | void luwra_lua_function_in_c_measure(benchmark::State& benchmark_state) { 149 | luwra::StateWrapper lua; 150 | lua_State* L = lua.state.get(); 151 | lua_atpanic(L, lbs::panic_throw); 152 | 153 | lua.runString(R"(function f (i) return i end)"); 154 | // Unless we specifically get it like this, 155 | // it picks the wrong overload in VC++ 156 | // I am too tired to fix this and honestly this bullshit shouldn't 157 | // be happening, who the fuck overloads on `const &&` ???? 158 | luwra::Function f = lua["f"].read>(); 159 | double x = 0; 160 | for (auto _ : benchmark_state) { 161 | double v = f(lbs::magic_value()); 162 | x += v; 163 | } 164 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 165 | } 166 | 167 | void luwra_c_function_through_lua_in_c_measure(benchmark::State& benchmark_state) { 168 | luwra::StateWrapper lua; 169 | lua_State* L = lua.state.get(); 170 | lua_atpanic(lua, lbs::panic_throw); 171 | 172 | lua["f"] = LUWRA_WRAP(lbs::basic_call); 173 | 174 | // Unless we specifically get it like this, 175 | // it picks the wrong overload in VC++ 176 | // I am too tired to fix this and honestly this bullshit shouldn't 177 | // be happening, who the fuck overloads on `const &&` ???? 178 | luwra::Function f = lua["f"].read>(); 179 | double x = 0; 180 | for (auto _ : benchmark_state) { 181 | double v = f(lbs::magic_value()); 182 | x += v; 183 | } 184 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 185 | } 186 | 187 | void luwra_member_function_call_measure(benchmark::State& benchmark_state) { 188 | luwra::StateWrapper lua; 189 | lua_State* L = lua.state.get(); 190 | luaL_openlibs(L); 191 | lua_atpanic(lua, lbs::panic_throw); 192 | 193 | lua.registerUserType( 194 | "basic", 195 | { LUWRA_MEMBER(lbs::basic, get), LUWRA_MEMBER(lbs::basic, set) }); 196 | lua.runString("b = basic()"); 197 | 198 | lbs::lua_bench_do_or_die(L, lbs::member_function_call_check); 199 | 200 | std::string code = lbs::repeated_code(lbs::member_function_call_code); 201 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 202 | for (auto _ : benchmark_state) { 203 | lbs::lua_bench_preload_do_or_die(L, code_index); 204 | } 205 | lbs::lua_bench_unload(L, code_index); 206 | } 207 | 208 | void luwra_userdata_variable_access_measure(benchmark::State& benchmark_state) { 209 | // Unsupported 210 | lbs::unsupported(benchmark_state); 211 | return; 212 | /* 213 | luwra::StateWrapper lua; 214 | lua_State* L = lua.state.get(); 215 | lua_atpanic(lua, lbs::panic_throw); 216 | lua.registerMember("var", &lbs::basic::var); 217 | lua.writeVariable("b", lbs::basic()); 218 | std::string code = lbs::repeated_code("b.var = i\nx = b.var"); 219 | for (auto _ : benchmark_state) { 220 | lua.runString(code.c_str()); 221 | } 222 | */ 223 | } 224 | 225 | void luwra_userdata_variable_access_last_measure(benchmark::State& benchmark_state) { 226 | // Unsupported 227 | lbs::unsupported(benchmark_state); 228 | return; 229 | } 230 | 231 | void luwra_userdata_variable_access_large_measure(benchmark::State& benchmark_state) { 232 | // Unsupported 233 | lbs::unsupported(benchmark_state); 234 | return; 235 | } 236 | 237 | void luwra_stateful_function_object_measure(benchmark::State& benchmark_state) { 238 | luwra::StateWrapper lua; 239 | lua_State* L = lua.state.get(); 240 | luaL_openlibs(L); 241 | lua_atpanic(lua, lbs::panic_throw); 242 | 243 | // Have to register as a usertype to get it. 244 | lua.registerUserType( 245 | "cs", 246 | {}, 247 | { { "__call", LUWRA_WRAP_MEMBER(lbs::basic_stateful, operator()) } }); 248 | lua.set("f", lbs::basic_stateful()); 249 | // Unless we specifically get it like this, 250 | // it picks the wrong overload in VC++ 251 | // I am too tired to fix this and honestly this bullshit shouldn't 252 | // be happening, who the fuck overloads on `const &&` ???? 253 | luwra::Function f = lua["f"].read>(); 254 | double x = 0; 255 | for (auto _ : benchmark_state) { 256 | double v = f(lbs::magic_value()); 257 | x += v; 258 | } 259 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 260 | } 261 | 262 | void luwra_multi_return_lua_measure(benchmark::State& benchmark_state) { 263 | luwra::StateWrapper lua; 264 | lua_State* L = lua.state.get(); 265 | luaL_openlibs(L); 266 | lua_atpanic(lua, lbs::panic_throw); 267 | 268 | lua.set("f", LUWRA_WRAP(lbs::basic_multi_return)); 269 | 270 | lbs::lua_bench_do_or_die(L, lbs::lua_multi_return_check); 271 | 272 | std::string code = lbs::repeated_code(lbs::lua_multi_return_code); 273 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 274 | for (auto _ : benchmark_state) { 275 | lbs::lua_bench_preload_do_or_die(L, code_index); 276 | } 277 | lbs::lua_bench_unload(L, code_index); 278 | } 279 | 280 | void luwra_multi_return_measure(benchmark::State& benchmark_state) { 281 | // Unsupported 282 | // std::tuple returns still not supported... 283 | // G R E A T 284 | 285 | lbs::unsupported(benchmark_state); 286 | return; 287 | 288 | luwra::StateWrapper lua; 289 | lua_State* L = lua.state.get(); 290 | luaL_openlibs(L); 291 | lua_atpanic(lua, lbs::panic_throw); 292 | 293 | lua.set("f", LUWRA_WRAP(lbs::basic_multi_return)); 294 | // Unless we specifically get it like this, 295 | // it picks the wrong overload in VC++ 296 | // I am too tired to fix this and honestly this bullshit shouldn't 297 | // be happening, who the fuck overloads on `const &&` ???? 298 | luwra::Function> f = lua["f"].read>>(); 299 | double x = 0; 300 | for (auto _ : benchmark_state) { 301 | std::tuple v = f(lbs::magic_value()); 302 | x += static_cast(std::get<0>(v)); 303 | x += static_cast(std::get<1>(v)); 304 | } 305 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * (lbs::magic_value() * 3)); 306 | } 307 | 308 | void luwra_base_derived_measure(benchmark::State& benchmark_state) { 309 | // Unsupported: 310 | // Luwra does not internally handle base classes 311 | // have to do it yourself 312 | 313 | lbs::unsupported(benchmark_state); 314 | return; 315 | 316 | luwra::StateWrapper lua; 317 | lua_State* L = lua.state.get(); 318 | lua_atpanic(lua, lbs::panic_throw); 319 | 320 | lua.registerUserType(); 321 | lbs::complex_ab ab; 322 | // Set and verify correctness 323 | lua.set("b", &ab); 324 | { 325 | lbs::complex_base_a* va = lua["b"].read(); 326 | lbs::complex_base_b* vb = lua["b"].read(); 327 | if (!lbs::verify_base_correctness(*va, *vb, ab)) { 328 | lbs::unsupported(benchmark_state); 329 | return; 330 | } 331 | } 332 | double x = 0; 333 | for (auto _ : benchmark_state) { 334 | lbs::complex_base_a* va = lua["b"].read(); 335 | lbs::complex_base_b* vb = lua["b"].read(); 336 | x += va->a_func(); 337 | x += vb->b_func(); 338 | } 339 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * (lbs::magic_value() * 2)); 340 | } 341 | 342 | void luwra_return_userdata_measure(benchmark::State& benchmark_state) { 343 | luwra::StateWrapper lua; 344 | lua_State* L = lua.state.get(); 345 | luaL_openlibs(L); 346 | lua_atpanic(lua, lbs::panic_throw); 347 | 348 | lua.set("f", LUWRA_WRAP(lbs::basic_return)); 349 | lua.set("h", LUWRA_WRAP(lbs::basic_get_var)); 350 | 351 | lbs::lua_bench_do_or_die(L, lbs::return_userdata_check); 352 | 353 | std::string code = lbs::repeated_code(lbs::return_userdata_code); 354 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 355 | for (auto _ : benchmark_state) { 356 | lbs::lua_bench_preload_do_or_die(L, code_index); 357 | } 358 | lbs::lua_bench_unload(L, code_index); 359 | } 360 | 361 | void luwra_optional_success_measure(benchmark::State& benchmark_state) { 362 | // UNSUPPORTED: 363 | // Luwra does not let you check if something exists with its own abstractions, 364 | // therefore will call panic function 365 | 366 | lbs::unsupported(benchmark_state); 367 | return; 368 | 369 | luwra::StateWrapper lua; 370 | lua_State* L = lua.state.get(); 371 | lua_atpanic(lua, lbs::panic_throw); 372 | 373 | double x = 0; 374 | for (auto _ : benchmark_state) { 375 | double v = lua["warble"]["value"]; 376 | x += v; 377 | } 378 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * 1); 379 | } 380 | 381 | void luwra_optional_half_failure_measure(benchmark::State& benchmark_state) { 382 | // UNSUPPORTED: 383 | // Luwra does not let you check if something exists with its own abstractions, 384 | // therefore will call panic function 385 | 386 | lbs::unsupported(benchmark_state); 387 | return; 388 | 389 | luwra::StateWrapper lua; 390 | lua_State* L = lua.state.get(); 391 | lua_atpanic(lua, lbs::panic_throw); 392 | 393 | double x = 0; 394 | for (auto _ : benchmark_state) { 395 | double v = lua["warble"]["value"]; 396 | x += v; 397 | } 398 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * 1); 399 | } 400 | 401 | void luwra_optional_failure_measure(benchmark::State& benchmark_state) { 402 | // UNSUPPORTED: 403 | // Luwra does not let you check if something exists with its own abstractions, 404 | // therefore will call panic function 405 | 406 | lbs::unsupported(benchmark_state); 407 | return; 408 | 409 | luwra::StateWrapper lua; 410 | lua_State* L = lua.state.get(); 411 | lua_atpanic(lua, lbs::panic_throw); 412 | 413 | double x = 0; 414 | for (auto _ : benchmark_state) { 415 | double v = lua["warble"]["value"]; 416 | x += v; 417 | } 418 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * 1); 419 | } 420 | 421 | void luwra_implicit_inheritance_measure(benchmark::State& benchmark_state) { 422 | // Unsupported? 423 | // Should contact author about whether or not this would work 424 | 425 | lbs::unsupported(benchmark_state); 426 | return; 427 | 428 | luwra::StateWrapper lua; 429 | lua_State* L = lua.state.get(); 430 | lua_atpanic(lua, lbs::panic_throw); 431 | } 432 | 433 | BENCHMARK(luwra_table_global_string_get_measure); 434 | BENCHMARK(luwra_table_global_string_set_measure); 435 | BENCHMARK(luwra_table_get_measure); 436 | BENCHMARK(luwra_table_set_measure); 437 | BENCHMARK(luwra_table_chained_get_measure); 438 | BENCHMARK(luwra_table_chained_set_measure); 439 | BENCHMARK(luwra_c_function_measure); 440 | BENCHMARK(luwra_c_function_through_lua_in_c_measure); 441 | BENCHMARK(luwra_lua_function_in_c_measure); 442 | BENCHMARK(luwra_member_function_call_measure); 443 | BENCHMARK(luwra_userdata_variable_access_measure); 444 | BENCHMARK(luwra_userdata_variable_access_large_measure); 445 | BENCHMARK(luwra_userdata_variable_access_last_measure); 446 | BENCHMARK(luwra_multi_return_lua_measure); 447 | BENCHMARK(luwra_multi_return_measure); 448 | BENCHMARK(luwra_stateful_function_object_measure); 449 | BENCHMARK(luwra_base_derived_measure); 450 | BENCHMARK(luwra_return_userdata_measure); 451 | BENCHMARK(luwra_optional_success_measure); 452 | BENCHMARK(luwra_optional_half_failure_measure); 453 | BENCHMARK(luwra_optional_failure_measure); 454 | BENCHMARK(luwra_implicit_inheritance_measure); 455 | -------------------------------------------------------------------------------- /source/selene.cpp: -------------------------------------------------------------------------------- 1 | // lua bindings shootout 2 | // The MIT License (MIT) 3 | 4 | // Copyright © 2018 ThePhD 5 | 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | // this software and associated documentation files (the "Software"), to deal in 8 | // the Software without restriction, including without limitation the rights to 9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | // the Software, and to permit persons to whom the Software is furnished to do so, 11 | // subject to the following conditions: 12 | 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | #include "lbs_lua.hpp" 24 | #include "lbs_lib.hpp" 25 | #include "benchmark.hpp" 26 | 27 | #include 28 | 29 | void selene_table_global_string_get_measure(benchmark::State& benchmark_state) { 30 | sel::State lua; 31 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 32 | lua["value"] = lbs::magic_value(); 33 | double x = 0; 34 | for (auto _ : benchmark_state) { 35 | double v = lua["value"]; 36 | x += v; 37 | } 38 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 39 | } 40 | 41 | void selene_table_global_string_set_measure(benchmark::State& benchmark_state) { 42 | sel::State lua; 43 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 44 | double v = 0; 45 | for (auto _ : benchmark_state) { 46 | v += lbs::magic_value(); 47 | lua["value"] = v; 48 | } 49 | double x = lua["value"]; 50 | lbs::expect(benchmark_state, x, v); 51 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 52 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 53 | } 54 | 55 | void selene_table_chained_get_measure(benchmark::State& benchmark_state) { 56 | sel::State lua; 57 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 58 | 59 | lua["ulahibe"]["warble"]["value"] = lbs::magic_value(); 60 | double x = 0; 61 | for (auto _ : benchmark_state) { 62 | double v = lua["ulahibe"]["warble"]["value"]; 63 | x += v; 64 | } 65 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 66 | } 67 | 68 | void selene_table_chained_set_measure(benchmark::State& benchmark_state) { 69 | sel::State lua; 70 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 71 | 72 | double v = 0; 73 | for (auto _ : benchmark_state) { 74 | v += lbs::magic_value(); 75 | lua["ulahibe"]["warble"]["value"] = v; 76 | } 77 | double x = lua["ulahibe"]["warble"]["value"]; 78 | lbs::expect(benchmark_state, x, v); 79 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 80 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 81 | } 82 | 83 | void selene_table_get_measure(benchmark::State& benchmark_state) { 84 | sel::State lua; 85 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 86 | 87 | auto t = lua["warble"]; 88 | t["value"] = lbs::magic_value(); 89 | double x = 0; 90 | for (auto _ : benchmark_state) { 91 | double v = t["value"]; 92 | x += v; 93 | } 94 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 95 | } 96 | 97 | void selene_table_set_measure(benchmark::State& benchmark_state) { 98 | sel::State lua; 99 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 100 | 101 | auto t = lua["value"]; 102 | double v = 0; 103 | for (auto _ : benchmark_state) { 104 | v += lbs::magic_value(); 105 | t["warble"] = v; 106 | } 107 | double x = t["warble"]; 108 | lbs::expect(benchmark_state, x, v); 109 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 110 | lbs::expect(benchmark_state, v, benchmark_state.iterations() * lbs::magic_value()); 111 | } 112 | 113 | void selene_c_function_measure(benchmark::State& benchmark_state) { 114 | sel::State lua{ true }; 115 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 116 | 117 | lua["f"] = lbs::basic_call; 118 | std::string code = lbs::repeated_code("f(i)"); 119 | for (auto _ : benchmark_state) { 120 | lua(code.c_str()); 121 | } 122 | } 123 | 124 | void selene_lua_function_in_c_measure(benchmark::State& benchmark_state) { 125 | sel::State lua; 126 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 127 | 128 | lua(R"(function f (i) 129 | return i; 130 | end)"); 131 | sel::function f = lua["f"]; 132 | 133 | double x = 0; 134 | for (auto _ : benchmark_state) { 135 | double v = f(lbs::magic_value()); 136 | x += v; 137 | } 138 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 139 | } 140 | 141 | void selene_c_function_through_lua_in_c_measure(benchmark::State& benchmark_state) { 142 | sel::State lua; 143 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 144 | 145 | lua["f"] = lbs::basic_call; 146 | sel::function f = lua["f"]; 147 | double x = 0; 148 | for (auto _ : benchmark_state) { 149 | double v = f(lbs::magic_value()); 150 | x += v; 151 | } 152 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 153 | } 154 | 155 | void selene_member_function_call_measure(benchmark::State& benchmark_state) { 156 | sel::State lua{ true }; 157 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 158 | 159 | lua["c"].SetClass( 160 | "get", &lbs::basic::get, 161 | "set", &lbs::basic::set); 162 | lua("b = c.new()"); 163 | 164 | lua(lbs::member_function_call_check.c_str()); 165 | 166 | std::string code = lbs::repeated_code(lbs::member_function_call_code); 167 | for (auto _ : benchmark_state) { 168 | lua(code.c_str()); 169 | } 170 | } 171 | 172 | void selene_userdata_variable_access_measure(benchmark::State& benchmark_state) { 173 | // Unsupported 174 | // just converts everything to functions 175 | lbs::unsupported(benchmark_state); 176 | return; 177 | 178 | sel::State lua{ true }; 179 | lua["c"].SetClass( 180 | "var", &lbs::basic::var, 181 | "set", &lbs::basic::set, 182 | "get", &lbs::basic::get); 183 | lua("b = c.new()"); 184 | std::string code = lbs::repeated_code(lbs::userdata_variable_access_code); 185 | for (auto _ : benchmark_state) { 186 | lua(code.c_str()); 187 | } 188 | } 189 | 190 | void selene_userdata_variable_access_large_measure(benchmark::State& benchmark_state) { 191 | // Unsupported 192 | // just converts everything to functions 193 | lbs::unsupported(benchmark_state); 194 | return; 195 | } 196 | 197 | void selene_userdata_variable_access_last_measure(benchmark::State& benchmark_state) { 198 | // Unsupported 199 | // just converts everything to functions 200 | 201 | lbs::unsupported(benchmark_state); 202 | return; 203 | } 204 | 205 | void selene_stateful_function_object_measure(benchmark::State& benchmark_state) { 206 | sel::State lua; 207 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 208 | 209 | lua["f"] = lbs::basic_stateful(); 210 | sel::function f = lua["f"]; 211 | double x = 0; 212 | for (auto _ : benchmark_state) { 213 | double v = f(lbs::magic_value()); 214 | x += v; 215 | } 216 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 217 | } 218 | 219 | void selene_multi_return_lua_measure(benchmark::State& benchmark_state) { 220 | sel::State lua{ true }; 221 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 222 | 223 | lua["f"] = lbs::basic_multi_return; 224 | 225 | lua(lbs::lua_multi_return_check.c_str()); 226 | 227 | std::string code = lbs::repeated_code(lbs::lua_multi_return_code); 228 | for (auto _ : benchmark_state) { 229 | lua(code.c_str()); 230 | } 231 | } 232 | 233 | void selene_multi_return_measure(benchmark::State& benchmark_state) { 234 | sel::State lua; 235 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 236 | 237 | lua["f"] = lbs::basic_multi_return; 238 | sel::function(double)> f = lua["f"]; 239 | double x = 0; 240 | for (auto _ : benchmark_state) { 241 | std::tuple v = f(lbs::magic_value()); 242 | x += std::get<0>(v); 243 | x += std::get<1>(v); 244 | } 245 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * (lbs::magic_value() * 3)); 246 | } 247 | 248 | void selene_base_derived_measure(benchmark::State& benchmark_state) { 249 | // Explicitly unsupported, 250 | // as stated by the Readme for inheritance 251 | lbs::unsupported(benchmark_state); 252 | return; 253 | } 254 | 255 | void selene_optional_success_measure(benchmark::State& benchmark_state) { 256 | sel::State lua; 257 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 258 | 259 | lua(lbs::optional_success_precode.c_str()); 260 | 261 | double x = 0; 262 | for (auto _ : benchmark_state) { 263 | auto cache = lua["warble"]["value"]; 264 | if (cache.exists()) { 265 | double v = cache; 266 | x += v; 267 | } 268 | else { 269 | x += 1; 270 | } 271 | } 272 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * lbs::magic_value()); 273 | } 274 | 275 | void selene_optional_half_failure_measure(benchmark::State& benchmark_state) { 276 | sel::State lua; 277 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 278 | 279 | lua(lbs::optional_half_failure_precode.c_str()); 280 | 281 | double x = 0; 282 | for (auto _ : benchmark_state) { 283 | auto cache = lua["warble"]["value"]; 284 | if (cache.exists()) { 285 | double v = cache; 286 | x += v; 287 | } 288 | else { 289 | x += 1; 290 | } 291 | } 292 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * 1); 293 | } 294 | 295 | void selene_optional_failure_measure(benchmark::State& benchmark_state) { 296 | sel::State lua; 297 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 298 | 299 | double x = 0; 300 | for (auto _ : benchmark_state) { 301 | auto cache = lua["warble"]["value"]; 302 | if (cache.exists()) { 303 | double v = cache; 304 | x += v; 305 | } 306 | else { 307 | x += 1; 308 | } 309 | } 310 | lbs::expect(benchmark_state, x, benchmark_state.iterations() * 1); 311 | } 312 | 313 | void selene_return_userdata_measure(benchmark::State& benchmark_state) { 314 | sel::State lua{ true }; 315 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 316 | 317 | lua["c"].SetClass(); 318 | lua["f"] = lbs::basic_return; 319 | lua["h"] = lbs::basic_get_var; 320 | 321 | lua(lbs::return_userdata_check.c_str()); 322 | 323 | std::string code = lbs::repeated_code(lbs::return_userdata_code); 324 | for (auto _ : benchmark_state) { 325 | lua(code.c_str()); 326 | } 327 | } 328 | 329 | void selene_implicit_inheritance_measure(benchmark::State& benchmark_state) { 330 | // UNSUPPORTED 331 | // The below code doesn't work and calls panic 332 | lbs::unsupported(benchmark_state); 333 | return; 334 | 335 | sel::State lua{ true }; 336 | lua.HandleExceptionsWith(lbs::selene_panic_throw); 337 | 338 | lua["ca"].SetClass( 339 | "a", &lbs::complex_base_a::a, 340 | "a_func", &lbs::complex_base_a::a_func); 341 | lua["cb"].SetClass( 342 | "b", &lbs::complex_base_b::b, 343 | "b_func", &lbs::complex_base_b::b_func); 344 | lua["cab"].SetClass( 345 | "ab", &lbs::complex_ab::ab, 346 | "ab_func", &lbs::complex_ab::ab_func); 347 | 348 | lua("b = cab.new()"); 349 | 350 | lua(lbs::implicit_inheritance_check.c_str()); 351 | 352 | std::string code = lbs::repeated_code(lbs::implicit_inheritance_code); 353 | for (auto _ : benchmark_state) { 354 | lua(code.c_str()); 355 | } 356 | } 357 | 358 | BENCHMARK(selene_table_global_string_get_measure); 359 | BENCHMARK(selene_table_global_string_set_measure); 360 | BENCHMARK(selene_table_get_measure); 361 | BENCHMARK(selene_table_set_measure); 362 | BENCHMARK(selene_table_chained_get_measure); 363 | BENCHMARK(selene_table_chained_set_measure); 364 | BENCHMARK(selene_c_function_measure); 365 | BENCHMARK(selene_c_function_through_lua_in_c_measure); 366 | BENCHMARK(selene_lua_function_in_c_measure); 367 | BENCHMARK(selene_member_function_call_measure); 368 | BENCHMARK(selene_userdata_variable_access_measure); 369 | BENCHMARK(selene_userdata_variable_access_large_measure); 370 | BENCHMARK(selene_userdata_variable_access_last_measure); 371 | BENCHMARK(selene_multi_return_lua_measure); 372 | BENCHMARK(selene_multi_return_measure); 373 | BENCHMARK(selene_stateful_function_object_measure); 374 | BENCHMARK(selene_base_derived_measure); 375 | BENCHMARK(selene_return_userdata_measure); 376 | BENCHMARK(selene_optional_success_measure); 377 | BENCHMARK(selene_optional_half_failure_measure); 378 | BENCHMARK(selene_optional_failure_measure); 379 | BENCHMARK(selene_implicit_inheritance_measure); 380 | -------------------------------------------------------------------------------- /source/swig.cpp: -------------------------------------------------------------------------------- 1 | // lua bindings shootout 2 | // The MIT License (MIT) 3 | 4 | // Copyright � 2018 ThePhD 5 | 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | // this software and associated documentation files (the "Software"), to deal in 8 | // the Software without restriction, including without limitation the rights to 9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | // the Software, and to permit persons to whom the Software is furnished to do so, 11 | // subject to the following conditions: 12 | 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | #include "benchmark.hpp" 24 | #include "lbs_lib.hpp" 25 | #include "lbs_lua.hpp" 26 | 27 | #include "swig_lib.gen.hpp" 28 | 29 | void swig_table_global_string_get_measure(benchmark::State& benchmark_state) { 30 | // Unsupported 31 | lbs::unsupported(benchmark_state); 32 | return; 33 | } 34 | 35 | void swig_table_global_string_set_measure(benchmark::State& benchmark_state) { 36 | // Unsupported 37 | lbs::unsupported(benchmark_state); 38 | return; 39 | } 40 | 41 | void swig_table_get_measure(benchmark::State& benchmark_state) { 42 | // Unsupported 43 | lbs::unsupported(benchmark_state); 44 | return; 45 | } 46 | 47 | void swig_table_set_measure(benchmark::State& benchmark_state) { 48 | // Unsupported 49 | lbs::unsupported(benchmark_state); 50 | return; 51 | } 52 | 53 | void swig_table_chained_get_measure(benchmark::State& benchmark_state) { 54 | // Unsupported 55 | lbs::unsupported(benchmark_state); 56 | return; 57 | } 58 | 59 | void swig_table_chained_set_measure(benchmark::State& benchmark_state) { 60 | // Unsupported 61 | lbs::unsupported(benchmark_state); 62 | return; 63 | } 64 | 65 | void swig_c_function_measure(benchmark::State& benchmark_state) { 66 | auto lua = lbs::create_state(true); 67 | lua_State* L = lua.get(); 68 | 69 | 70 | luaopen_swig_lib(L); 71 | lbs::lua_bench_do_or_die(L, "f = swig_lib.basic_call"); 72 | 73 | lbs::lua_bench_do_or_die(L, lbs::c_function_check); 74 | 75 | std::string code = lbs::repeated_code(lbs::c_function_code); 76 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 77 | for (auto _ : benchmark_state) { 78 | lbs::lua_bench_preload_do_or_die(L, code_index); 79 | } 80 | lbs::lua_bench_unload(L, code_index); 81 | } 82 | 83 | void swig_lua_function_in_c_measure(benchmark::State& benchmark_state) { 84 | // Unsupported 85 | lbs::unsupported(benchmark_state); 86 | return; 87 | } 88 | 89 | void swig_c_function_through_lua_in_c_measure(benchmark::State& benchmark_state) { 90 | // Unsupported 91 | lbs::unsupported(benchmark_state); 92 | return; 93 | } 94 | 95 | void swig_member_function_call_measure(benchmark::State& benchmark_state) { 96 | auto lua = lbs::create_state(true); 97 | lua_State* L = lua.get(); 98 | 99 | 100 | luaopen_swig_lib(L); 101 | lbs::lua_bench_do_or_die(L, "b = swig_lib.basic()"); 102 | 103 | lbs::lua_bench_do_or_die(L, lbs::member_function_call_check); 104 | 105 | std::string code = lbs::repeated_code(lbs::member_function_call_code); 106 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 107 | for (auto _ : benchmark_state) { 108 | lbs::lua_bench_preload_do_or_die(L, code_index); 109 | } 110 | lbs::lua_bench_unload(L, code_index); 111 | } 112 | 113 | void swig_userdata_variable_access_measure(benchmark::State& benchmark_state) { 114 | auto lua = lbs::create_state(true); 115 | lua_State* L = lua.get(); 116 | 117 | 118 | luaopen_swig_lib(L); 119 | lbs::lua_bench_do_or_die(L, "b = swig_lib.basic()"); 120 | 121 | lbs::lua_bench_do_or_die(L, lbs::userdata_variable_access_check); 122 | 123 | std::string code = lbs::repeated_code(lbs::userdata_variable_access_code); 124 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 125 | for (auto _ : benchmark_state) { 126 | lbs::lua_bench_preload_do_or_die(L, code_index); 127 | } 128 | lbs::lua_bench_unload(L, code_index); 129 | } 130 | 131 | void swig_userdata_variable_access_large_measure(benchmark::State& benchmark_state) { 132 | // Unsupported 133 | // int64_t is not treated as an integral type 134 | lbs::unsupported(benchmark_state); 135 | return; 136 | 137 | auto lua = lbs::create_state(true); 138 | lua_State* L = lua.get(); 139 | 140 | 141 | luaopen_swig_lib(L); 142 | lbs::lua_bench_do_or_die(L, "b = swig_lib.basic_large()"); 143 | 144 | lbs::lua_bench_do_or_die(L, lbs::userdata_variable_access_large_check); 145 | 146 | std::string code = lbs::repeated_code(lbs::userdata_variable_access_large_code); 147 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 148 | for (auto _ : benchmark_state) { 149 | lbs::lua_bench_preload_do_or_die(L, code_index); 150 | } 151 | lbs::lua_bench_unload(L, code_index); 152 | } 153 | 154 | void swig_userdata_variable_access_last_measure(benchmark::State& benchmark_state) { 155 | // Unsupported 156 | // int64_t is not treated as an integral type 157 | lbs::unsupported(benchmark_state); 158 | return; 159 | 160 | auto lua = lbs::create_state(true); 161 | lua_State* L = lua.get(); 162 | 163 | 164 | luaopen_swig_lib(L); 165 | lbs::lua_bench_do_or_die(L, "b = swig_lib.basic_large()"); 166 | 167 | lbs::lua_bench_do_or_die(L, lbs::userdata_variable_access_large_last_check); 168 | 169 | std::string code = lbs::repeated_code(lbs::userdata_variable_access_large_last_code); 170 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 171 | for (auto _ : benchmark_state) { 172 | lbs::lua_bench_preload_do_or_die(L, code_index); 173 | } 174 | lbs::lua_bench_unload(L, code_index); 175 | } 176 | 177 | void swig_stateful_function_object_measure(benchmark::State& benchmark_state) { 178 | // Unsupported 179 | lbs::unsupported(benchmark_state); 180 | return; 181 | } 182 | 183 | void swig_multi_return_measure(benchmark::State& benchmark_state) { 184 | // Unsupported 185 | lbs::unsupported(benchmark_state); 186 | return; 187 | } 188 | 189 | void swig_multi_return_lua_measure(benchmark::State& benchmark_state) { 190 | auto lua = lbs::create_state(true); 191 | lua_State* L = lua.get(); 192 | 193 | 194 | luaopen_swig_lib(L); 195 | lbs::lua_bench_do_or_die(L, "f = swig_lib.basic_multi_return_out"); 196 | 197 | lbs::lua_bench_do_or_die(L, lbs::lua_multi_return_check); 198 | 199 | std::string code = lbs::repeated_code(lbs::lua_multi_return_code); 200 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 201 | for (auto _ : benchmark_state) { 202 | lbs::lua_bench_preload_do_or_die(L, code_index); 203 | } 204 | lbs::lua_bench_unload(L, code_index); 205 | } 206 | 207 | void swig_base_derived_measure(benchmark::State& benchmark_state) { 208 | // Unsupported 209 | lbs::unsupported(benchmark_state); 210 | return; 211 | } 212 | 213 | void swig_optional_success_measure(benchmark::State& benchmark_state) { 214 | // Unsupported 215 | lbs::unsupported(benchmark_state); 216 | return; 217 | } 218 | 219 | void swig_optional_half_failure_measure(benchmark::State& benchmark_state) { 220 | // Unsupported 221 | lbs::unsupported(benchmark_state); 222 | return; 223 | } 224 | 225 | void swig_optional_failure_measure(benchmark::State& benchmark_state) { 226 | // Unsupported 227 | lbs::unsupported(benchmark_state); 228 | return; 229 | } 230 | 231 | void swig_return_userdata_measure(benchmark::State& benchmark_state) { 232 | auto lua = lbs::create_state(true); 233 | lua_State* L = lua.get(); 234 | 235 | 236 | luaopen_swig_lib(L); 237 | lbs::lua_bench_do_or_die(L, "f = swig_lib.basic_return"); 238 | lbs::lua_bench_do_or_die(L, "h = swig_lib.basic_get_var"); 239 | 240 | lbs::lua_bench_do_or_die(L, lbs::return_userdata_check); 241 | 242 | std::string code = lbs::repeated_code(lbs::return_userdata_code); 243 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 244 | for (auto _ : benchmark_state) { 245 | lbs::lua_bench_preload_do_or_die(L, code_index); 246 | } 247 | lbs::lua_bench_unload(L, code_index); 248 | } 249 | 250 | void swig_implicit_inheritance_measure(benchmark::State& benchmark_state) { 251 | // Unsupported 252 | // E.g., we're doing something wrong 253 | auto lua = lbs::create_state(true); 254 | lua_State* L = lua.get(); 255 | 256 | 257 | luaopen_swig_lib(L); 258 | lbs::lua_bench_do_or_die(L, "b = swig_lib.complex_ab()"); 259 | 260 | lbs::lua_bench_do_or_die(L, lbs::implicit_inheritance_check); 261 | 262 | std::string code = lbs::repeated_code(lbs::implicit_inheritance_code); 263 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 264 | for (auto _ : benchmark_state) { 265 | lbs::lua_bench_preload_do_or_die(L, code_index); 266 | } 267 | lbs::lua_bench_unload(L, code_index); 268 | } 269 | 270 | BENCHMARK(swig_table_global_string_get_measure); 271 | BENCHMARK(swig_table_global_string_set_measure); 272 | BENCHMARK(swig_table_get_measure); 273 | BENCHMARK(swig_table_set_measure); 274 | BENCHMARK(swig_table_chained_get_measure); 275 | BENCHMARK(swig_table_chained_set_measure); 276 | BENCHMARK(swig_c_function_measure); 277 | BENCHMARK(swig_c_function_through_lua_in_c_measure); 278 | BENCHMARK(swig_lua_function_in_c_measure); 279 | BENCHMARK(swig_member_function_call_measure); 280 | BENCHMARK(swig_userdata_variable_access_measure); 281 | BENCHMARK(swig_userdata_variable_access_large_measure); 282 | BENCHMARK(swig_userdata_variable_access_last_measure); 283 | BENCHMARK(swig_multi_return_measure); 284 | BENCHMARK(swig_multi_return_lua_measure); 285 | BENCHMARK(swig_stateful_function_object_measure); 286 | BENCHMARK(swig_base_derived_measure); 287 | BENCHMARK(swig_return_userdata_measure); 288 | BENCHMARK(swig_optional_success_measure); 289 | BENCHMARK(swig_optional_half_failure_measure); 290 | BENCHMARK(swig_optional_failure_measure); 291 | BENCHMARK(swig_implicit_inheritance_measure); 292 | -------------------------------------------------------------------------------- /source/swig_lib.i: -------------------------------------------------------------------------------- 1 | %module swig_lib 2 | %include // this is all the typemaps for this 3 | %apply double& OUTPUT{ double& out_1 }; 4 | %apply double& OUTPUT{ double& out_2 }; 5 | %{ 6 | #include "lbs_lib.hpp" 7 | using namespace lbs; 8 | %} 9 | 10 | struct basic { 11 | double var; 12 | int var0; 13 | int var1; 14 | int var2; 15 | int var3; 16 | int var4; 17 | 18 | basic(); 19 | basic(double x); 20 | 21 | double get() const; 22 | 23 | void set(double x); 24 | }; 25 | 26 | struct basic_large { 27 | double var; 28 | int var0; 29 | int var1; 30 | int var2; 31 | int var3; 32 | int var4; 33 | int var5; 34 | int var6; 35 | int var7; 36 | int var8; 37 | int var9; 38 | int var10; 39 | int var11; 40 | int var12; 41 | int var13; 42 | int var14; 43 | int var15; 44 | int var16; 45 | int var17; 46 | int var18; 47 | int var19; 48 | int var20; 49 | int var21; 50 | int var22; 51 | int var23; 52 | int var24; 53 | int var25; 54 | int var26; 55 | int var27; 56 | int var28; 57 | int var29; 58 | int var30; 59 | int var31; 60 | int var32; 61 | int var33; 62 | int var34; 63 | int var35; 64 | int var36; 65 | int var37; 66 | int var38; 67 | int var39; 68 | int var40; 69 | int var41; 70 | int var42; 71 | int var43; 72 | int var44; 73 | int var45; 74 | int var46; 75 | int var47; 76 | int var48; 77 | int64_t var49; 78 | 79 | basic_large(); 80 | }; 81 | 82 | struct complex_base_a { 83 | complex_base_a(); 84 | 85 | virtual double a_func() const; 86 | }; 87 | 88 | struct complex_base_b { 89 | complex_base_b(); 90 | 91 | virtual double b_func() const; 92 | }; 93 | 94 | struct complex_ab : complex_base_a, complex_base_b { 95 | complex_ab(); 96 | 97 | virtual double a_func() const; 98 | 99 | virtual double b_func() const; 100 | 101 | double ab_func() const; 102 | }; 103 | 104 | double basic_call(double x); 105 | 106 | basic basic_return(double x); 107 | 108 | double basic_get_var(const basic& b); 109 | 110 | void basic_multi_return_out(double i, double& out_1, double& out_2); 111 | -------------------------------------------------------------------------------- /source/toluapp.cpp: -------------------------------------------------------------------------------- 1 | // lua bindings shootout 2 | // The MIT License (MIT) 3 | 4 | // Copyright © 2018 ThePhD 5 | 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | // this software and associated documentation files (the "Software"), to deal in 8 | // the Software without restriction, including without limitation the rights to 9 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | // the Software, and to permit persons to whom the Software is furnished to do so, 11 | // subject to the following conditions: 12 | 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | #include "benchmark.hpp" 24 | #include "lbs_lib.hpp" 25 | #include "lbs_lua.hpp" 26 | 27 | // generated file must be included after 28 | // and we must modify API inludes 29 | #include 30 | #ifdef TOLUA_API 31 | #undef TOLUA_API 32 | #endif 33 | #define TOLUA_API inline 34 | #include "toluapp_lib.gen.hpp" 35 | #undef TOLUA_API 36 | 37 | void toluapp_table_global_string_get_measure(benchmark::State& benchmark_state) { 38 | // No table abstraction 39 | lbs::unsupported(benchmark_state); 40 | return; 41 | } 42 | 43 | void toluapp_table_global_string_set_measure(benchmark::State& benchmark_state) { 44 | // No table abstraction 45 | lbs::unsupported(benchmark_state); 46 | return; 47 | } 48 | 49 | void toluapp_table_chained_get_measure(benchmark::State& benchmark_state) { 50 | // No table abstraction 51 | lbs::unsupported(benchmark_state); 52 | return; 53 | } 54 | 55 | void toluapp_table_chained_set_measure(benchmark::State& benchmark_state) { 56 | // No table abstraction 57 | lbs::unsupported(benchmark_state); 58 | return; 59 | } 60 | 61 | void toluapp_table_get_measure(benchmark::State& benchmark_state) { 62 | // No table abstraction 63 | lbs::unsupported(benchmark_state); 64 | return; 65 | } 66 | 67 | void toluapp_table_set_measure(benchmark::State& benchmark_state) { 68 | // No table abstraction 69 | lbs::unsupported(benchmark_state); 70 | return; 71 | } 72 | 73 | void toluapp_c_function_measure(benchmark::State& benchmark_state) { 74 | auto lua = lbs::create_state(true); 75 | lua_State* L = lua.get(); 76 | lua_atpanic(L, lbs::panic_throw); 77 | 78 | tolua_open(L); 79 | tolua_toluapp_lib_open(L); 80 | 81 | lbs::lua_bench_do_or_die(L, "f = basic_call"); 82 | 83 | lbs::lua_bench_do_or_die(L, lbs::c_function_check); 84 | 85 | std::string code = lbs::repeated_code(lbs::c_function_code); 86 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 87 | for (auto _ : benchmark_state) { 88 | lbs::lua_bench_preload_do_or_die(L, code_index); 89 | } 90 | lbs::lua_bench_unload(L, code_index); 91 | } 92 | 93 | void toluapp_lua_function_in_c_measure(benchmark::State& benchmark_state) { 94 | // No table abstraction 95 | lbs::unsupported(benchmark_state); 96 | return; 97 | } 98 | 99 | void toluapp_c_function_through_lua_in_c_measure(benchmark::State& benchmark_state) { 100 | // No table abstraction 101 | lbs::unsupported(benchmark_state); 102 | return; 103 | } 104 | 105 | void toluapp_member_function_call_measure(benchmark::State& benchmark_state) { 106 | auto lua = lbs::create_state(true); 107 | lua_State* L = lua.get(); 108 | lua_atpanic(L, lbs::panic_throw); 109 | 110 | tolua_open(L); 111 | tolua_toluapp_lib_open(L); 112 | 113 | lbs::lua_bench_do_or_die(L, "b = c:new()"); 114 | 115 | lbs::lua_bench_do_or_die(L, lbs::member_function_call_check); 116 | 117 | std::string code = lbs::repeated_code(lbs::member_function_call_code); 118 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 119 | for (auto _ : benchmark_state) { 120 | lbs::lua_bench_preload_do_or_die(L, code_index); 121 | } 122 | lbs::lua_bench_unload(L, code_index); 123 | } 124 | 125 | void toluapp_userdata_variable_access_measure(benchmark::State& benchmark_state) { 126 | auto lua = lbs::create_state(true); 127 | lua_State* L = lua.get(); 128 | lua_atpanic(L, lbs::panic_throw); 129 | 130 | tolua_open(L); 131 | tolua_toluapp_lib_open(L); 132 | 133 | lbs::lua_bench_do_or_die(L, "b = c:new()"); 134 | 135 | lbs::lua_bench_do_or_die(L, lbs::userdata_variable_access_check); 136 | 137 | std::string code = lbs::repeated_code(lbs::userdata_variable_access_code); 138 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 139 | for (auto _ : benchmark_state) { 140 | lbs::lua_bench_preload_do_or_die(L, code_index); 141 | } 142 | lbs::lua_bench_unload(L, code_index); 143 | } 144 | 145 | void toluapp_userdata_variable_access_large_measure(benchmark::State& benchmark_state) { 146 | // Unsupported 147 | // ** tolua warning: No support for operator (), ignoring. 148 | lbs::unsupported(benchmark_state); 149 | return; 150 | 151 | auto lua = lbs::create_state(true); 152 | lua_State* L = lua.get(); 153 | lua_atpanic(L, lbs::panic_throw); 154 | 155 | tolua_open(L); 156 | tolua_toluapp_lib_open(L); 157 | 158 | lbs::lua_bench_do_or_die(L, "b = cl:new()"); 159 | 160 | lbs::lua_bench_do_or_die(L, lbs::userdata_variable_access_large_check); 161 | 162 | std::string code = lbs::repeated_code(lbs::userdata_variable_access_large_code); 163 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 164 | for (auto _ : benchmark_state) { 165 | lbs::lua_bench_preload_do_or_die(L, code_index); 166 | } 167 | lbs::lua_bench_unload(L, code_index); 168 | } 169 | 170 | void toluapp_userdata_variable_access_last_measure(benchmark::State& benchmark_state) { 171 | // Unsupported 172 | // ** tolua warning: No support for operator (), ignoring. 173 | lbs::unsupported(benchmark_state); 174 | return; 175 | 176 | auto lua = lbs::create_state(true); 177 | lua_State* L = lua.get(); 178 | lua_atpanic(L, lbs::panic_throw); 179 | 180 | tolua_open(L); 181 | tolua_toluapp_lib_open(L); 182 | 183 | lbs::lua_bench_do_or_die(L, "b = cl:new()"); 184 | 185 | lbs::lua_bench_do_or_die(L, lbs::userdata_variable_access_large_last_check); 186 | 187 | std::string code = lbs::repeated_code(lbs::userdata_variable_access_large_last_code); 188 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 189 | for (auto _ : benchmark_state) { 190 | lbs::lua_bench_preload_do_or_die(L, code_index); 191 | } 192 | lbs::lua_bench_unload(L, code_index); 193 | } 194 | 195 | void toluapp_stateful_function_object_measure(benchmark::State& benchmark_state) { 196 | // Unsupported 197 | // ** tolua warning: No support for operator (), ignoring. 198 | lbs::unsupported(benchmark_state); 199 | return; 200 | } 201 | 202 | void toluapp_multi_return_measure(benchmark::State& benchmark_state) { 203 | // Unsupported 204 | // tolua does not support multiple returns that are not ALSO input 205 | // parameters... 206 | // kinda crappy tbh 207 | lbs::unsupported(benchmark_state); 208 | return; 209 | } 210 | 211 | void toluapp_multi_return_lua_measure(benchmark::State& benchmark_state) { 212 | // Unsupported 213 | // tolua does not support multiple returns that are not ALSO input 214 | // parameters... 215 | // kinda crappy tbh 216 | lbs::unsupported(benchmark_state); 217 | return; 218 | } 219 | 220 | void toluapp_base_derived_measure(benchmark::State& benchmark_state) { 221 | // Unsupported 222 | lbs::unsupported(benchmark_state); 223 | return; 224 | } 225 | 226 | void toluapp_return_userdata_measure(benchmark::State& benchmark_state) { 227 | auto lua = lbs::create_state(true); 228 | lua_State* L = lua.get(); 229 | lua_atpanic(L, lbs::panic_throw); 230 | 231 | tolua_open(L); 232 | tolua_toluapp_lib_open(L); 233 | 234 | lbs::lua_bench_do_or_die(L, "f = basic_return"); 235 | lbs::lua_bench_do_or_die(L, "h = basic_get_var"); 236 | 237 | lbs::lua_bench_do_or_die(L, lbs::return_userdata_check); 238 | 239 | std::string code = lbs::repeated_code(lbs::return_userdata_code); 240 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 241 | for (auto _ : benchmark_state) { 242 | lbs::lua_bench_preload_do_or_die(L, code_index); 243 | } 244 | lbs::lua_bench_unload(L, code_index); 245 | } 246 | 247 | void toluapp_optional_success_measure(benchmark::State& benchmark_state) { 248 | // Unsupported 249 | lbs::unsupported(benchmark_state); 250 | return; 251 | } 252 | 253 | void toluapp_optional_half_failure_measure(benchmark::State& benchmark_state) { 254 | // Unsupported 255 | lbs::unsupported(benchmark_state); 256 | return; 257 | } 258 | 259 | void toluapp_optional_failure_measure(benchmark::State& benchmark_state) { 260 | // Unsupported 261 | lbs::unsupported(benchmark_state); 262 | return; 263 | } 264 | 265 | void toluapp_implicit_inheritance_measure(benchmark::State& benchmark_state) { 266 | auto lua = lbs::create_state(true); 267 | lua_State* L = lua.get(); 268 | lua_atpanic(L, lbs::panic_throw); 269 | 270 | tolua_open(L); 271 | tolua_toluapp_lib_open(L); 272 | 273 | lbs::lua_bench_do_or_die(L, "b = cab:new()"); 274 | 275 | lbs::lua_bench_do_or_die(L, lbs::implicit_inheritance_check); 276 | 277 | std::string code = lbs::repeated_code(lbs::implicit_inheritance_code); 278 | int code_index = lbs::lua_bench_load_up(L, code.c_str(), code.size()); 279 | for (auto _ : benchmark_state) { 280 | lbs::lua_bench_preload_do_or_die(L, code_index); 281 | } 282 | lbs::lua_bench_unload(L, code_index); 283 | } 284 | 285 | BENCHMARK(toluapp_table_global_string_get_measure); 286 | BENCHMARK(toluapp_table_global_string_set_measure); 287 | BENCHMARK(toluapp_table_get_measure); 288 | BENCHMARK(toluapp_table_set_measure); 289 | BENCHMARK(toluapp_table_chained_get_measure); 290 | BENCHMARK(toluapp_table_chained_set_measure); 291 | BENCHMARK(toluapp_c_function_measure); 292 | BENCHMARK(toluapp_c_function_through_lua_in_c_measure); 293 | BENCHMARK(toluapp_lua_function_in_c_measure); 294 | BENCHMARK(toluapp_member_function_call_measure); 295 | BENCHMARK(toluapp_userdata_variable_access_measure); 296 | BENCHMARK(toluapp_userdata_variable_access_large_measure); 297 | BENCHMARK(toluapp_userdata_variable_access_last_measure); 298 | BENCHMARK(toluapp_multi_return_lua_measure); 299 | BENCHMARK(toluapp_multi_return_measure); 300 | BENCHMARK(toluapp_stateful_function_object_measure); 301 | BENCHMARK(toluapp_base_derived_measure); 302 | BENCHMARK(toluapp_return_userdata_measure); 303 | BENCHMARK(toluapp_optional_success_measure); 304 | BENCHMARK(toluapp_optional_half_failure_measure); 305 | BENCHMARK(toluapp_optional_failure_measure); 306 | BENCHMARK(toluapp_implicit_inheritance_measure); 307 | -------------------------------------------------------------------------------- /source/toluapp_lib.gen.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ThePhD/lua-bindings-shootout/6c89ed21366040de391348de36076dead1b22934/source/toluapp_lib.gen.hpp -------------------------------------------------------------------------------- /source/toluapp_lib.pkg: -------------------------------------------------------------------------------- 1 | $using namespace lbs; 2 | 3 | struct basic { 4 | double var; 5 | int var0; 6 | int var1; 7 | int var2; 8 | int var3; 9 | int var4; 10 | 11 | basic(); 12 | basic(double x); 13 | 14 | double get() const; 15 | 16 | void set(double x); 17 | }; 18 | 19 | struct basic_large { 20 | double var; 21 | int var0; 22 | int var1; 23 | int var2; 24 | int var3; 25 | int var4; 26 | int var5; 27 | int var6; 28 | int var7; 29 | int var8; 30 | int var9; 31 | int var10; 32 | int var11; 33 | int var12; 34 | int var13; 35 | int var14; 36 | int var15; 37 | int var16; 38 | int var17; 39 | int var18; 40 | int var19; 41 | int var20; 42 | int var21; 43 | int var22; 44 | int var23; 45 | int var24; 46 | int var25; 47 | int var26; 48 | int var27; 49 | int var28; 50 | int var29; 51 | int var30; 52 | int var31; 53 | int var32; 54 | int var33; 55 | int var34; 56 | int var35; 57 | int var36; 58 | int var37; 59 | int var38; 60 | int var39; 61 | int var40; 62 | int var41; 63 | int var42; 64 | int var43; 65 | int var44; 66 | int var45; 67 | int var46; 68 | int var47; 69 | int var48; 70 | int64_t var49; 71 | 72 | basic_large(); 73 | }; 74 | 75 | struct complex_base_a { 76 | complex_base_a(); 77 | 78 | virtual double a_func() const; 79 | }; 80 | 81 | struct complex_base_b { 82 | complex_base_b(); 83 | 84 | virtual double b_func() const; 85 | }; 86 | 87 | struct complex_ab : complex_base_a, complex_base_b { 88 | complex_ab(); 89 | 90 | virtual double a_func() const; 91 | 92 | virtual double b_func() const; 93 | 94 | double ab_func() const; 95 | }; 96 | 97 | $renaming ^basic$ @ c 98 | $renaming ^basic_large$ @ cl 99 | $renaming ^basic_stateful$ @ cs 100 | $renaming ^complex_base_a$ @ cba 101 | $renaming ^complex_base_b$ @ cbb 102 | $renaming ^complex_ab$ @ cab 103 | 104 | double basic_call(double x); 105 | 106 | basic basic_return(double x); 107 | 108 | double basic_get_var(const basic& b); 109 | -------------------------------------------------------------------------------- /vendor/sol2/sol2/sol2_forward.hpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2013-2018 Rapptz, ThePhD and contributors 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // This file was generated with a script. 23 | // Generated 2018-04-18 00:12:41.996673 UTC 24 | // This header was generated with sol v2.20.0 (revision 8b77411) 25 | // https://github.com/ThePhD/sol2 26 | 27 | #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP 28 | #define SOL_SINGLE_INCLUDE_FORWARD_HPP 29 | 30 | // beginning of sol/forward.hpp 31 | 32 | // beginning of sol/feature_test.hpp 33 | 34 | #if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && ((defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L)))) 35 | #ifndef SOL_CXX17_FEATURES 36 | #define SOL_CXX17_FEATURES 1 37 | #endif // C++17 features macro 38 | #endif // C++17 features check 39 | 40 | #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES 41 | #if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && (defined(_MSVC_LANG) && ((_MSVC_LANG >= 201403L)))) 42 | #ifndef SOL_NOEXCEPT_FUNCTION_TYPE 43 | #define SOL_NOEXCEPT_FUNCTION_TYPE 1 44 | #endif // noexcept is part of a function's type 45 | #endif // compiler-specific checks 46 | #if defined(__clang__) && defined(__APPLE__) 47 | #if defined(__has_include) 48 | #if __has_include() 49 | #define SOL_STD_VARIANT 1 50 | #endif // has include nonsense 51 | #endif // __has_include 52 | #else 53 | #define SOL_STD_VARIANT 1 54 | #endif // Clang screws up variant 55 | #endif // C++17 only 56 | 57 | // beginning of sol/config.hpp 58 | 59 | #ifdef _MSC_VER 60 | #if defined(_DEBUG) && !defined(NDEBUG) 61 | 62 | #ifndef SOL_IN_DEBUG_DETECTED 63 | #define SOL_IN_DEBUG_DETECTED 1 64 | #endif 65 | 66 | #endif // VC++ Debug macros 67 | 68 | #ifndef _CPPUNWIND 69 | #ifndef SOL_NO_EXCEPTIONS 70 | #define SOL_NO_EXCEPTIONS 1 71 | #endif 72 | #endif // Automatic Exceptions 73 | 74 | #ifndef _CPPRTTI 75 | #ifndef SOL_NO_RTTI 76 | #define SOL_NO_RTTI 1 77 | #endif 78 | #endif // Automatic RTTI 79 | #elif defined(__GNUC__) || defined(__clang__) 80 | 81 | #if !defined(NDEBUG) && !defined(__OPTIMIZE__) 82 | 83 | #ifndef SOL_IN_DEBUG_DETECTED 84 | #define SOL_IN_DEBUG_DETECTED 1 85 | #endif 86 | 87 | #endif // Not Debug && g++ optimizer flag 88 | 89 | #ifndef __EXCEPTIONS 90 | #ifndef SOL_NO_EXCEPTIONS 91 | #define SOL_NO_EXCEPTIONS 1 92 | #endif 93 | #endif // No Exceptions 94 | 95 | #ifndef __GXX_RTTI 96 | #ifndef SOL_NO_RTII 97 | #define SOL_NO_RTTI 1 98 | #endif 99 | #endif // No RTTI 100 | 101 | #endif // vc++ || clang++/g++ 102 | 103 | #if defined(SOL_CHECK_ARGUMENTS) && SOL_CHECK_ARGUMENTS 104 | 105 | // Checks low-level getter function 106 | // (and thusly, affects nearly entire framework) 107 | #if !defined(SOL_SAFE_GETTER) 108 | #define SOL_SAFE_GETTER 1 109 | #endif 110 | 111 | // Checks access on usertype functions 112 | // local my_obj = my_type.new() 113 | // my_obj.my_member_function() 114 | // -- bad syntax and crash 115 | #if !defined(SOL_SAFE_USERTYPE) 116 | #define SOL_SAFE_USERTYPE 1 117 | #endif 118 | 119 | // Checks sol::reference derived boundaries 120 | // sol::function ref(L, 1); 121 | // sol::userdata sref(L, 2); 122 | #if !defined(SOL_SAFE_REFERENCES) 123 | #define SOL_SAFE_REFERENCES 1 124 | #endif 125 | 126 | // Changes all typedefs of sol::function to point to the 127 | // protected_function version, instead of unsafe_function 128 | #if !defined(SOL_SAFE_FUNCTION) 129 | #define SOL_SAFE_FUNCTION 1 130 | #endif 131 | 132 | // Checks function parameters and 133 | // returns upon call into/from Lua 134 | // local a = 1 135 | // local b = "woof" 136 | // my_c_function(a, b) 137 | #if !defined(SOL_SAFE_FUNCTION_CALLS) 138 | #define SOL_SAFE_FUNCTION_CALLS 1 139 | #endif 140 | 141 | // Checks conversions 142 | // int v = lua["bark"]; 143 | // int v2 = my_sol_function(); 144 | #if !defined(SOL_SAFE_PROXIES) 145 | #define SOL_SAFE_PROXIES 1 146 | #endif 147 | 148 | // Check overflowing number conversions 149 | // for things like 64 bit integers that don't fit in a typical lua_Number 150 | // for Lua 5.1 and 5.2 151 | #if !defined(SOL_SAFE_NUMERICS) 152 | #define SOL_SAFE_NUMERICS 1 153 | #endif 154 | 155 | // Turn off Number Precision Checks 156 | // if this is defined, we do not do range 157 | // checks on integers / unsigned integers that might 158 | // be bigger than what Lua can represent 159 | #if !defined(SOL_NO_CHECK_NUMBER_PRECISION) 160 | // off by default 161 | #define SOL_NO_CHECK_NUMBER_PRECISION 0 162 | #endif 163 | 164 | #endif // Turn on Safety for all if top-level macro is defined 165 | 166 | #if defined(SOL_IN_DEBUG_DETECTED) && SOL_IN_DEBUG_DETECTED 167 | 168 | #if !defined(SOL_SAFE_REFERENCES) 169 | // Ensure that references are forcefully type-checked upon construction 170 | #define SOL_SAFE_REFERENCES 1 171 | #endif 172 | 173 | // Safe usertypes checks for errors such as 174 | // obj = my_type.new() 175 | // obj.f() -- note the '.' instead of ':' 176 | // usertypes should be safe no matter what 177 | #if !defined(SOL_SAFE_USERTYPE) 178 | #define SOL_SAFE_USERTYPE 1 179 | #endif 180 | 181 | #if !defined(SOL_SAFE_FUNCTION_CALLS) 182 | // Function calls from Lua should be automatically safe in debug mode 183 | #define SOL_SAFE_FUNCTION_CALLS 1 184 | #endif 185 | 186 | // Print any exceptions / errors that occur 187 | // in debug mode to the default error stream / console 188 | #if !defined(SOL_PRINT_ERRORS) 189 | #define SOL_PRINT_ERRORS 1 190 | #endif 191 | 192 | #endif // DEBUG: Turn on all debug safety features for VC++ / g++ / clang++ and similar 193 | 194 | #if !defined(SOL_PRINT_ERRORS) 195 | #define SOL_PRINT_ERRORS 0 196 | #endif 197 | 198 | #if !defined(SOL_DEFAULT_PASS_ON_ERROR) 199 | #define SOL_DEFAULT_PASS_ON_ERROR 0 200 | #endif 201 | 202 | #if !defined(SOL_ENABLE_INTEROP) 203 | #define SOL_ENABLE_INTEROP 0 204 | #endif 205 | 206 | #if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil) 207 | #if !defined(SOL_NO_NIL) 208 | #define SOL_NO_NIL 1 209 | #endif 210 | #endif // avoiding nil defines / keywords 211 | 212 | #if defined(SOL_USE_BOOST) && SOL_USE_BOOST 213 | #ifndef SOL_UNORDERED_MAP_COMPATIBLE_HASH 214 | #define SOL_UNORDERED_MAP_COMPATIBLE_HASH 1 215 | #endif // SOL_UNORDERED_MAP_COMPATIBLE_HASH 216 | #endif 217 | 218 | #ifndef SOL_STACK_STRING_OPTIMIZATION_SIZE 219 | #define SOL_STACK_STRING_OPTIMIZATION_SIZE 1024 220 | #endif // Optimized conversion routines using a KB or so off the stack 221 | 222 | // end of sol/config.hpp 223 | 224 | // end of sol/feature_test.hpp 225 | 226 | namespace sol2 227 | { 228 | 229 | template 230 | class basic_reference; 231 | using reference = basic_reference; 232 | using main_reference = basic_reference; 233 | class stack_reference; 234 | 235 | struct proxy_base_tag; 236 | template 237 | struct proxy_base; 238 | template 239 | struct proxy; 240 | 241 | template 242 | class usertype; 243 | template 244 | class simple_usertype; 245 | template 246 | class basic_table_core; 247 | template 248 | using table_core = basic_table_core; 249 | template 250 | using main_table_core = basic_table_core; 251 | template 252 | using stack_table_core = basic_table_core; 253 | template 254 | using basic_table = basic_table_core; 255 | typedef table_core table; 256 | typedef table_core global_table; 257 | typedef main_table_core main_table; 258 | typedef main_table_core main_global_table; 259 | typedef stack_table_core stack_table; 260 | typedef stack_table_core stack_global_table; 261 | template 262 | struct basic_environment; 263 | using environment = basic_environment; 264 | using main_environment = basic_environment; 265 | using stack_environment = basic_environment; 266 | template 267 | class basic_function; 268 | template 269 | class basic_protected_function; 270 | using unsafe_function = basic_function; 271 | using safe_function = basic_protected_function; 272 | using main_unsafe_function = basic_function; 273 | using main_safe_function = basic_protected_function; 274 | using stack_unsafe_function = basic_function; 275 | using stack_safe_function = basic_protected_function; 276 | using stack_aligned_unsafe_function = basic_function; 277 | using stack_aligned_safe_function = basic_protected_function; 278 | using protected_function = safe_function; 279 | using main_protected_function = main_safe_function; 280 | using stack_protected_function = stack_safe_function; 281 | using stack_aligned_protected_function = stack_aligned_safe_function; 282 | #if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION 283 | using function = protected_function; 284 | using main_function = main_protected_function; 285 | using stack_function = stack_protected_function; 286 | #else 287 | using function = unsafe_function; 288 | using main_function = main_unsafe_function; 289 | using stack_function = stack_unsafe_function; 290 | #endif 291 | using stack_aligned_function = stack_aligned_unsafe_function; 292 | using stack_aligned_stack_handler_function = basic_protected_function; 293 | 294 | struct unsafe_function_result; 295 | struct protected_function_result; 296 | using safe_function_result = protected_function_result; 297 | #if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION 298 | using function_result = safe_function_result; 299 | #else 300 | using function_result = unsafe_function_result; 301 | #endif 302 | 303 | template 304 | class basic_object; 305 | template 306 | class basic_userdata; 307 | template 308 | class basic_lightuserdata; 309 | template 310 | class basic_coroutine; 311 | template 312 | class basic_thread; 313 | 314 | using object = basic_object; 315 | using userdata = basic_userdata; 316 | using lightuserdata = basic_lightuserdata; 317 | using thread = basic_thread; 318 | using coroutine = basic_coroutine; 319 | using main_object = basic_object; 320 | using main_userdata = basic_userdata; 321 | using main_lightuserdata = basic_lightuserdata; 322 | using main_coroutine = basic_coroutine; 323 | using stack_object = basic_object; 324 | using stack_userdata = basic_userdata; 325 | using stack_lightuserdata = basic_lightuserdata; 326 | using stack_thread = basic_thread; 327 | using stack_coroutine = basic_coroutine; 328 | 329 | struct stack_proxy_base; 330 | struct stack_proxy; 331 | struct variadic_args; 332 | struct variadic_results; 333 | struct stack_count; 334 | struct this_state; 335 | struct this_main_state; 336 | struct this_environment; 337 | 338 | template 339 | struct as_table_t; 340 | template 341 | struct as_container_t; 342 | template 343 | struct nested; 344 | template 345 | struct light; 346 | template 347 | struct user; 348 | template 349 | struct as_args_t; 350 | template 351 | struct protect_t; 352 | template 353 | struct filter_wrapper; 354 | } // namespace sol2 355 | 356 | // end of sol/forward.hpp 357 | 358 | #endif // SOL_SINGLE_INCLUDE_FORWARD_HPP 359 | --------------------------------------------------------------------------------