Compare commits

..

1 Commits

Author SHA1 Message Date
KimLS a65d8836af Task scheduler test 2019-08-04 20:12:22 -07:00
432 changed files with 45501 additions and 16772 deletions
+23
View File
@@ -0,0 +1,23 @@
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8
[*.cpp]
indent_style = tab
[*.h]
indent_style = tab
# Tab indentation (no size specified)
[Makefile]
indent_style = tab
+1 -2
View File
@@ -29,5 +29,4 @@ logs/
vcpkg/
.idea/*
*cbp
.editorconfig
*cbp
-3
View File
@@ -16,6 +16,3 @@
[submodule "submodules/recastnavigation"]
path = submodules/recastnavigation
url = https://github.com/EQEmu/recastnavigation.git
[submodule "submodules/zlibng"]
path = submodules/zlibng
url = https://github.com/zlib-ng/zlib-ng.git
+305 -222
View File
@@ -1,24 +1,128 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
#EQEmu CMake
#Variables used:
#EQEMU_DISABLE_CRT_SECURE_WARNINGS
#EQEMU_FAST_FLOATINGPOINT
#EQEMU_ENABLE_CRASH_LOGGING
#EQEMU_DISABLE_SAFESEH
#EQEMU_BUILD_MSVC_MP
#EQEMU_DEBUG_LEVEL
#EQEMU_LOG_LEVEL_STATUS
#EQEMU_LOG_LEVEL_NORMAL
#EQEMU_LOG_LEVEL_ERROR
#EQEMU_LOG_LEVEL_DEBUG
#EQEMU_LOG_LEVEL_QUEST
#EQEMU_LOG_LEVEL_COMMANDS
#EQEMU_LOG_LEVEL_CRASH
#EQEMU_DEPOP_INVALIDATES_CACHE
#EQEMU_ENABLE_BOTS
#EQEMU_DISABLE_LOGSYS
#EQEMU_COMMANDS_LOGGING
#EQEMU_BUILD_SERVER
#EQEMU_BUILD_LOGIN
#EQEMU_BUILD_TESTS
#EQEMU_BUILD_PERL
#EQEMU_BUILD_LUA
#EQEMU_SANITIZE_LUA_LIBS
#EQEMU_BUILD_CLIENT_FILES
#EQEMU_USE_MAP_MMFS
#EQEMU_MAP_DIR
#EQEMU_ARCH
#EQEMU_ARCH_ALT
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
IF(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
ENDIF()
#FindMySQL is located here so lets make it so CMake can find it
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH})
#Our project name is EQEmu
PROJECT(EQEmu)
#Default build type is set to RelWithDebInfo for generators that honor that like makefiles
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
SET(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/dependencies" "${CMAKE_PREFIX_PATH}")
#Add our various windows definitions
IF(MSVC OR MINGW)
ADD_DEFINITIONS(-D_WINDOWS)
IF(CMAKE_CL_64)
ADD_DEFINITIONS(-DWIN64)
ELSE(CMAKE_CL_64)
ADD_DEFINITIONS(-DWIN32)
ENDIF(CMAKE_CL_64)
ENDIF(MSVC OR MINGW)
IF(MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ADD_DEFINITIONS(-DNOMINMAX)
ADD_DEFINITIONS(-DCRASH_LOGGING)
IF(CMAKE_CL_64)
SET(EQEMU_ARCH "x64")
SET(EQEMU_ARCH_ALT "x64")
ELSE(CMAKE_CL_64)
SET(EQEMU_ARCH "x86")
SET(EQEMU_ARCH_ALT "Win32")
ENDIF(CMAKE_CL_64)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
SET(MYSQL_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/mysql_${EQEMU_ARCH}")
IF(VCPKG_TOOLCHAIN)
IF(NOT MSVC_VERSION GREATER 1800)
SET(SODIUM_INCLUDE_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/include")
ENDIF()
ELSE(VCPKG_TOOLCHAIN)
SET(ZLIB_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/zlib_${EQEMU_ARCH}")
SET(LUA_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/luaj_${EQEMU_ARCH}")
SET(OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/openssl_${EQEMU_ARCH}")
SET(SODIUM_INCLUDE_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/include")
ENDIF(VCPKG_TOOLCHAIN)
IF(SODIUM_INCLUDE_HINTS)
IF(MSVC_VERSION GREATER 1800)
SET(SODIUM_LIBRARY_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/${EQEMU_ARCH_ALT}/Release/v140/dynamic")
ELSEIF(MSVC_VERSION EQUAL 1800)
SET(SODIUM_LIBRARY_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/${EQEMU_ARCH_ALT}/Release/v120/dynamic")
ELSE()
SET(SODIUM_LIBRARY_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/${EQEMU_ARCH_ALT}/Release/v110/dynamic")
ENDIF()
ENDIF(SODIUM_INCLUDE_HINTS)
#disable CRT warnings on windows cause they're annoying as shit and we use C functions everywhere
OPTION(EQEMU_DISABLE_CRT_SECURE_WARNINGS "Disable Secure CRT Warnings" ON)
IF(EQEMU_DISABLE_CRT_SECURE_WARNINGS)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF(EQEMU_DISABLE_CRT_SECURE_WARNINGS)
#fast FP if you'd like it
OPTION(EQEMU_FAST_FLOATINGPOINT "Use MSVC /fp:fast option" ON)
IF(EQEMU_FAST_FLOATINGPOINT)
ADD_DEFINITIONS(/fp:fast)
ENDIF(EQEMU_FAST_FLOATINGPOINT)
#crash logging currently only works on windows x86/x64
OPTION(EQEMU_ENABLE_CRASH_LOGGING "Enable crash logging" ON)
IF(EQEMU_ENABLE_CRASH_LOGGING)
ADD_DEFINITIONS(-DCRASH_LOGGING)
ENDIF(EQEMU_ENABLE_CRASH_LOGGING)
OPTION(EQEMU_BUILD_MSVC_MP "Enable build with multiple processes." ON)
IF(EQEMU_BUILD_MSVC_MP)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
ENDIF(EQEMU_BUILD_MSVC_MP)
#We want to compile /MT not /MD so we change that
FOREACH(flag_var CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO)
IF(${flag_var} MATCHES "/MD")
STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
ENDIF(${flag_var} MATCHES "/MD")
ENDFOREACH(flag_var)
ADD_DEFINITIONS(-DNOMINMAX)
ELSE(MSVC)
#Normally set by perl but we don't use the perl flags anymore so we set it.
ADD_DEFINITIONS(-DHAS_UNION_SEMUN)
ENDIF(MSVC)
@@ -35,239 +139,197 @@ IF(UNIX)
ENDIF(CMAKE_SYSTEM_NAME MATCHES "Darwin")
ENDIF(UNIX)
ADD_DEFINITIONS(-DGLM_FORCE_RADIANS)
ADD_DEFINITIONS(-DGLM_FORCE_CTOR_INIT)
ADD_DEFINITIONS(-DGLM_ENABLE_EXPERIMENTAL)
#debug level, 5 is default. Most people wont ever change this but it's there if you want to
SET(EQEMU_DEBUG_LEVEL 5 CACHE STRING "EQEmu debug level:
0 - Quiet mode Errors to file Status and Normal ignored
1 - Status and Normal to console, Errors to logfile
2 - Status, Normal, and Error to console and logfile
3 - Light debug release errors and status
4 - Moderate debug release errors and status
5 - Maximum debug release errors and status
10 - More errors than you ever wanted to see"
)
#Find everything we need
FIND_PACKAGE(MySQL)
FIND_PACKAGE(MariaDB)
FIND_PACKAGE(Boost REQUIRED)
FIND_PACKAGE(ZLIB)
FIND_PACKAGE(OpenSSL)
FIND_PACKAGE(Lua51)
FIND_PACKAGE(PerlLibs)
FIND_PACKAGE(Sodium)
FIND_PACKAGE(mbedTLS)
SET(EQEMU_LOG_LEVEL_STATUS 2 CACHE STRING "EQEmu logging level for [Status]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
MESSAGE(STATUS "**************************************************")
MESSAGE(STATUS "* Library Detection *")
MESSAGE(STATUS "**************************************************")
SET(EQEMU_LOG_LEVEL_NORMAL 3 CACHE STRING "EQEmu logging level for [Normal]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
IF(MYSQL_FOUND)
MESSAGE(STATUS "* MySQL: FOUND *")
ELSE()
MESSAGE(STATUS "* MySQL: MISSING *")
ENDIF()
SET(EQEMU_LOG_LEVEL_ERROR 2 CACHE STRING "EQEmu logging level for [Error]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
IF(MARIADB_FOUND)
MESSAGE(STATUS "* MariaDB: FOUND *")
ELSE()
MESSAGE(STATUS "* MariaDB: MISSING *")
ENDIF()
SET(EQEMU_LOG_LEVEL_DEBUG 3 CACHE STRING "EQEmu logging level for [Debug]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
IF(ZLIB_FOUND)
MESSAGE(STATUS "* ZLIB: FOUND *")
ELSE()
MESSAGE(STATUS "* ZLIB: MISSING *")
ENDIF()
SET(EQEMU_LOG_LEVEL_QUEST 2 CACHE STRING "EQEmu logging level for [Quest]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
IF(Lua51_FOUND)
MESSAGE(STATUS "* Lua: FOUND *")
ELSE()
MESSAGE(STATUS "* Lua: MISSING *")
ENDIF()
SET(EQEMU_LOG_LEVEL_COMMANDS 1 CACHE STRING "EQEmu logging level for [Commands]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
IF(PerlLibs_FOUND)
MESSAGE(STATUS "* Perl: FOUND *")
ELSE()
MESSAGE(STATUS "* Perl: MISSING *")
ENDIF()
SET(EQEMU_LOG_LEVEL_CRASH 3 CACHE STRING "EQEmu logging level for [Crash]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
IF(SODIUM_FOUND)
MESSAGE(STATUS "* libsodium: FOUND *")
ELSE()
MESSAGE(STATUS "* libsodium: MISSING *")
ENDIF()
MARK_AS_ADVANCED(EQEMU_LOG_LEVEL_STATUS EQEMU_LOG_LEVEL_NORMAL EQEMU_LOG_LEVEL_ERROR EQEMU_LOG_LEVEL_DEBUG EQEMU_LOG_LEVEL_QUEST EQEMU_LOG_LEVEL_COMMANDS EQEMU_LOG_LEVEL_CRASH)
IF(OpenSSL_FOUND)
MESSAGE(STATUS "* OpenSSL: FOUND *")
ELSE()
MESSAGE(STATUS "* OpenSSL: MISSING *")
ENDIF()
IF(MBEDTLS_FOUND)
MESSAGE(STATUS "* mbedTLS: FOUND *")
ELSE()
MESSAGE(STATUS "* mbedTLS: MISSING *")
ENDIF()
MESSAGE(STATUS "**************************************************")
#options
#NPC Types Cache Behavior
OPTION(EQEMU_DEPOP_INVALIDATES_CACHE "#repop invalidates the npc_types cache (will cause a larger database hit on #repop but is more convienent)." ON)
#Bots are a compile time option so on/off
OPTION(EQEMU_ENABLE_BOTS "Enable Bots" OFF)
#Disable entire _mlog system (excludes trade/command logs)
OPTION(EQEMU_DISABLE_LOGSYS "Disable Logging INI System" ON)
#Enable GM Command log system
OPTION(EQEMU_COMMANDS_LOGGING "Enable GM Command logs" ON)
OPTION(EQEMU_BUILD_SERVER "Build the game server." ON)
OPTION(EQEMU_BUILD_HC "Build the headless client." OFF)
OPTION(EQEMU_BUILD_TESTS "Build utility tests." OFF)
OPTION(EQEMU_BUILD_CLIENT_FILES "Build Client Import/Export Data Programs." ON)
IF(EQEMU_COMMANDS_LOGGING)
ADD_DEFINITIONS(-DCOMMANDS_LOGGING)
ENDIF(EQEMU_COMMANDS_LOGGING)
IF(EQEMU_DISABLE_LOGSYS)
ADD_DEFINITIONS(-DDISABLE_LOGSYS)
ENDIF(EQEMU_DISABLE_LOGSYS)
IF(EQEMU_ENABLE_BOTS)
ADD_DEFINITIONS(-DBOTS)
ENDIF(EQEMU_ENABLE_BOTS)
#database
#prefer mariadb to mysql (arbitrary)
IF(MySQL_FOUND AND MariaDB_FOUND)
SET(DATABASE_LIBRARY_TYPE "MariaDB")
SET(DATABASE_LIBRARY_LIBS ${MariaDB_LIBRARIES})
SET(DATABASE_LIBRARY_INCLUDE ${MariaDB_INCLUDE_DIR})
ELSEIF(MariaDB_FOUND)
SET(DATABASE_LIBRARY_TYPE "MariaDB")
SET(DATABASE_LIBRARY_LIBS ${MariaDB_LIBRARIES})
SET(DATABASE_LIBRARY_INCLUDE ${MariaDB_INCLUDE_DIR})
ELSEIF(MySQL_FOUND)
SET(DATABASE_LIBRARY_TYPE " MySQL")
SET(DATABASE_LIBRARY_LIBS ${MySQL_LIBRARIES})
SET(DATABASE_LIBRARY_INCLUDE ${MySQL_INCLUDE_DIR})
ELSE()
MESSAGE(FATAL_ERROR "One of MySQL or MariaDB is a required dependency.")
ENDIF()
#What to build
OPTION(EQEMU_BUILD_SERVER "Build the game server." ON)
OPTION(EQEMU_BUILD_LOGIN "Build the login server." OFF)
OPTION(EQEMU_BUILD_HC "Build the headless client." OFF)
OPTION(EQEMU_BUILD_TESTS "Build utility tests." OFF)
OPTION(EQEMU_BUILD_PERL "Build Perl parser." ON)
OPTION(EQEMU_BUILD_LUA "Build Lua parser." ON)
OPTION(EQEMU_BUILD_CLIENT_FILES "Build Client Import/Export Data Programs." ON)
#security
#prefer openssl to mbedtls (arbitrary)
IF(OpenSSL_FOUND AND MBEDTLS_FOUND)
SET(SSL_LIBRARY_TYPE " OpenSSL")
SET(SSL_LIBRARY_ENABLED ON)
SET(SSL_LIBRARY_LIBS ${OPENSSL_LIBRARIES})
SET(SSL_LIBRARY_INCLUDE ${OPENSSL_INCLUDE_DIR})
ELSEIF(OpenSSL_FOUND)
SET(SSL_LIBRARY_TYPE " OpenSSL")
SET(SSL_LIBRARY_ENABLED ON)
SET(SSL_LIBRARY_LIBS ${OPENSSL_LIBRARIES})
SET(SSL_LIBRARY_INCLUDE ${OPENSSL_INCLUDE_DIR})
ELSEIF(MBEDTLS_FOUND)
SET(SSL_LIBRARY_TYPE " mbedTLS")
SET(SSL_LIBRARY_ENABLED ON)
SET(SSL_LIBRARY_LIBS ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY})
SET(SSL_LIBRARY_INCLUDE ${MBEDTLS_INCLUDE_DIR})
ELSE()
SET(SSL_LIBRARY_TYPE "Disabled")
SET(SSL_LIBRARY_ENABLED OFF)
ENDIF()
#C++11 stuff
IF(NOT MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reserved-user-defined-literal")
ENDIF()
ENDIF(NOT MSVC)
#Various definitions
IF(EQEMU_BUILD_PERL)
ADD_DEFINITIONS(-DEMBPERL)
ADD_DEFINITIONS(-DEMBPERL_PLUGIN)
ENDIF(EQEMU_BUILD_PERL)
IF(EQEMU_BUILD_LUA)
ADD_DEFINITIONS(-DLUA_EQEMU)
ENDIF(EQEMU_BUILD_LUA)
#Disabled until reevaluation performed
#OPTION(EQEMU_USE_MAP_MMFS "Create and use Zone Map MMF files." OFF)
#IF(EQEMU_USE_MAP_MMFS)
# ADD_DEFINITIONS(-DUSE_MAP_MMFS)
#ENDIF(EQEMU_USE_MAP_MMFS)
SET(EQEMU_MAP_DIR "./Maps" CACHE STRING "The dir that maps, water maps, and paths are located in.")
ADD_DEFINITIONS(-DEQDEBUG=${EQEMU_DEBUG_LEVEL})
ADD_DEFINITIONS(-DINVERSEXY)
ADD_DEFINITIONS(-DFIELD_ITEMS)
ADD_DEFINITIONS(-DMAP_DIR="${EQEMU_MAP_DIR}")
ADD_DEFINITIONS(-DLOG_LEVEL_STATUS=${EQEMU_LOG_LEVEL_STATUS})
ADD_DEFINITIONS(-DLOG_LEVEL_NORMAL=${EQEMU_LOG_LEVEL_NORMAL})
ADD_DEFINITIONS(-DLOG_LEVEL_ERROR=${EQEMU_LOG_LEVEL_ERROR})
ADD_DEFINITIONS(-DLOG_LEVEL_DEBUG=${EQEMU_LOG_LEVEL_DEBUG})
ADD_DEFINITIONS(-DLOG_LEVEL_QUEST=${EQEMU_LOG_LEVEL_QUEST})
ADD_DEFINITIONS(-DLOG_LEVEL_COMMANDS=${EQEMU_LOG_LEVEL_COMMANDS})
ADD_DEFINITIONS(-DLOG_LEVEL_CRASH=${EQEMU_LOG_LEVEL_CRASH})
ADD_DEFINITIONS(-DGLM_FORCE_RADIANS)
ADD_DEFINITIONS(-DGLM_FORCE_CTOR_INIT)
ADD_DEFINITIONS(-DGLM_ENABLE_EXPERIMENTAL)
#Find everything we need
FIND_PACKAGE(ZLIB)
FIND_PACKAGE(MySQL REQUIRED)
IF(EQEMU_BUILD_PERL)
FIND_PACKAGE(PerlLibs REQUIRED)
INCLUDE_DIRECTORIES(SYSTEM "${PERL_INCLUDE_PATH}")
ENDIF(EQEMU_BUILD_PERL)
SET(SERVER_LIBS common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} uv_a fmt RecastNavigation::Detour)
FIND_PACKAGE(Sodium REQUIRED)
IF(SODIUM_FOUND)
SET(SODIUM_LIBRARY_TYPE "Libsodium")
SET(SODIUM_LIBRARY_ENABLED ON)
SET(SODIUM_LIBRARY_LIBS ${SODIUM_LIBRARIES})
SET(SODIUM_LIBRARY_INCLUDE ${SODIUM_INCLUDE_DIRS})
ADD_DEFINITIONS(-DENABLE_SECURITY)
ELSE()
SET(SODIUM_LIBRARY_TYPE " Disabled")
SET(SODIUM_LIBRARY_ENABLED OFF)
ENDIF()
IF(Lua51_FOUND)
SET(LUA_LIBRARY_TYPE " Lua 5.1")
SET(LUA_LIBRARY_LIBS ${LUA_LIBRARY} luabind)
SET(LUA_LIBRARY_INCLUDE ${LUA_INCLUDE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/libs/luabind")
OPTION(EQEMU_BUILD_LUA "Build Lua parser." ON)
IF(EQEMU_BUILD_LUA)
ADD_DEFINITIONS(-DLUA_EQEMU)
OPTION(EQEMU_SANITIZE_LUA_LIBS "Sanitize Lua Libraries (Remove OS and IO standard libraries from being able to run)." ON)
IF(EQEMU_SANITIZE_LUA_LIBS)
ADD_DEFINITIONS(-DSANITIZE_LUA_LIBS)
ENDIF()
OPTION(EQEMU_ENABLE_SECURITY "Use Encryption For TCP Connections" ON)
IF(EQEMU_ENABLE_SECURITY)
INCLUDE_DIRECTORIES(SYSTEM "${SODIUM_INCLUDE_DIRS}")
ADD_DEFINITIONS(-DENABLE_SECURITY)
SET(SERVER_LIBS ${SERVER_LIBS} ${SODIUM_LIBRARIES})
ENDIF()
ELSE()
SET(LUA_LIBRARY_TYPE "Disabled")
ENDIF()
IF(PerlLibs_FOUND)
SET(PERL_LIBRARY_TYPE " Perl")
SET(PERL_LIBRARY_LIBS ${PERL_LIBRARY})
SET(PERL_LIBRARY_INCLUDE ${PERL_INCLUDE_PATH})
OPTION(EQEMU_BUILD_PERL "Build Perl parser." ON)
IF(EQEMU_BUILD_PERL)
ADD_DEFINITIONS(-DEMBPERL)
ADD_DEFINITIONS(-DEMBPERL_PLUGIN)
ENDIF()
ELSE()
SET(PERL_LIBRARY_TYPE "Disabled")
ENDIF()
#use zlib if exists
IF(ZLIB_FOUND)
OPTION(EQEMU_BUILD_ZLIB "Build internal version of zlib." OFF)
IF(EQEMU_BUILD_ZLIB)
SET(ZLIB_LIBRARY_TYPE "zlib-ng")
SET(ZLIB_LIBRARY_LIBS "zlibstatic")
SET(ZLIB_LIBRARY_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/submodules/zlibng")
INCLUDE_DIRECTORIES(BEFORE SYSTEM "${CMAKE_CURRENT_BINARY_DIR}/libs/zlibng" "${CMAKE_CURRENT_SOURCE_DIR}/libs/zlibng")
SET(SERVER_LIBS ${SERVER_LIBS} "zlibstatic")
ELSE()
SET(ZLIB_LIBRARY_TYPE " zlib")
SET(ZLIB_LIBRARY_LIBS ${ZLIB_LIBRARY})
SET(ZLIB_LIBRARY_INCLUDE ${ZLIB_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(SYSTEM "${ZLIB_INCLUDE_DIRS}")
SET(SERVER_LIBS ${SERVER_LIBS} ${ZLIB_LIBRARY})
ENDIF()
ELSE()
SET(ZLIB_LIBRARY_TYPE "zlib-ng")
SET(ZLIB_LIBRARY_LIBS "zlibstatic")
SET(ZLIB_LIBRARY_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/submodules/zlibng")
ENDIF()
MESSAGE(STATUS "")
MESSAGE(STATUS "**************************************************")
MESSAGE(STATUS "* Library Usage *")
MESSAGE(STATUS "**************************************************")
MESSAGE(STATUS "* Database: ${DATABASE_LIBRARY_TYPE} *")
MESSAGE(STATUS "* TLS: ${SSL_LIBRARY_TYPE} *")
MESSAGE(STATUS "* Sodium: ${SODIUM_LIBRARY_TYPE} *")
MESSAGE(STATUS "* Lua: ${LUA_LIBRARY_TYPE} *")
MESSAGE(STATUS "* Perl: ${PERL_LIBRARY_TYPE} *")
MESSAGE(STATUS "* zlib: ${ZLIB_LIBRARY_TYPE} *")
MESSAGE(STATUS "**************************************************")
#setup server libs and headers
SET(SERVER_LIBS common ${DATABASE_LIBRARY_LIBS} ${ZLIB_LIBRARY_LIBS} ${Boost_LIBRARIES} uv_a fmt RecastNavigation::Detour)
INCLUDE_DIRECTORIES(SYSTEM "${DATABASE_LIBRARY_INCLUDE}")
INCLUDE_DIRECTORIES(SYSTEM "${ZLIB_LIBRARY_INCLUDE}")
INCLUDE_DIRECTORIES(SYSTEM "${Boost_INCLUDE_DIRS}")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/glm")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/cereal/include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/fmt/include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/libuv/include" )
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DebugUtils/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/Detour/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DetourCrowd/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DetourTileCache/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/Recast/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/websocketpp")
IF(SSL_LIBRARY_ENABLED)
SET(SERVER_LIBS ${SERVER_LIBS} ${SSL_LIBRARY_LIBS})
INCLUDE_DIRECTORIES(SYSTEM "${SSL_LIBRARY_INCLUDE}")
ENDIF()
IF(SODIUM_LIBRARY_ENABLED)
SET(SERVER_LIBS ${SERVER_LIBS} ${SODIUM_LIBRARY_LIBS})
INCLUDE_DIRECTORIES(SYSTEM "${SODIUM_LIBRARY_INCLUDE}")
ENDIF()
IF(EQEMU_BUILD_LUA)
SET(SERVER_LIBS ${SERVER_LIBS} ${LUA_LIBRARY_LIBS})
INCLUDE_DIRECTORIES(SYSTEM "${LUA_LIBRARY_INCLUDE}")
ENDIF()
IF(EQEMU_BUILD_PERL)
SET(SERVER_LIBS ${SERVER_LIBS} ${PERL_LIBRARY_LIBS})
INCLUDE_DIRECTORIES(SYSTEM "${PERL_LIBRARY_INCLUDE}")
MESSAGE(STATUS "Could NOT find ZLIB - using ZLIBSTATIC package.")
SET(EQEMU_BUILD_ZLIB ON)
INCLUDE_DIRECTORIES(BEFORE SYSTEM "${CMAKE_CURRENT_BINARY_DIR}/libs/zlibng" "${CMAKE_CURRENT_SOURCE_DIR}/libs/zlibng")
SET(SERVER_LIBS ${SERVER_LIBS} "zlibstatic")
ENDIF()
IF(WIN32)
@@ -282,30 +344,52 @@ IF(UNIX)
SET(SERVER_LIBS ${SERVER_LIBS} "uuid")
ENDIF()
IF(EQEMU_BUILD_LOGIN AND NOT SSL_LIBRARY_ENABLED)
MESSAGE(FATAL_ERROR "Login server requires a SSL Library to build.")
ENDIF()
IF(EQEMU_BUILD_LUA)
FIND_PACKAGE(EQLua51 REQUIRED)
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREADED ON)
SET(Boost_USE_STATIC_RUNTIME OFF)
SET(BOOST_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/boost")
FIND_PACKAGE(Boost REQUIRED)
INCLUDE_DIRECTORIES(SYSTEM "${LUA_INCLUDE_DIR}" "${Boost_INCLUDE_DIRS}")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/libs/luabind")
OPTION(EQEMU_SANITIZE_LUA_LIBS "Sanitize Lua Libraries (Remove OS and IO standard libraries from being able to run)." ON)
IF(EQEMU_SANITIZE_LUA_LIBS)
ADD_DEFINITIONS(-DSANITIZE_LUA_LIBS)
ENDIF(EQEMU_SANITIZE_LUA_LIBS)
ENDIF(EQEMU_BUILD_LUA)
INCLUDE_DIRECTORIES(SYSTEM "${MySQL_INCLUDE_DIR}")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/glm")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/cereal/include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/fmt/include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/libuv/include" )
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DebugUtils/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/Detour/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DetourCrowd/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DetourTileCache/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/Recast/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/websocketpp")
IF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS OR EQEMU_BUILD_HC)
ADD_SUBDIRECTORY(common)
ADD_SUBDIRECTORY(libs)
ADD_SUBDIRECTORY(submodules/fmt)
ADD_SUBDIRECTORY(submodules/libuv)
IF(EQEMU_BUILD_ZLIB)
SET(ZLIB_COMPAT ON CACHE BOOL "Compile with zlib compatible API")
SET(ZLIB_ENABLE_TESTS OFF CACHE BOOL "Build test binaries")
ADD_SUBDIRECTORY(submodules/zlibng)
ENDIF()
SET(RECASTNAVIGATION_DEMO OFF CACHE BOOL "Build demo")
SET(RECASTNAVIGATION_TESTS OFF CACHE BOOL "Build tests")
SET(RECASTNAVIGATION_EXAMPLES OFF CACHE BOOL "Build examples")
ADD_SUBDIRECTORY(submodules/recastnavigation)
IF(EQEMU_BUILD_ZLIB)
SET(ZLIB_COMPAT ON CACHE BOOL "Compile with zlib compatible API")
SET(ZLIB_ENABLE_TESTS OFF CACHE BOOL "Build test binaries")
ADD_SUBDIRECTORY(libs/zlibng)
ENDIF()
ENDIF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS OR EQEMU_BUILD_HC)
MESSAGE(STATUS "Libs: ${SERVER_LIBS}")
IF(EQEMU_BUILD_SERVER)
ADD_SUBDIRECTORY(shared_memory)
ADD_SUBDIRECTORY(world)
@@ -314,7 +398,6 @@ IF(EQEMU_BUILD_SERVER)
ADD_SUBDIRECTORY(queryserv)
ADD_SUBDIRECTORY(eqlaunch)
ENDIF(EQEMU_BUILD_SERVER)
IF(EQEMU_BUILD_LOGIN)
ADD_SUBDIRECTORY(loginserver)
ENDIF(EQEMU_BUILD_LOGIN)
-3
View File
@@ -1,3 +0,0 @@
# Security Policy - Reporting Vulnerabilities
When reporting active hacks, exploits and other vulnerabilities, please describe how to reproduce said report and if you can provide context into a possible solution
-18
View File
@@ -1,23 +1,5 @@
EQEMu Changelog (Started on Sept 24, 2003 15:50)
-------------------------------------------------------
== 8/16/2019 ==
Akkadius: Simplified the use of roamboxes and improved the AI for roambox pathing https://i.imgur.com/z33u7y9.gif
Akkadius: Implemented command #roambox set <box_size> [move_delay]
Akkadius: Implemented command #roambox remove
Akkadius: Implemented LUA NPC:SetSimpleRoamBox(box_size, [move_distance], [move_delay]);
Akkadius: Implemented Perl $npc->SetSimpleRoamBox(box_size, [move_distance], [move_delay]);
Akkadius: Spawngroup data now hot reloads on #repop
Akkadius: Command #npceditmass now lists column options when one isn't properly specified
Akkadius: Implemented command #spawneditmass <search> <option> <value> with options [respawn_time] currently implemented
== 8/11/2019 ==
Akkadius: Added bulk edit command #npceditmass <column-to-search> <column-search-value> <change-column> <change-value>
Akkadius: Modified #findzone to include clickable saylinks to both regular zone (if able) and private gmzone instances
Akkadius: Added #findzone expansion <expansion-number> to show zones via expansion
== 8/6/2019 ==
Akkadius: Optimizations to movement updates to eliminate ghosting possibilities in larger zones
== 7/22/2019 ==
Uleat: Added script 'vcxproj_dependencies.py' - a script to help determine conflicting project dependencies (alpha-stage)
+1 -1
View File
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
add_subdirectory(import)
add_subdirectory(export)
+1 -1
View File
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(export_sources
main.cpp
+1 -1
View File
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(import_sources
main.cpp
+124
View File
@@ -0,0 +1,124 @@
#CMake - Cross Platform Makefile Generator
#Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
#All rights reserved.
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions
#are met:
#
#* Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
#* Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
#* Neither the names of Kitware, Inc., the Insight Software Consortium,
# nor the names of their contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
#A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
#HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
#THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This module defines
# LUA51_FOUND, if false, do not try to link to Lua
# LUA_LIBRARIES
# LUA_INCLUDE_DIR, where to find lua.h
# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
IF(LUA_ROOT)
FIND_PATH(LUA_INCLUDE_DIR
NAMES lua.h
HINTS
ENV LUA_DIR
PATHS
${LUA_ROOT}
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
PATH_SUFFIXES include/lua51 include/lua5.1 include/lua include src
)
FIND_LIBRARY(LUA_LIBRARY
NAMES lua51 lua5.1 lua-5.1 lua
HINTS
ENV LUA_DIR
PATHS
${LUA_ROOT}
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
PATH_SUFFIXES lib bin
)
ELSE(LUA_ROOT)
FIND_PATH(LUA_INCLUDE_DIR
NAMES lua.h
HINTS
ENV LUA_DIR
PATHS
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
PATH_SUFFIXES include/lua51 include/lua5.1 include/lua include
)
FIND_LIBRARY(LUA_LIBRARY
NAMES lua51 lua5.1 lua-5.1 lua
HINTS
ENV LUA_DIR
PATHS
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
PATH_SUFFIXES lib bin
)
ENDIF(LUA_ROOT)
IF(LUA_LIBRARY)
# include the math library for Unix
IF(UNIX AND NOT APPLE)
FIND_LIBRARY(LUA_MATH_LIBRARY m)
SET(LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
# For Windows and Mac, don't need to explicitly include the math library
ELSE()
SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
ENDIF()
ENDIF()
IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
UNSET(lua_version_str)
ENDIF()
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51
REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
VERSION_VAR LUA_VERSION_STRING)
MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)
-87
View File
@@ -1,87 +0,0 @@
# - Find mariadbclient
#
# -*- cmake -*-
#
# Find the native MariaDB includes and library
#
# MariaDB_INCLUDE_DIR - where to find mysql.h, etc.
# MariaDB_LIBRARIES - List of libraries when using MariaDB.
# MariaDB_FOUND - True if MariaDB found.
# The following can be used as a hint as to where to search:
# MARIADB_ROOT
IF (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARIES)
# Already in cache, be silent
SET(MariaDB_FIND_QUIETLY TRUE)
ENDIF (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARIES)
# Include dir
IF(MARIADB_ROOT)
FIND_PATH(MariaDB_INCLUDE_DIR
NAMES mariadb_version.h
PATHS ${MARIADB_ROOT}/include
PATH_SUFFIXES mysql mariadb
NO_DEFAULT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
)
FIND_PATH(MariaDB_INCLUDE_DIR
NAMES mariadb_version.h
PATH_SUFFIXES mysql mariadb
)
ELSE(MARIADB_ROOT)
FIND_PATH(MariaDB_INCLUDE_DIR
NAMES mariadb_version.h
PATH_SUFFIXES mysql mariadb
)
ENDIF(MARIADB_ROOT)
# Library
SET(MariaDB_NAMES libmariadb)
IF(MARIADB_ROOT)
FIND_LIBRARY(MariaDB_LIBRARY
NAMES ${MariaDB_NAMES}
PATHS ${MARIADB_ROOT}/lib
PATH_SUFFIXES mysql mariadb
NO_DEFAULT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
)
FIND_LIBRARY(MariaDB_LIBRARY
NAMES ${MariaDB_NAMES}
PATH_SUFFIXES mysql mariadb
)
ELSE(MARIADB_ROOT)
FIND_LIBRARY(MariaDB_LIBRARY
NAMES ${MariaDB_NAMES} mariadbclient_r mariadbclient
PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64
PATH_SUFFIXES mysql mariadb
)
ENDIF(MARIADB_ROOT)
IF (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARY)
SET(MariaDB_FOUND TRUE)
SET(MariaDB_LIBRARIES ${MariaDB_LIBRARY})
ELSE (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARY)
SET(MariaDB_FOUND FALSE)
SET(MariaDB_LIBRARIES)
ENDIF (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARY)
# handle the QUIETLY and REQUIRED arguments and set MariaDB_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(MariaDB DEFAULT_MSG MariaDB_LIBRARY MariaDB_INCLUDE_DIR)
IF(MariaDB_FOUND)
SET( MariaDB_LIBRARY_RELEASE ${MariaDB_LIBRARY} )
SET( MariaDB_LIBRARY_DEBUG ${MariaDB_LIBRARY} )
SET( MariaDB_LIBRARIES ${MariaDB_LIBRARY_RELEASE} ${MariaDB_LIBRARY_DEBUG} )
ELSE(MariaDB_FOUND)
SET( MariaDB_LIBRARIES )
ENDIF(MariaDB_FOUND)
MARK_AS_ADVANCED(
MariaDB_LIBRARY_DEBUG
MariaDB_LIBRARY_RELEASE
MariaDB_INCLUDE_DIR
)
-93
View File
@@ -1,93 +0,0 @@
# - Try to find mbedTLS
# Once done this will define
#
# Read-Only variables
# MBEDTLS_FOUND - system has mbedTLS
# MBEDTLS_INCLUDE_DIR - the mbedTLS include directory
# MBEDTLS_LIBRARY_DIR - the mbedTLS library directory
# MBEDTLS_LIBRARIES - Link these to use mbedTLS
# MBEDTLS_LIBRARY - path to mbedTLS library
# MBEDX509_LIBRARY - path to mbedTLS X.509 library
# MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto library
#
# Hint
# MBEDTLS_ROOT_DIR can be pointed to a local mbedTLS installation.
SET(_MBEDTLS_ROOT_HINTS
${MBEDTLS_ROOT_DIR}
ENV MBEDTLS_ROOT_DIR
)
SET(_MBEDTLS_ROOT_HINTS_AND_PATHS
HINTS ${_MBEDTLS_ROOT_HINTS}
PATHS ${_MBEDTLS_ROOT_PATHS}
)
FIND_PATH(MBEDTLS_INCLUDE_DIR
NAMES mbedtls/version.h
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES include
)
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
# Already in cache, be silent
SET(MBEDTLS_FIND_QUIETLY TRUE)
ENDIF()
FIND_LIBRARY(MBEDTLS_LIBRARY
NAMES mbedtls libmbedtls
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES library
)
FIND_LIBRARY(MBEDX509_LIBRARY
NAMES mbedx509 libmbedx509
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES library
)
FIND_LIBRARY(MBEDCRYPTO_LIBRARY
NAMES mbedcrypto libmbedcrypto
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES library
)
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
SET(MBEDTLS_FOUND TRUE)
ENDIF()
IF(MBEDTLS_FOUND)
# split mbedTLS into -L and -l linker options, so we can set them for pkg-config
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH)
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE)
STRING(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE})
STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE})
STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE})
SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}")
IF(NOT MBEDTLS_FIND_QUIETLY)
MESSAGE(STATUS "Found mbedTLS:")
FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
IF (MBEDTLSMATCH)
STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
MESSAGE(STATUS " version ${MBEDTLS_VERSION}")
ENDIF(MBEDTLSMATCH)
MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}")
MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}")
MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
ENDIF(NOT MBEDTLS_FIND_QUIETLY)
ELSE(MBEDTLS_FOUND)
IF(MBEDTLS_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find mbedTLS")
ENDIF(MBEDTLS_FIND_REQUIRED)
ENDIF(MBEDTLS_FOUND)
MARK_AS_ADVANCED(
MBEDTLS_INCLUDE_DIR
MBEDTLS_LIBRARY_DIR
MBEDTLS_LIBRARIES
MBEDTLS_LIBRARY
MBEDX509_LIBRARY
MBEDCRYPTO_LIBRARY
)
+3 -3
View File
@@ -1,4 +1,5 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(common_sources
base_packet.cpp
classes.cpp
@@ -211,8 +212,8 @@ SET(common_headers
xml_parser.h
zone_numbers.h
event/event_loop.h
event/idle.h
event/task.h
event/task_scheduler.h
event/timer.h
json/json.h
json/json-forwards.h
@@ -272,7 +273,6 @@ SET(common_headers
SOURCE_GROUP(Event FILES
event/event_loop.h
event/idle.h
event/timer.h
event/task.h
)
+1 -1
View File
@@ -23,7 +23,7 @@
* 2005-08-05 v5 - Removed most Lint (http://www.gimpel.com/) errors... thanks to Okko Willeboordse!
*
**********************************************************************/
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
+1 -1
View File
@@ -9,7 +9,7 @@
* 2013-01-26 - Modified by KimLS(KLS) for EQEmu's purposes
*
**********************************************************************/
#ifdef _WIN32
#ifdef _WINDOWS
// #pragma once is supported starting with _MCS_VER 1000,
// so we need not to check the version (because we only support _MSC_VER >= 1100)!
#pragma once
+1 -1
View File
@@ -23,7 +23,7 @@
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#ifdef _WINDOWS
#include <time.h>
#include <winsock2.h>
#include <windows.h>
+1 -1
View File
@@ -18,7 +18,7 @@
#include "condition.h"
#ifdef _WIN32
#ifdef _WINDOWS
Condition::Condition()
{
+2 -2
View File
@@ -20,7 +20,7 @@
#include "global_define.h"
#include "mutex.h"
#ifndef _WIN32
#ifndef WIN32
#include <pthread.h>
#endif
@@ -30,7 +30,7 @@
class Condition {
private:
#ifdef _WIN32
#ifdef WIN32
enum {
SignalEvent = 0,
BroadcastEvent,
+1 -1
View File
@@ -2,7 +2,7 @@
#include "eqemu_logsys.h"
#include "crash.h"
#if defined(_WIN32) && defined(CRASH_LOGGING)
#if defined(_WINDOWS) && defined(CRASH_LOGGING)
#include "StackWalker.h"
class EQEmuStackWalker : public StackWalker
+1 -1
View File
@@ -30,7 +30,7 @@
#include <string.h>
// Disgrace: for windows compile
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#define snprintf _snprintf
#define strncasecmp _strnicmp
+10 -2
View File
@@ -82,9 +82,17 @@ struct VarCache_Struct {
};
class PTimerList;
# define _ISNAN_(a) std::isnan(a)
#define SQL(...) #__VA_ARGS__
#ifdef _WINDOWS
#if _MSC_VER > 1700 // greater than 2012 (2013+)
# define _ISNAN_(a) std::isnan(a)
#else
# include <float.h>
# define _ISNAN_(a) _isnan(a)
#endif
#else
# define _ISNAN_(a) std::isnan(a)
#endif
class Database : public DBcore {
public:
+2 -2
View File
@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <iostream>
// Disgrace: for windows compile
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#define snprintf _snprintf
#define strncasecmp _strnicmp
@@ -476,7 +476,7 @@ bool Database::CheckDatabaseConversions() {
CheckDatabaseConvertCorpseDeblob();
/* Run EQEmu Server script (Checks for database updates) */
if(system("perl eqemu_server.pl ran_from_world"));
system("perl eqemu_server.pl ran_from_world");
return true;
}
+1 -1
View File
@@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <iostream>
// Disgrace: for windows compile
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#define snprintf _snprintf
#define strncasecmp _strnicmp
+2 -2
View File
@@ -1,4 +1,4 @@
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#endif
@@ -13,7 +13,7 @@
#include <mysqld_error.h>
#include <string.h>
#ifdef _WIN32
#ifdef _WINDOWS
#define snprintf _snprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef DBCORE_H
#define DBCORE_H
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#endif
-4
View File
@@ -77,10 +77,6 @@ namespace EQEmu
} // namespace invtype
namespace DevTools {
const int32 GM_ACCOUNT_STATUS_LEVEL = 150;
}
namespace popupresponse {
const int32 SERVER_INTERNAL_USE_BASE = 2000000000;
const int32 MOB_INFO_DISMISS = 2000000001;
+194 -108
View File
@@ -71,7 +71,7 @@
//#define AT_Trader 300 // Bazaar Trader Mode (not present in SoF or RoF2)
// animations for AT_Anim
#define ANIM_FREEZE 102
#define ANIM_FREEZE 102
#define ANIM_STAND 0x64
#define ANIM_SIT 0x6e
#define ANIM_CROUCH 0x6f
@@ -87,114 +87,200 @@ typedef enum {
_eaMaxAppearance
} EmuAppearance;
namespace Chat {
const uint16 White = 0;
const uint16 DimGray = 1;
const uint16 Default = 1;
const uint16 Green = 2;
const uint16 BrightBlue = 3;
const uint16 LightBlue = 4;
const uint16 Magenta = 5;
const uint16 Gray = 6;
const uint16 LightGray = 7;
const uint16 NPCQuestSay = 10;
const uint16 DarkGray = 12;
const uint16 Red = 13;
const uint16 Lime = 14;
const uint16 Yellow = 15;
const uint16 Blue = 16;
const uint16 LightNavy = 17;
const uint16 Cyan = 18;
const uint16 Black = 20;
#define MT_NPCQuestSay 10
// msg_type's for custom usercolors
#define MT_Say 256
#define MT_Tell 257
#define MT_Group 258
#define MT_Guild 259
#define MT_OOC 260
#define MT_Auction 261
#define MT_Shout 262
#define MT_Emote 263
#define MT_Spells 264
#define MT_YouHitOther 265
#define MT_OtherHitsYou 266
#define MT_YouMissOther 267
#define MT_OtherMissesYou 268
#define MT_Broadcasts 269
#define MT_Skills 270
#define MT_Disciplines 271
#define MT_Unused1 272
#define MT_DefaultText 273
#define MT_Unused2 274
#define MT_MerchantOffer 275
#define MT_MerchantBuySell 276
#define MT_YourDeath 277
#define MT_OtherDeath 278
#define MT_OtherHits 279
#define MT_OtherMisses 280
#define MT_Who 281
#define MT_YellForHelp 282
#define MT_NonMelee 283
#define MT_WornOff 284
#define MT_MoneySplit 285
#define MT_LootMessages 286
#define MT_DiceRoll 287
#define MT_OtherSpells 288
#define MT_SpellFailure 289
#define MT_Chat 290
#define MT_Channel1 291
#define MT_Channel2 292
#define MT_Channel3 293
#define MT_Channel4 294
#define MT_Channel5 295
#define MT_Channel6 296
#define MT_Channel7 297
#define MT_Channel8 298
#define MT_Channel9 299
#define MT_Channel10 300
#define MT_CritMelee 301
#define MT_SpellCrits 302
#define MT_TooFarAway 303
#define MT_NPCRampage 304
#define MT_NPCFlurry 305
#define MT_NPCEnrage 306
#define MT_SayEcho 307
#define MT_TellEcho 308
#define MT_GroupEcho 309
#define MT_GuildEcho 310
#define MT_OOCEcho 311
#define MT_AuctionEcho 312
#define MT_ShoutECho 313
#define MT_EmoteEcho 314
#define MT_Chat1Echo 315
#define MT_Chat2Echo 316
#define MT_Chat3Echo 317
#define MT_Chat4Echo 318
#define MT_Chat5Echo 319
#define MT_Chat6Echo 320
#define MT_Chat7Echo 321
#define MT_Chat8Echo 322
#define MT_Chat9Echo 323
#define MT_Chat10Echo 324
#define MT_DoTDamage 325
#define MT_ItemLink 326
#define MT_RaidSay 327
#define MT_MyPet 328
#define MT_DS 329
#define MT_Leadership 330
#define MT_PetFlurry 331
#define MT_PetCrit 332
#define MT_FocusEffect 333
#define MT_Experience 334
#define MT_System 335
#define MT_PetSpell 336
#define MT_PetResponse 337
#define MT_ItemSpeech 338
#define MT_StrikeThrough 339
#define MT_Stun 340
/**
* User colors
*/
const uint16 Say = 256;
const uint16 Tell = 257;
const uint16 Group = 258;
const uint16 Guild = 259;
const uint16 OOC = 260;
const uint16 Auction = 261;
const uint16 Shout = 262;
const uint16 Emote = 263;
const uint16 Spells = 264;
const uint16 YouHitOther = 265;
const uint16 OtherHitYou = 266;
const uint16 YouMissOther = 267;
const uint16 OtherMissYou = 268;
const uint16 Broadcasts = 269;
const uint16 Skills = 270;
const uint16 Disciplines = 271;
const uint16 Unused1 = 272;
const uint16 DefaultText = 273;
const uint16 Unused2 = 274;
const uint16 MerchantOffer = 275;
const uint16 MerchantExchange = 276;
const uint16 YourDeath = 277;
const uint16 OtherDeath = 278;
const uint16 OtherHitOther = 279;
const uint16 OtherMissOther = 280;
const uint16 Who = 281;
const uint16 YellForHelp = 282;
const uint16 NonMelee = 283;
const uint16 SpellWornOff = 284;
const uint16 MoneySplit = 285;
const uint16 Loot = 286;
const uint16 DiceRoll = 287;
const uint16 OtherSpells = 288;
const uint16 SpellFailure = 289;
const uint16 ChatChannel = 290;
const uint16 Chat1 = 291;
const uint16 Chat2 = 292;
const uint16 Chat3 = 293;
const uint16 Chat4 = 294;
const uint16 Chat5 = 295;
const uint16 Chat6 = 296;
const uint16 Chat7 = 297;
const uint16 Chat8 = 298;
const uint16 Chat9 = 299;
const uint16 Chat10 = 300;
const uint16 MeleeCrit = 301;
const uint16 SpellCrit = 302;
const uint16 TooFarAway = 303;
const uint16 NPCRampage = 304;
const uint16 NPCFlurry = 305;
const uint16 NPCEnrage = 306;
const uint16 EchoSay = 307;
const uint16 EchoTell = 308;
const uint16 EchoGroup = 309;
const uint16 EchoGuild = 310;
const uint16 EchoOOC = 311;
const uint16 EchoAuction = 312;
const uint16 EchoShout = 313;
const uint16 EchoEmote = 314;
const uint16 EchoChat1 = 315;
const uint16 EchoChat2 = 316;
const uint16 EchoChat3 = 317;
const uint16 EchoChat4 = 318;
const uint16 EchoChat5 = 319;
const uint16 EchoChat6 = 320;
const uint16 EchoChat7 = 321;
const uint16 EchoChat8 = 322;
const uint16 EchoChat9 = 323;
const uint16 EchoChat10 = 324;
const uint16 DotDamage = 325;
const uint16 ItemLink = 326;
const uint16 RaidSay = 327;
const uint16 MyPet = 328;
const uint16 DamageShield = 329;
const uint16 LeaderShip = 330;
const uint16 PetFlurry = 331;
const uint16 PetCritical = 332;
const uint16 FocusEffect = 333;
const uint16 Experience = 334;
const uint16 System = 335;
const uint16 PetSpell = 336;
const uint16 PetResponse = 337;
const uint16 ItemSpeech = 338;
const uint16 StrikeThrough = 339;
const uint16 Stun = 340;
// TODO: Really should combine above and below into one
//from showeq
enum ChatColor
{
/*
CC_Default = 0,
CC_DarkGrey = 1,
CC_DarkGreen = 2,
CC_DarkBlue = 3,
CC_Purple = 5,
CC_LightGrey = 6,
*/
CC_WhiteSmoke = 0, // FF|F0F0F0
CC_Green = 2, // FF|008000
CC_BrightBlue = 3, // FF|0040FF
CC_Magenta = 5, // FF|F000F0
CC_Gray = 6, // FF|808080
CC_LightGray = 7, // FF|E0E0E0
//CC_WhiteSmoke2 = 10, // FF|F0F0F0
CC_DarkGray = 12, // FF|A0A0A0
CC_Red = 13, // FF|F00000
CC_Lime = 14, // FF|00F000
CC_Yellow = 15, // FF|F0F000
CC_Blue = 16, // FF|0000F0
CC_LightNavy = 17, // FF|0000AF
CC_Cyan = 18, // FF|00F0F0
CC_Black = 20, // FF|000000
// any index <= 255 that is not defined above
CC_DimGray = 1, // FF|606060
CC_Default = 1,
CC_User_Say = 256,
CC_User_Tell = 257,
CC_User_Group = 258,
CC_User_Guild = 259,
CC_User_OOC = 260,
CC_User_Auction = 261,
CC_User_Shout = 262,
CC_User_Emote = 263,
CC_User_Spells = 264,
CC_User_YouHitOther = 265,
CC_User_OtherHitYou = 266,
CC_User_YouMissOther = 267,
CC_User_OtherMissYou = 268,
CC_User_Duels = 269,
CC_User_Skills = 270,
CC_User_Disciplines = 271,
CC_User_Default = 273,
CC_User_MerchantOffer = 275,
CC_User_MerchantExchange = 276,
CC_User_YourDeath = 277,
CC_User_OtherDeath = 278,
CC_User_OtherHitOther = 279,
CC_User_OtherMissOther = 280,
CC_User_Who = 281,
CC_User_Yell = 282,
CC_User_NonMelee = 283,
CC_User_SpellWornOff = 284,
CC_User_MoneySplit = 285,
CC_User_Loot = 286,
CC_User_Random = 287,
CC_User_OtherSpells = 288,
CC_User_SpellFailure = 289,
CC_User_ChatChannel = 290,
CC_User_Chat1 = 291,
CC_User_Chat2 = 292,
CC_User_Chat3 = 293,
CC_User_Chat4 = 294,
CC_User_Chat5 = 295,
CC_User_Chat6 = 296,
CC_User_Chat7 = 297,
CC_User_Chat8 = 298,
CC_User_Chat9 = 299,
CC_User_Chat10 = 300,
CC_User_MeleeCrit = 301,
CC_User_SpellCrit = 302,
CC_User_TooFarAway = 303,
CC_User_NPCRampage = 304,
CC_User_NPCFurry = 305,
CC_User_NPCEnrage = 306,
CC_User_EchoSay = 307,
CC_User_EchoTell = 308,
CC_User_EchoGroup = 309,
CC_User_EchoGuild = 310,
CC_User_EchoOOC = 311,
CC_User_EchoAuction = 312,
CC_User_EchoShout = 313,
CC_User_EchoEmote = 314,
CC_User_EchoChat1 = 315,
CC_User_EchoChat2 = 316,
CC_User_EchoChat3 = 317,
CC_User_EchoChat4 = 318,
CC_User_EchoChat5 = 319,
CC_User_EchoChat6 = 320,
CC_User_EchoChat7 = 321,
CC_User_EchoChat8 = 322,
CC_User_EchoChat9 = 323,
CC_User_EchoChat10 = 324,
CC_User_UnusedAtThisTime = 325,
CC_User_ItemTags = 326,
CC_User_RaidSay = 327,
CC_User_MyPet = 328,
CC_User_DamageShield = 329,
};
//ZoneChange_Struct->success values
+1 -1
View File
@@ -152,7 +152,7 @@ void EQEmuConfig::parse_config()
TerminateWait = atoi(_root["server"]["launcher"]["timers"].get("reterminate", "10000").asString().c_str());
InitialBootWait = atoi(_root["server"]["launcher"]["timers"].get("initial", "20000").asString().c_str());
ZoneBootInterval = atoi(_root["server"]["launcher"]["timers"].get("interval", "2000").asString().c_str());
#ifdef _WIN32
#ifdef WIN32
ZoneExe = _root["server"]["launcher"].get("exe", "zone.exe").asString();
#else
ZoneExe = _root["server"]["launcher"].get("exe", "./zone").asString();
+18 -10
View File
@@ -33,7 +33,7 @@
std::ofstream process_log;
#ifdef _WIN32
#ifdef _WINDOWS
#include <direct.h>
#include <conio.h>
#include <iostream>
@@ -81,6 +81,14 @@ namespace Console {
};
}
enum GameChatColor {
yellow = 15,
red = 13,
light_green = 14,
light_cyan = 258,
light_purple = 5
};
/**
* EQEmuLogSys Constructor
*/
@@ -298,22 +306,22 @@ uint16 EQEmuLogSys::GetGMSayColorFromCategory(uint16 log_category)
switch (log_category) {
case Logs::Status:
case Logs::Normal:
return Chat::Yellow;
return GameChatColor::yellow;
case Logs::MySQLError:
case Logs::Error:
return Chat::Red;
return GameChatColor::red;
case Logs::MySQLQuery:
case Logs::Debug:
return Chat::Lime;
return GameChatColor::light_green;
case Logs::Quests:
return Chat::Group;
return GameChatColor::light_cyan;
case Logs::Commands:
case Logs::Mercenaries:
return Chat::Magenta;
return GameChatColor::light_purple;
case Logs::Crash:
return Chat::Red;
return GameChatColor::red;
default:
return Chat::Yellow;
return GameChatColor::yellow;
}
}
@@ -324,7 +332,7 @@ uint16 EQEmuLogSys::GetGMSayColorFromCategory(uint16 log_category)
*/
void EQEmuLogSys::ProcessConsoleMessage(uint16 debug_level, uint16 log_category, const std::string &message)
{
#ifdef _WIN32
#ifdef _WINDOWS
HANDLE console_handle;
console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFOEX info = { 0 };
@@ -408,7 +416,7 @@ void EQEmuLogSys::SetCurrentTimeStamp(char *time_stamp)
*/
void EQEmuLogSys::MakeDirectory(const std::string &directory_name)
{
#ifdef _WIN32
#ifdef _WINDOWS
struct _stat st;
if (_stat(directory_name.c_str(), &st) == 0) // exists
return;
+12 -12
View File
@@ -8,30 +8,30 @@ namespace EQ
class EventLoop
{
public:
EventLoop() {
memset(&m_loop, 0, sizeof(uv_loop_t));
uv_loop_init(&m_loop);
static EventLoop &Get() {
static thread_local EventLoop inst;
return inst;
}
~EventLoop() {
uv_loop_close(&m_loop);
}
EventLoop(const EventLoop&) = delete;
EventLoop& operator=(const EventLoop&) = delete;
static EventLoop &GetDefault() {
static thread_local EventLoop inst;
return inst;
}
void Process() {
uv_run(&m_loop, UV_RUN_NOWAIT);
}
uv_loop_t* Handle() { return &m_loop; }
private:
private:
EventLoop() {
memset(&m_loop, 0, sizeof(uv_loop_t));
uv_loop_init(&m_loop);
}
EventLoop(const EventLoop&);
EventLoop& operator=(const EventLoop&);
uv_loop_t m_loop;
};
}
View File
+17 -22
View File
@@ -24,12 +24,8 @@ namespace EQ {
std::exception error;
};
Task(EventLoop &loop, TaskFn fn) : _loop(loop) {
_fn = fn;
}
Task(TaskFn fn) : _loop(EventLoop::GetDefault()) {
_fn = fn;
Task(TaskFn fn) {
m_fn = fn;
}
~Task() {
@@ -37,34 +33,34 @@ namespace EQ {
}
Task& Then(ResolveFn fn) {
_then = fn;
m_then = fn;
return *this;
}
Task& Catch(RejectFn fn) {
_catch = fn;
m_catch = fn;
return *this;
}
Task& Finally(FinallyFn fn) {
_fin = fn;
m_finally = fn;
return *this;
}
void Run() {
uv_work_t *work = new uv_work_t;
memset(work, 0, sizeof(uv_work_t));
uv_work_t *m_work = new uv_work_t;
memset(m_work, 0, sizeof(uv_work_t));
TaskBaton *baton = new TaskBaton();
baton->fn = _fn;
baton->on_then = _then;
baton->on_catch = _catch;
baton->on_finally = _fin;
baton->fn = m_fn;
baton->on_then = m_then;
baton->on_catch = m_catch;
baton->on_finally = m_finally;
baton->has_result = false;
baton->has_error = false;
work->data = baton;
m_work->data = baton;
uv_queue_work(_loop.Handle(), work, [](uv_work_t* req) {
uv_queue_work(EventLoop::Get().Handle(), m_work, [](uv_work_t* req) {
TaskBaton *baton = (TaskBaton*)req->data;
baton->fn([baton](const EQEmu::Any& result) {
@@ -96,10 +92,9 @@ namespace EQ {
}
private:
TaskFn _fn;
ResolveFn _then;
RejectFn _catch;
FinallyFn _fin;
EventLoop &_loop;
TaskFn m_fn;
ResolveFn m_then;
RejectFn m_catch;
FinallyFn m_finally;
};
}
+114
View File
@@ -0,0 +1,114 @@
#pragma once
#include <vector>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <queue>
#include <future>
namespace EQ
{
namespace Event
{
class TaskScheduler
{
public:
static const int DefaultThreadCount = 4;
TaskScheduler() : _running(false)
{
Start(DefaultThreadCount);
}
TaskScheduler(size_t threads) : _running(false)
{
Start(threads);
}
~TaskScheduler() {
Stop();
}
void Start(size_t threads) {
if (true == _running) {
return;
}
_running = true;
for (size_t i = 0; i < threads; ++i) {
_threads.push_back(std::thread(std::bind(&TaskScheduler::ProcessWork, this)));
}
}
void Stop() {
if (false == _running) {
return;
}
{
std::unique_lock<std::mutex> lock(_lock);
_running = false;
}
_cv.notify_all();
for (auto &t : _threads) {
t.join();
}
}
template<typename Fn, typename... Args>
auto Enqueue(Fn&& fn, Args&&... args) -> std::future<typename std::result_of<Fn(Args...)>::type> {
using return_type = typename std::result_of<Fn(Args...)>::type;
auto task = std::make_shared<std::packaged_task<return_type()>>(
std::bind(std::forward<Fn>(fn), std::forward<Args>(args)...)
);
std::future<return_type> res = task->get_future();
{
std::unique_lock<std::mutex> lock(_lock);
if (false == _running) {
throw std::runtime_error("Enqueue on stopped scheduler.");
}
_tasks.emplace([task]() { (*task)(); });
}
_cv.notify_one();
return res;
}
private:
void ProcessWork() {
for (;;) {
std::function<void()> work;
{
std::unique_lock<std::mutex> lock(_lock);
_cv.wait(lock, [this] { return !_running || !_tasks.empty(); });
if (false == _running) {
return;
}
work = std::move(_tasks.front());
_tasks.pop();
}
work();
}
}
bool _running = true;
std::vector<std::thread> _threads;
std::mutex _lock;
std::condition_variable _cv;
std::queue<std::function<void()>> _tasks;
};
}
}
+20 -34
View File
@@ -6,29 +6,16 @@ namespace EQ {
class Timer
{
public:
Timer(EventLoop &loop, std::function<void(Timer *)> cb) : _loop(loop)
Timer(std::function<void(Timer *)> cb)
{
_timer = nullptr;
_cb = cb;
m_timer = nullptr;
m_cb = cb;
}
Timer(EventLoop &loop, uint64_t duration_ms, bool repeats, std::function<void(Timer *)> cb) : _loop(loop)
Timer(uint64_t duration_ms, bool repeats, std::function<void(Timer *)> cb)
{
_timer = nullptr;
_cb = cb;
Start(duration_ms, repeats);
}
Timer(std::function<void(Timer *)> cb) : _loop(EventLoop::GetDefault())
{
_timer = nullptr;
_cb = cb;
}
Timer(uint64_t duration_ms, bool repeats, std::function<void(Timer *)> cb) : _loop(EventLoop::GetDefault())
{
_timer = nullptr;
_cb = cb;
m_timer = nullptr;
m_cb = cb;
Start(duration_ms, repeats);
}
@@ -38,21 +25,21 @@ namespace EQ {
}
void Start(uint64_t duration_ms, bool repeats) {
auto loop = EventLoop::GetDefault().Handle();
if (!_timer) {
_timer = new uv_timer_t;
memset(_timer, 0, sizeof(uv_timer_t));
uv_timer_init(loop, _timer);
_timer->data = this;
auto loop = EventLoop::Get().Handle();
if (!m_timer) {
m_timer = new uv_timer_t;
memset(m_timer, 0, sizeof(uv_timer_t));
uv_timer_init(loop, m_timer);
m_timer->data = this;
if (repeats) {
uv_timer_start(_timer, [](uv_timer_t *handle) {
uv_timer_start(m_timer, [](uv_timer_t *handle) {
Timer *t = (Timer*)handle->data;
t->Execute();
}, duration_ms, duration_ms);
}
else {
uv_timer_start(_timer, [](uv_timer_t *handle) {
uv_timer_start(m_timer, [](uv_timer_t *handle) {
Timer *t = (Timer*)handle->data;
t->Stop();
t->Execute();
@@ -62,20 +49,19 @@ namespace EQ {
}
void Stop() {
if (_timer) {
uv_close((uv_handle_t*)_timer, [](uv_handle_t* handle) {
if (m_timer) {
uv_close((uv_handle_t*)m_timer, [](uv_handle_t* handle) {
delete handle;
});
_timer = nullptr;
m_timer = nullptr;
}
}
private:
void Execute() {
_cb(this);
m_cb(this);
}
EventLoop &_loop;
uv_timer_t *_timer;
std::function<void(Timer*)> _cb;
uv_timer_t *m_timer;
std::function<void(Timer*)> m_cb;
};
}
+2 -2
View File
@@ -17,7 +17,7 @@
*/
// WHY IS THIS UP HERE
#if defined(_DEBUG) && defined(_WIN32)
#if defined(_DEBUG) && defined(WIN32)
#ifndef _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
@@ -27,7 +27,7 @@
#ifndef EQDEBUG_H
#define EQDEBUG_H
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#endif
+2 -2
View File
@@ -23,6 +23,6 @@
#include "eq_packet_structs.h"
#ifndef _WIN32
#ifndef WIN32
#include <netinet/in.h> //for htonl
#endif
#endif
+6 -6
View File
@@ -17,7 +17,7 @@
*/
#include "ipc_mutex.h"
#ifdef _WIN32
#ifdef _WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#undef WIN32_LEAN_AND_MEAN
@@ -33,7 +33,7 @@
namespace EQEmu {
struct IPCMutex::Implementation {
#ifdef _WIN32
#ifdef _WINDOWS
HANDLE mut_;
#else
int fd_;
@@ -42,7 +42,7 @@ namespace EQEmu {
IPCMutex::IPCMutex(std::string name) : locked_(false) {
imp_ = new Implementation;
#ifdef _WIN32
#ifdef _WINDOWS
auto Config = EQEmuConfig::get();
std::string final_name = Config->SharedMemDir + "EQEmuMutex_";
final_name += name;
@@ -82,7 +82,7 @@ namespace EQEmu {
}
IPCMutex::~IPCMutex() {
#ifdef _WIN32
#ifdef _WINDOWS
if(locked_) {
ReleaseMutex(imp_->mut_);
}
@@ -103,7 +103,7 @@ namespace EQEmu {
return false;
}
#ifdef _WIN32
#ifdef _WINDOWS
DWORD wait_result = WaitForSingleObject(imp_->mut_, INFINITE);
if(wait_result != WAIT_OBJECT_0) {
return false;
@@ -121,7 +121,7 @@ namespace EQEmu {
if(!locked_) {
return false;
}
#ifdef _WIN32
#ifdef _WINDOWS
if(!ReleaseMutex(imp_->mut_)) {
return false;
}
+5 -5
View File
@@ -17,7 +17,7 @@
*/
#include "memory_mapped_file.h"
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#else
#include <sys/types.h>
@@ -36,7 +36,7 @@
namespace EQEmu {
struct MemoryMappedFile::Implementation {
#ifdef _WIN32
#ifdef _WINDOWS
HANDLE mapped_object_;
#else
int fd_;
@@ -47,7 +47,7 @@ namespace EQEmu {
: filename_(filename), size_(size) {
imp_ = new Implementation;
#ifdef _WIN32
#ifdef _WINDOWS
DWORD total_size = size + sizeof(shared_memory_struct);
HANDLE file = CreateFile(filename.c_str(),
GENERIC_READ | GENERIC_WRITE,
@@ -116,7 +116,7 @@ namespace EQEmu {
size_ = size;
fclose(f);
#ifdef _WIN32
#ifdef _WINDOWS
DWORD total_size = size + sizeof(shared_memory_struct);
HANDLE file = CreateFile(filename.c_str(),
GENERIC_READ | GENERIC_WRITE,
@@ -172,7 +172,7 @@ namespace EQEmu {
}
MemoryMappedFile::~MemoryMappedFile() {
#ifdef _WIN32
#ifdef _WINDOWS
if(imp_->mapped_object_) {
CloseHandle(imp_->mapped_object_);
}
+4 -4
View File
@@ -1,4 +1,4 @@
#ifdef _WIN32
#ifdef _WINDOWS
// VS6 doesn't like the length of STL generated names: disabling
#pragma warning(disable:4786)
#endif
@@ -10,7 +10,7 @@
#include <iostream>
#include <zlib.h>
#ifndef _WIN32
#ifndef WIN32
#include <sys/time.h>
#endif
@@ -24,7 +24,7 @@
std::map<int,std::string> DBFieldNames;
#ifndef _WIN32
#ifndef WIN32
#if defined(FREEBSD) || defined(__CYGWIN__)
int print_stacktrace()
{
@@ -526,7 +526,7 @@ std::string generate_key(int length)
{
std::string key;
//TODO: write this for win32...
#ifndef _WIN32
#ifndef WIN32
int i;
timeval now;
static const char *chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+1 -1
View File
@@ -24,7 +24,7 @@ void decode(char *in, char *out);
void encode_chunk(char *in, int len, char *out);
void decode_chunk(char *in, char *out);
#ifndef _WIN32
#ifndef WIN32
int print_stacktrace();
#endif
+10 -10
View File
@@ -22,19 +22,19 @@
#include <string.h>
#include <time.h>
#ifndef _WIN32
#ifndef WIN32
#include <netinet/in.h>
#include <sys/socket.h>
#endif
#include <iostream>
#include <iomanip>
#ifdef _WIN32
#ifdef _WINDOWS
#include <io.h>
#endif
#include "../common/timer.h"
#include "../common/seperator.h"
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#define snprintf _snprintf
@@ -73,7 +73,7 @@ void CoutTimestamp(bool ms) {
int32 filesize(FILE* fp) {
#ifdef _WIN32
#ifdef _WINDOWS
return _filelength(_fileno(fp));
#else
struct stat file_stat;
@@ -88,7 +88,7 @@ int32 filesize(FILE* fp) {
}
uint32 ResolveIP(const char* hostname, char* errbuf) {
#ifdef _WIN32
#ifdef _WINDOWS
static InitWinsock ws;
#endif
if (errbuf)
@@ -99,14 +99,14 @@ uint32 ResolveIP(const char* hostname, char* errbuf) {
return 0;
}
struct sockaddr_in server_sin;
#ifdef _WIN32
#ifdef _WINDOWS
PHOSTENT phostent = nullptr;
#else
struct hostent *phostent = nullptr;
#endif
server_sin.sin_family = AF_INET;
if ((phostent = gethostbyname(hostname)) == nullptr) {
#ifdef _WIN32
#ifdef _WINDOWS
if (errbuf)
snprintf(errbuf, ERRBUF_SIZE, "Unable to get the host name. Error: %i", WSAGetLastError());
#else
@@ -115,7 +115,7 @@ uint32 ResolveIP(const char* hostname, char* errbuf) {
#endif
return 0;
}
#ifdef _WIN32
#ifdef _WINDOWS
memcpy ((char FAR *)&(server_sin.sin_addr), phostent->h_addr, phostent->h_length);
#else
memcpy ((char*)&(server_sin.sin_addr), phostent->h_addr, phostent->h_length);
@@ -136,7 +136,7 @@ bool ParseAddress(const char* iAddress, uint32* oIP, uint16* oPort, char* errbuf
return false;
}
#ifdef _WIN32
#ifdef _WINDOWS
InitWinsock::InitWinsock() {
WORD version = MAKEWORD (1,1);
WSADATA wsadata;
@@ -157,7 +157,7 @@ const char * itoa(int num) {
return temp;
}
#ifndef _WIN32
#ifndef WIN32
const char * itoa(int num, char* a,int b) {
static char temp[_ITOA_BUFLEN];
memset(temp,0,_ITOA_BUFLEN);
+1 -1
View File
@@ -77,7 +77,7 @@ uint32 Catch22(uint32 mask);
#define _ITOA_BUFLEN 25
const char *itoa(int num); //not thread safe
#ifndef _WIN32
#ifndef _WINDOWS
const char *itoa(int num, char* a,int b);
#endif
+7 -7
View File
@@ -25,7 +25,7 @@
#endif
#ifdef _WIN32
#ifdef _WINDOWS
bool IsTryLockSupported();
bool TrylockSupported = IsTryLockSupported();
@@ -69,7 +69,7 @@ Mutex::Mutex() {
#if DEBUG_MUTEX_CLASS >= 7
std::cout << "Constructing Mutex" << std::endl;
#endif
#ifdef _WIN32
#ifdef _WINDOWS
InitializeCriticalSection(&CSMutex);
#else
pthread_mutexattr_t attr;
@@ -85,7 +85,7 @@ Mutex::Mutex() {
}
Mutex::~Mutex() {
#ifdef _WIN32
#ifdef _WINDOWS
DeleteCriticalSection(&CSMutex);
#else
#endif
@@ -95,14 +95,14 @@ void Mutex::lock() {
#if DEBUG_MUTEX_CLASS >= 5
if (!trylock()) {
std::cout << "Locking Mutex: Having to wait" << std::endl;
#ifdef _WIN32
#ifdef _WINDOWS
EnterCriticalSection(&CSMutex);
#else
pthread_mutex_lock(&CSMutex);
#endif
}
#else
#ifdef _WIN32
#ifdef _WINDOWS
EnterCriticalSection(&CSMutex);
#else
pthread_mutex_lock(&CSMutex);
@@ -111,7 +111,7 @@ void Mutex::lock() {
}
bool Mutex::trylock() {
#ifdef _WIN32
#ifdef _WINDOWS
#if(_WIN32_WINNT >= 0x0400)
if (TrylockSupported)
return TryEnterCriticalSection(&CSMutex);
@@ -129,7 +129,7 @@ bool Mutex::trylock() {
}
void Mutex::unlock() {
#ifdef _WIN32
#ifdef _WINDOWS
LeaveCriticalSection(&CSMutex);
#else
pthread_mutex_unlock(&CSMutex);
+2 -2
View File
@@ -17,7 +17,7 @@
*/
#ifndef MYMUTEX_H
#define MYMUTEX_H
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#else
@@ -36,7 +36,7 @@ public:
bool trylock();
protected:
private:
#if defined _WIN32
#if defined WIN32 || defined WIN64
CRITICAL_SECTION CSMutex;
#else
pthread_mutex_t CSMutex;
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef MYSQL_REQUEST_RESULT_H
#define MYSQL_REQUEST_RESULT_H
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#endif
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef MYSQL_REQUEST_ROW_H
#define MYSQL_REQUEST_ROW_H
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#endif
+2 -2
View File
@@ -13,7 +13,7 @@ EQ::Net::DaybreakConnectionManager::DaybreakConnectionManager()
memset(&m_timer, 0, sizeof(uv_timer_t));
memset(&m_socket, 0, sizeof(uv_udp_t));
Attach(EQ::EventLoop::GetDefault().Handle());
Attach(EQ::EventLoop::Get().Handle());
}
EQ::Net::DaybreakConnectionManager::DaybreakConnectionManager(const DaybreakConnectionManagerOptions &opts)
@@ -23,7 +23,7 @@ EQ::Net::DaybreakConnectionManager::DaybreakConnectionManager(const DaybreakConn
memset(&m_timer, 0, sizeof(uv_timer_t));
memset(&m_socket, 0, sizeof(uv_udp_t));
Attach(EQ::EventLoop::GetDefault().Handle());
Attach(EQ::EventLoop::Get().Handle());
}
EQ::Net::DaybreakConnectionManager::~DaybreakConnectionManager()
+1 -1
View File
@@ -257,7 +257,7 @@ namespace EQ
resend_delay_min = 150;
resend_delay_max = 5000;
connect_delay_ms = 500;
stale_connection_ms = 60000;
stale_connection_ms = 30000;
connect_stale_ms = 5000;
crc_length = 2;
max_packet_size = 512;
+1 -1
View File
@@ -21,7 +21,7 @@ namespace EQ
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
auto loop = EQ::EventLoop::GetDefault().Handle();
auto loop = EQ::EventLoop::Get().Handle();
uv_getaddrinfo_t *resolver = new uv_getaddrinfo_t();
memset(resolver, 0, sizeof(uv_getaddrinfo_t));
auto port_str = std::to_string(port);
+279 -6
View File
@@ -1,16 +1,279 @@
#include "packet.h"
#include <fmt/format.h>
#include "endian.h"
#include <cctype>
#include <fmt/format.h>
bool EQ::Net::StaticPacket::Resize(size_t new_size)
void EQ::Net::Packet::PutInt8(size_t offset, int8_t value)
{
if (new_size > _max_len) {
return false;
if (Length() < offset + 1) {
if (!Resize(offset + 1)) {
throw std::out_of_range("Packet::PutInt8(), could not resize packet and would of written past the end.");
}
}
_len = new_size;
return true;
*(int8_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutInt16(size_t offset, int16_t value)
{
if (Length() < offset + 2) {
if (!Resize(offset + 2)) {
throw std::out_of_range("Packet::PutInt16(), could not resize packet and would of written past the end.");
}
}
*(int16_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutInt32(size_t offset, int32_t value)
{
if (Length() < offset + 4) {
if (!Resize(offset + 4)) {
throw std::out_of_range("Packet::PutInt32(), could not resize packet and would of written past the end.");
}
}
*(int32_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutInt64(size_t offset, int64_t value)
{
if (Length() < offset + 8) {
if (!Resize(offset + 8)) {
throw std::out_of_range("Packet::PutInt64(), could not resize packet and would of written past the end.");
}
}
*(int64_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutUInt8(size_t offset, uint8_t value)
{
if (Length() < offset + 1) {
if (!Resize(offset + 1)) {
throw std::out_of_range("Packet::PutUInt8(), could not resize packet and would of written past the end.");
}
}
*(uint8_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutUInt16(size_t offset, uint16_t value)
{
if (Length() < offset + 2) {
if (!Resize(offset + 2)) {
throw std::out_of_range("Packet::PutUInt16(), could not resize packet and would of written past the end.");
}
}
*(uint16_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutUInt32(size_t offset, uint32_t value)
{
if (Length() < offset + 4) {
if (!Resize(offset + 4)) {
throw std::out_of_range("Packet::PutUInt32(), could not resize packet and would of written past the end.");
}
}
*(uint32_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutUInt64(size_t offset, uint64_t value)
{
if (Length() < offset + 8) {
if (!Resize(offset + 8)) {
throw std::out_of_range("Packet::PutUInt64(), could not resize packet and would of written past the end.");
}
}
*(uint64_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutFloat(size_t offset, float value)
{
if (Length() < offset + 4) {
if (!Resize(offset + 4)) {
throw std::out_of_range("Packet::PutFloat(), could not resize packet and would of written past the end.");
}
}
*(float*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutDouble(size_t offset, double value)
{
if (Length() < offset + 8) {
if (!Resize(offset + 8)) {
throw std::out_of_range("Packet::PutDouble(), could not resize packet and would of written past the end.");
}
}
*(double*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutString(size_t offset, const std::string &str)
{
if (Length() < offset + str.length()) {
if (!Resize(offset + str.length())) {
throw std::out_of_range("Packet::PutString(), could not resize packet and would of written past the end.");
}
}
memcpy(((char*)Data() + offset), str.c_str(), str.length());
}
void EQ::Net::Packet::PutCString(size_t offset, const char *str)
{
size_t sz = strlen(str);
if (Length() < offset + sz + 1) {
if (!Resize(offset + sz + 1)) {
throw std::out_of_range("Packet::PutCString(), could not resize packet and would of written past the end.");
}
}
memcpy(((char*)Data() + offset), str, sz);
*((char*)Data() + offset + sz) = 0;
}
void EQ::Net::Packet::PutPacket(size_t offset, const Packet &p)
{
if (p.Length() == 0) {
return;
}
if (Length() < offset + p.Length()) {
if (!Resize(offset + p.Length())) {
throw std::out_of_range("Packet::PutPacket(), could not resize packet and would of written past the end.");
}
}
memcpy(((char*)Data() + offset), p.Data(), p.Length());
}
void EQ::Net::Packet::PutData(size_t offset, void *data, size_t length)
{
if (length == 0) {
return;
}
if (Length() < offset + length) {
if (!Resize(offset + length)) {
throw std::out_of_range("Packet::PutData(), could not resize packet and would of written past the end.");
}
}
memcpy(((char*)Data() + offset), data, length);
}
int8_t EQ::Net::Packet::GetInt8(size_t offset) const
{
if (Length() < offset + 1) {
throw std::out_of_range("Packet read out of range.");
}
return *(int8_t*)((char*)Data() + offset);
}
int16_t EQ::Net::Packet::GetInt16(size_t offset) const
{
if (Length() < offset + 2) {
throw std::out_of_range("Packet read out of range.");
}
return *(int16_t*)((char*)Data() + offset);
}
int32_t EQ::Net::Packet::GetInt32(size_t offset) const
{
if (Length() < offset + 4) {
throw std::out_of_range("Packet read out of range.");
}
return *(int32_t*)((char*)Data() + offset);
}
int64_t EQ::Net::Packet::GetInt64(size_t offset) const
{
if (Length() < offset + 8) {
throw std::out_of_range("Packet read out of range.");
}
return *(int64_t*)((char*)Data() + offset);
}
uint8_t EQ::Net::Packet::GetUInt8(size_t offset) const
{
if (Length() < offset + 1) {
throw std::out_of_range("Packet read out of range.");
}
return *(uint8_t*)((char*)Data() + offset);
}
uint16_t EQ::Net::Packet::GetUInt16(size_t offset) const
{
if (Length() < offset + 2) {
throw std::out_of_range("Packet read out of range.");
}
return *(uint16_t*)((char*)Data() + offset);
}
uint32_t EQ::Net::Packet::GetUInt32(size_t offset) const
{
if (Length() < offset + 4) {
throw std::out_of_range("Packet read out of range.");
}
return *(uint32_t*)((char*)Data() + offset);
}
uint64_t EQ::Net::Packet::GetUInt64(size_t offset) const
{
if (Length() < offset + 8) {
throw std::out_of_range("Packet read out of range.");
}
return *(uint64_t*)((char*)Data() + offset);
}
float EQ::Net::Packet::GetFloat(size_t offset) const
{
if (Length() < offset + 4) {
throw std::out_of_range("Packet read out of range.");
}
return *(float*)((char*)Data() + offset);
}
double EQ::Net::Packet::GetDouble(size_t offset) const
{
if (Length() < offset + 8) {
throw std::out_of_range("Packet read out of range.");
}
return *(double*)((char*)Data() + offset);
}
std::string EQ::Net::Packet::GetString(size_t offset, size_t length) const
{
if (Length() < offset + length) {
throw std::out_of_range("Packet read out of range.");
}
return std::string((char*)Data() + offset, (char*)Data() + offset + length);
}
std::string EQ::Net::Packet::GetCString(size_t offset) const
{
if (Length() < offset + 1) {
throw std::out_of_range("Packet read out of range.");
}
char *str = ((char*)Data() + offset);
return std::string(str);
}
char ToSafePrint(unsigned char in) {
@@ -79,3 +342,13 @@ std::string EQ::Net::Packet::ToString(size_t line_length) const
return ret;
}
bool EQ::Net::StaticPacket::Resize(size_t new_size)
{
if (new_size > m_max_data_length) {
return false;
}
m_data_length = new_size;
return true;
}
+67 -691
View File
@@ -13,7 +13,8 @@ namespace EQ {
class Packet
{
public:
Packet() = default;
Packet() : m_stream(std::ios::out | std::ios::binary) { }
virtual ~Packet() { }
virtual const void *Data() const = 0;
virtual void *Data() = 0;
@@ -23,617 +24,6 @@ namespace EQ {
virtual bool Resize(size_t new_size) = 0;
virtual void Reserve(size_t new_size) = 0;
std::string ToString() const;
std::string ToString(size_t line_length) const;
void SetWritePos(size_t offset) { _wpos = offset; }
void SetReadPos(size_t offset) { _rpos = offset; }
//Position Independent Output Interface
void PutInt8(size_t offset, int8_t value) {
if (Length() < offset + sizeof(int8_t)) {
if (!Resize(offset + sizeof(int8_t))) {
throw std::out_of_range("Packet::PutInt8(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<int8_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(int8_t);
}
void PutInt16(size_t offset, int16_t value) {
if (Length() < offset + sizeof(int16_t)) {
if (!Resize(offset + sizeof(int16_t))) {
throw std::out_of_range("Packet::PutInt16(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<int16_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(int16_t);
}
void PutInt32(size_t offset, int32_t value) {
if (Length() < offset + sizeof(int32_t)) {
if (!Resize(offset + sizeof(int32_t))) {
throw std::out_of_range("Packet::PutInt32(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<int32_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(int32_t);
}
void PutInt64(size_t offset, int64_t value) {
if (Length() < offset + sizeof(int64_t)) {
if (!Resize(offset + sizeof(int64_t))) {
throw std::out_of_range("Packet::PutInt64(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<int64_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(int64_t);
}
void PutUInt8(size_t offset, uint8_t value) {
if (Length() < offset + sizeof(uint8_t)) {
if (!Resize(offset + sizeof(uint8_t))) {
throw std::out_of_range("Packet::PutUInt8(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<uint8_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(uint8_t);
}
void PutUInt16(size_t offset, uint16_t value) {
if (Length() < offset + sizeof(uint16_t)) {
if (!Resize(offset + sizeof(uint16_t))) {
throw std::out_of_range("Packet::PutUInt16(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<uint16_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(uint16_t);
}
void PutUInt32(size_t offset, uint32_t value) {
if (Length() < offset + sizeof(uint32_t)) {
if (!Resize(offset + sizeof(uint32_t))) {
throw std::out_of_range("Packet::PutUInt32(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<uint32_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(uint32_t);
}
void PutUInt64(size_t offset, uint64_t value) {
if (Length() < offset + sizeof(uint64_t)) {
if (!Resize(offset + sizeof(uint64_t))) {
throw std::out_of_range("Packet::PutUInt64(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<uint64_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(uint64_t);
}
void PutFloat(size_t offset, float value) {
if (Length() < offset + sizeof(float)) {
if (!Resize(offset + sizeof(float))) {
throw std::out_of_range("Packet::PutFloat(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<float*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(float);
}
void PutDouble(size_t offset, double value) {
if (Length() < offset + sizeof(double)) {
if (!Resize(offset + sizeof(double))) {
throw std::out_of_range("Packet::PutDouble(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<double*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(double);
}
void PutString(size_t offset, const std::string &str) {
if (Length() < offset + str.length()) {
if (!Resize(offset + str.length())) {
throw std::out_of_range("Packet::PutString(), could not resize packet and would of written past the end.");
}
}
std::memcpy((static_cast<char*>(Data()) + offset), str.c_str(), str.length());
_wpos = offset + str.length();
}
void PutCString(size_t offset, const char *str) {
size_t sz = strlen(str);
if (Length() < offset + sz + sizeof(int8_t)) {
if (!Resize(offset + sz + sizeof(int8_t))) {
throw std::out_of_range("Packet::PutCString(), could not resize packet and would of written past the end.");
}
}
std::memcpy((static_cast<char*>(Data()) + offset), str, sz);
*(static_cast<char*>(Data()) + offset + sz) = 0;
_wpos = offset + sz + sizeof(int8_t);
}
void PutPacket(size_t offset, const Packet &p) {
if (p.Length() == 0) {
return;
}
if (Length() < offset + p.Length()) {
if (!Resize(offset + p.Length())) {
throw std::out_of_range("Packet::PutPacket(), could not resize packet and would of written past the end.");
}
}
std::memcpy((static_cast<char*>(Data()) + offset), p.Data(), p.Length());
_wpos = offset + p.Length();
}
void PutData(size_t offset, void *data, size_t length) {
if (length == 0) {
return;
}
if (Length() < offset + length) {
if (!Resize(offset + length)) {
throw std::out_of_range("Packet::PutData(), could not resize packet and would of written past the end.");
}
}
std::memcpy((static_cast<char*>(Data()) + offset), data, length);
_wpos = offset + length;
}
//Position Dependent Output Interface
void PutInt8(int8_t value) {
PutInt8(_wpos, value);
}
void PutInt16(int16_t value) {
PutInt16(_wpos, value);
}
void PutInt32(int32_t value) {
PutInt32(_wpos, value);
}
void PutInt64(int64_t value) {
PutInt64(_wpos, value);
}
void PutUInt8(uint8_t value) {
PutUInt8(_wpos, value);
}
void PutUInt16(uint16_t value) {
PutUInt16(_wpos, value);
}
void PutUInt32(uint32_t value) {
PutUInt32(_wpos, value);
}
void PutUInt64(uint64_t value) {
PutUInt64(_wpos, value);
}
void PutFloat(float value) {
PutFloat(_wpos, value);
}
void PutDouble(double value) {
PutDouble(_wpos, value);
}
void PutString(const std::string &str) {
PutString(_wpos, str);
}
void PutCString(const char *str) {
PutCString(_wpos, str);
}
void PutPacket(const Packet &p) {
PutPacket(_wpos, p);
}
void PutData(void *data, size_t length) {
PutData(_wpos, data, length);
}
//Position Independent Input Interface
int8_t GetInt8(size_t offset) const {
if (Length() < offset + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const int8_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
int16_t GetInt16(size_t offset) const {
if (Length() < offset + sizeof(int16_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const int16_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
int32_t GetInt32(size_t offset) const {
if (Length() < offset + sizeof(int32_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const int32_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
int64_t GetInt64(size_t offset) const {
if (Length() < offset + sizeof(int64_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const int64_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
uint8_t GetUInt8(size_t offset) const {
if (Length() < offset + sizeof(uint8_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const uint8_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
uint16_t GetUInt16(size_t offset) const {
if (Length() < offset + sizeof(uint16_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const uint16_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
uint32_t GetUInt32(size_t offset) const {
if (Length() < offset + sizeof(uint32_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const uint32_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
uint64_t GetUInt64(size_t offset) const {
if (Length() < offset + sizeof(uint64_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const uint64_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
float GetFloat(size_t offset) const {
if (Length() < offset + sizeof(float)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const float*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
double GetDouble(size_t offset) const {
if (Length() < offset + sizeof(double)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const double*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
std::string GetString(size_t offset, size_t length) const {
if (Length() < offset + length) {
throw std::out_of_range("Packet read out of range.");
}
return std::string(reinterpret_cast<const int8_t*>(Data()) + offset, reinterpret_cast<const int8_t*>(Data()) + offset + length);
}
std::string GetCString(size_t offset) const {
if (Length() < offset) {
throw std::out_of_range("Packet read out of range.");
}
auto sz = strlen(static_cast<const char*>(Data()));
if (Length() < offset + sz + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
const char *str = reinterpret_cast<const char*>(reinterpret_cast<const int8_t*>(Data()) + offset);
return std::string(str);
}
//Position Dependent Input Interface
int8_t GetInt8() {
auto offset = _rpos;
if (Length() < offset + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(int8_t);
return *reinterpret_cast<int8_t*>(static_cast<char*>(Data()) + offset);
}
int16_t GetInt16() {
auto offset = _rpos;
if (Length() < offset + sizeof(int16_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(int16_t);
return *reinterpret_cast<int16_t*>(static_cast<char*>(Data()) + offset);
}
int32_t GetInt32() {
auto offset = _rpos;
if (Length() < offset + sizeof(int32_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(int32_t);
return *reinterpret_cast<int32_t*>(static_cast<char*>(Data()) + offset);
}
int64_t GetInt64() {
auto offset = _rpos;
if (Length() < offset + sizeof(int64_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(int64_t);
return *reinterpret_cast<int64_t*>(static_cast<char*>(Data()) + offset);
}
uint8_t GetUInt8() {
auto offset = _rpos;
if (Length() < offset + sizeof(uint8_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(uint8_t);
return *reinterpret_cast<uint8_t*>(static_cast<char*>(Data()) + offset);
}
uint16_t GetUInt16() {
auto offset = _rpos;
if (Length() < offset + sizeof(uint16_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(uint16_t);
return *reinterpret_cast<uint16_t*>(static_cast<char*>(Data()) + offset);
}
uint32_t GetUInt32() {
auto offset = _rpos;
if (Length() < offset + sizeof(uint32_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(uint32_t);
return *reinterpret_cast<uint32_t*>(static_cast<char*>(Data()) + offset);
}
uint64_t GetUInt64() {
auto offset = _rpos;
if (Length() < offset + sizeof(uint64_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(uint64_t);
return *reinterpret_cast<uint64_t*>(static_cast<char*>(Data()) + offset);
}
float GetFloat() {
auto offset = _rpos;
if (Length() < offset + sizeof(float)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(float);
return *reinterpret_cast<float*>(static_cast<char*>(Data()) + offset);
}
double GetDouble() {
auto offset = _rpos;
if (Length() < offset + sizeof(double)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(double);
return *reinterpret_cast<double*>(static_cast<char*>(Data()) + offset);
}
std::string GetString(size_t length) {
auto offset = _rpos;
if (Length() < offset + length) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + length;
return std::string(static_cast<char*>(Data()) + offset, static_cast<char*>(Data()) + offset + length);
}
std::string GetCString() {
auto offset = _rpos;
if (Length() < offset + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
auto sz = strlen(static_cast<const char*>(Data()));
if (Length() < offset + sz + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sz + sizeof(int8_t);
char *str = (static_cast<char*>(Data()) + offset);
return std::string(str);
}
int8_t& operator[](size_t offset) {
if (Length() < offset + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<int8_t*>(static_cast<char*>(Data()) + offset);
}
const int8_t& operator[](size_t offset) const {
if (Length() < offset + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const int8_t*>(static_cast<const char*>(Data()) + offset);
}
//Stream Output Interface
Packet &operator<<(int8_t v) {
PutInt8(v);
return *this;
}
Packet &operator<<(int16_t v) {
PutInt16(v);
return *this;
}
Packet &operator<<(int32_t v) {
PutInt32(v);
return *this;
}
Packet &operator<<(int64_t v) {
PutInt64(v);
return *this;
}
Packet &operator<<(uint8_t v) {
PutUInt8(v);
return *this;
}
Packet &operator<<(uint16_t v) {
PutUInt16(v);
return *this;
}
Packet &operator<<(uint32_t v) {
PutUInt32(v);
return *this;
}
Packet &operator<<(uint64_t v) {
PutUInt64(v);
return *this;
}
Packet &operator<<(float v) {
PutFloat(v);
return *this;
}
Packet &operator<<(double v) {
PutDouble(v);
return *this;
}
Packet &operator<<(const std::string &v) {
PutString(v.data());
return *this;
}
Packet &operator<<(const char *v) {
PutCString(v);
return *this;
}
Packet &operator<<(const Packet &v) {
PutPacket(v);
return *this;
}
//Stream Input Interface
Packet &operator>>(int8_t &v) {
v = GetInt8();
return *this;
}
Packet &operator>>(int16_t &v) {
v = GetInt16();
return *this;
}
Packet &operator>>(int32_t &v) {
v = GetInt32();
return *this;
}
Packet &operator>>(int64_t &v) {
v = GetInt64();
return *this;
}
Packet &operator>>(uint8_t &v) {
v = GetUInt8();
return *this;
}
Packet &operator>>(uint16_t &v) {
v = GetUInt16();
return *this;
}
Packet &operator>>(uint32_t &v) {
v = GetUInt32();
return *this;
}
Packet &operator>>(uint64_t &v) {
v = GetUInt64();
return *this;
}
Packet &operator>>(float &v) {
v = GetFloat();
return *this;
}
Packet &operator>>(double &v) {
v = GetDouble();
return *this;
}
Packet &operator>>(std::string &v) {
v = GetCString();
return *this;
}
// Seriliazation
template<typename T>
T GetSerialize(size_t offset) const
{
@@ -646,12 +36,11 @@ namespace EQ {
template<typename T>
void PutSerialize(size_t offset, const T &value) {
std::stringstream stream;
cereal::BinaryOutputArchive output(stream);
m_stream.clear();
cereal::BinaryOutputArchive output(m_stream);
output(value);
auto str = stream.str();
auto str = m_stream.str();
if (Length() < offset + str.length()) {
if (!Resize(offset + str.length())) {
throw std::out_of_range("Packet::PutSerialize(), could not resize packet and would of written past the end.");
@@ -660,95 +49,82 @@ namespace EQ {
memcpy((char*)Data() + offset, &str[0], str.length());
}
void PutInt8(size_t offset, int8_t value);
void PutInt16(size_t offset, int16_t value);
void PutInt32(size_t offset, int32_t value);
void PutInt64(size_t offset, int64_t value);
void PutUInt8(size_t offset, uint8_t value);
void PutUInt16(size_t offset, uint16_t value);
void PutUInt32(size_t offset, uint32_t value);
void PutUInt64(size_t offset, uint64_t value);
void PutFloat(size_t offset, float value);
void PutDouble(size_t offset, double value);
void PutString(size_t offset, const std::string &str);
void PutCString(size_t offset, const char *str);
void PutPacket(size_t offset, const Packet &p);
void PutData(size_t offset, void *data, size_t length);
int8_t GetInt8(size_t offset) const;
int16_t GetInt16(size_t offset) const;
int32_t GetInt32(size_t offset) const;
int64_t GetInt64(size_t offset) const;
uint8_t GetUInt8(size_t offset) const;
uint16_t GetUInt16(size_t offset) const;
uint32_t GetUInt32(size_t offset) const;
uint64_t GetUInt64(size_t offset) const;
float GetFloat(size_t offset) const;
double GetDouble(size_t offset) const;
std::string GetString(size_t offset, size_t length) const;
std::string GetCString(size_t offset) const;
std::string ToString() const;
std::string ToString(size_t line_length) const;
protected:
size_t _rpos{ 0 };
size_t _wpos{ 0 };
std::stringstream m_stream;
};
class StaticPacket : public Packet
{
public:
StaticPacket(void *data, size_t len) : _data(data), _len(len), _max_len(len) {
}
StaticPacket(void *data, size_t size) { m_data = data; m_data_length = size; m_max_data_length = size; }
virtual ~StaticPacket() { }
StaticPacket(const StaticPacket &o) { m_data = o.m_data; m_data_length = o.m_data_length; }
StaticPacket& operator=(const StaticPacket &o) { m_data = o.m_data; m_data_length = o.m_data_length; return *this; }
StaticPacket(StaticPacket &&o) { m_data = o.m_data; m_data_length = o.m_data_length; }
StaticPacket(const StaticPacket &o) : _data(o._data), _len(o._len), _max_len(o._max_len) {
_rpos = o._rpos;
_wpos = o._wpos;
}
StaticPacket& operator=(const StaticPacket& o) {
_data = o._data;
_len = o._len;
_max_len = o._max_len;
_rpos = o._rpos;
_wpos = o._wpos;
return *this;
}
StaticPacket(StaticPacket &&o) noexcept : _data(o._data), _len(o._len), _max_len(o._max_len) {
_rpos = o._rpos;
_wpos = o._wpos;
}
const void *Data() const override { return _data; }
void *Data() override { return _data; }
size_t Length() const override { return _len; }
size_t Length() override { return _len; }
bool Clear() override { return false; }
bool Resize(size_t new_size) override;
void Reserve(size_t new_size) override { }
virtual const void *Data() const { return m_data; }
virtual void *Data() { return m_data; }
virtual size_t Length() const { return m_data_length; }
virtual size_t Length() { return m_data_length; }
virtual bool Clear() { return false; }
virtual bool Resize(size_t new_size);
virtual void Reserve(size_t new_size) { }
protected:
void *_data;
size_t _len;
size_t _max_len;
void *m_data;
size_t m_data_length;
size_t m_max_data_length;
};
class DynamicPacket : public Packet
{
public:
const static size_t DefaultSize = 4096;
DynamicPacket() {
_data.reserve(DefaultSize);
}
DynamicPacket(size_t size) {
_data.reserve(size);
}
DynamicPacket(const DynamicPacket& o) : _data(o._data) {
_rpos = o._rpos;
_wpos = o._wpos;
}
DynamicPacket& operator=(const DynamicPacket& o) {
_data = o._data;
_rpos = o._rpos;
_wpos = o._wpos;
}
DynamicPacket(DynamicPacket &&o) noexcept : _data(o.MoveData()) {
_rpos = o._rpos;
_wpos = o._wpos;
}
std::vector<int8_t>&& MoveData() {
_rpos = 0;
_wpos = 0;
return std::move(_data);
}
const void *Data() const override { return _data.data(); }
void *Data() override { return _data.data(); }
size_t Length() const override { return _data.size(); }
size_t Length() override { return _data.size(); }
bool Clear() override { _data.clear(); return true; }
bool Resize(size_t new_size) override { _data.resize(new_size); return true; }
void Reserve(size_t new_size) override { _data.reserve(new_size); }
DynamicPacket() { }
virtual ~DynamicPacket() { }
DynamicPacket(DynamicPacket &&o) { m_data = std::move(o.m_data); }
DynamicPacket(const DynamicPacket &o) { m_data = o.m_data; }
DynamicPacket& operator=(const DynamicPacket &o) { m_data = o.m_data; return *this; }
virtual const void *Data() const { return &m_data[0]; }
virtual void *Data() { return &m_data[0]; }
virtual size_t Length() const { return m_data.size(); }
virtual size_t Length() { return m_data.size(); }
virtual bool Clear() { m_data.clear(); return true; }
virtual bool Resize(size_t new_size) { m_data.resize(new_size, 0); return true; }
virtual void Reserve(size_t new_size) { m_data.reserve(new_size); }
protected:
std::vector<int8_t> _data;
std::vector<char> m_data;
};
} // namespace Net
} // namespace EQ
}
}
+2 -2
View File
@@ -23,7 +23,7 @@ void EQ::Net::TCPConnection::Connect(const std::string &addr, int port, bool ipv
std::function<void(std::shared_ptr<EQ::Net::TCPConnection>)> cb;
};
auto loop = EQ::EventLoop::GetDefault().Handle();
auto loop = EQ::EventLoop::Get().Handle();
uv_tcp_t *socket = new uv_tcp_t;
memset(socket, 0, sizeof(uv_tcp_t));
uv_tcp_init(loop, socket);
@@ -142,7 +142,7 @@ void EQ::Net::TCPConnection::Write(const char *data, size_t count)
WriteBaton *baton = new WriteBaton;
baton->connection = this;
baton->buffer = new char[count];
baton->buffer = new char[count];;
uv_write_t *write_req = new uv_write_t;
memset(write_req, 0, sizeof(uv_write_t));
+2 -2
View File
@@ -32,7 +32,7 @@ void EQ::Net::TCPServer::Listen(const std::string &addr, int port, bool ipv6, st
m_on_new_connection = cb;
auto loop = EQ::EventLoop::GetDefault().Handle();
auto loop = EQ::EventLoop::Get().Handle();
m_socket = new uv_tcp_t;
memset(m_socket, 0, sizeof(uv_tcp_t));
uv_tcp_init(loop, m_socket);
@@ -53,7 +53,7 @@ void EQ::Net::TCPServer::Listen(const std::string &addr, int port, bool ipv6, st
return;
}
auto loop = EQ::EventLoop::GetDefault().Handle();
auto loop = EQ::EventLoop::Get().Handle();
uv_tcp_t *client = new uv_tcp_t;
memset(client, 0, sizeof(uv_tcp_t));
uv_tcp_init(loop, client);
+1 -1
View File
@@ -29,7 +29,7 @@
//#endif
#include <string.h>
#ifdef _WIN32
#ifdef _WINDOWS
#define snprintf _snprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
+1 -1
View File
@@ -23,7 +23,7 @@
#include "packet_dump.h"
#include "packet_functions.h"
#ifndef _WIN32
#ifndef WIN32
#include <netinet/in.h>
#endif
-6
View File
@@ -1116,10 +1116,7 @@ namespace SoF
}
OUT(deity);
OUT(intoxication);
OUT_array(spellSlotRefresh, spells::SPELL_GEM_COUNT);
eq->spellSlotRefresh[9] = 0; // 10th slot is not valid in this release
OUT(abilitySlotRefresh);
OUT(points); // Relocation Test
// OUT(unknown0166[4]);
@@ -1180,10 +1177,7 @@ namespace SoF
}
// OUT(unknown4184[128]);
OUT_array(mem_spells, spells::SPELL_GEM_COUNT);
eq->mem_spells[9] = 0xFFFFFFFFU; // 10th slot is not valid in this release
// OUT(unknown04396[32]);
OUT(platinum);
OUT(gold);
-4
View File
@@ -328,11 +328,7 @@ namespace SoF
const int SPELL_ID_MAX = 15999;
const int SPELLBOOK_SIZE = 480;
// Be careful not to confuse these two..SoF disc release has a special requirement...
// - The number of available spell gems HAS NOT increased from 9 at this point
// - The profile allocation HAS increased to 10 at this point
const int SPELL_GEM_COUNT = static_cast<uint32>(CastingSlot::MaxGems);
const int SPELL_GEM_PROFILE_SIZE = 10; // special case declaration
const int LONG_BUFFS = 25;
const int SHORT_BUFFS = 15;
+3 -3
View File
@@ -885,7 +885,7 @@ struct PlayerProfile_Struct //23576 Octets
/*00060*/ BindStruct binds[5]; // Bind points (primary is first)
/*00160*/ uint32 deity; // deity
/*00164*/ uint32 intoxication; // Alcohol level (in ticks till sober?)
/*00168*/ uint32 spellSlotRefresh[spells::SPELL_GEM_PROFILE_SIZE]; // Refresh time (millis) - 4 Octets Each
/*00168*/ uint32 spellSlotRefresh[spells::SPELL_GEM_COUNT]; // Refresh time (millis) - 4 Octets Each
/*00208*/ uint32 abilitySlotRefresh;
/*00212*/ uint8 haircolor; // Player hair color
/*00213*/ uint8 beardcolor; // Player beard color
@@ -912,7 +912,7 @@ struct PlayerProfile_Struct //23576 Octets
/*04173*/ uint8 unknown02264[147]; // was [139]
/*04312*/ uint32 spell_book[spells::SPELLBOOK_SIZE]; // List of the Spells in spellbook 480 = 60 pages
/*06232*/ uint8 unknown4184[128]; // was [136]
/*06396*/ uint32 mem_spells[spells::SPELL_GEM_PROFILE_SIZE]; // List of spells memorized
/*06396*/ uint32 mem_spells[spells::SPELL_GEM_COUNT]; // List of spells memorized
/*06436*/ uint8 unknown04396[28]; //#### uint8 unknown04396[32]; in Titanium ####[28]
/*06464*/ uint32 platinum; // Platinum Pieces on player
/*06468*/ uint32 gold; // Gold Pieces on player
@@ -3768,7 +3768,7 @@ struct AnnoyingZoneUnknown_Struct {
};
struct LoadSpellSet_Struct {
uint32 spell[spells::SPELL_GEM_PROFILE_SIZE];
uint32 spell[spells::SPELL_GEM_COUNT];
uint32 unknown;
};
+8 -8
View File
@@ -22,7 +22,7 @@
#include "global_define.h"
#include "types.h"
#include "proc_launcher.h"
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#else
#include <sys/types.h>
@@ -39,7 +39,7 @@
ProcLauncher ProcLauncher::s_launcher;
#ifdef _WIN32
#ifdef _WINDOWS
const ProcLauncher::ProcRef ProcLauncher::ProcError = 0xFFFFFFFF;
#else
const ProcLauncher::ProcRef ProcLauncher::ProcError = -1;
@@ -47,7 +47,7 @@ const ProcLauncher::ProcRef ProcLauncher::ProcError = -1;
ProcLauncher::ProcLauncher()
{
#ifndef _WIN32
#ifndef WIN32
if(signal(SIGCHLD, ProcLauncher::HandleSigChild) == SIG_ERR)
fprintf(stderr, "Unable to register child signal handler. Thats bad.");
m_signalCount = 0;
@@ -55,7 +55,7 @@ ProcLauncher::ProcLauncher()
}
void ProcLauncher::Process() {
#ifdef _WIN32
#ifdef _WINDOWS
std::map<ProcRef, Spec *>::iterator cur, end, tmp;
cur = m_running.begin();
end = m_running.end();
@@ -112,7 +112,7 @@ void ProcLauncher::ProcessTerminated(std::map<ProcRef, Spec *>::iterator &it) {
if(it->second->handler != nullptr)
it->second->handler->OnTerminate(it->first, it->second);
#ifdef _WIN32
#ifdef _WINDOWS
CloseHandle(it->second->proc_info.hProcess);
#else //!WIN32
#endif //!WIN32
@@ -125,7 +125,7 @@ ProcLauncher::ProcRef ProcLauncher::Launch(Spec *&to_launch) {
Spec *it = to_launch;
to_launch = nullptr;
#ifdef _WIN32
#ifdef _WINDOWS
STARTUPINFO siStartInfo;
BOOL bFuncRetn = FALSE;
@@ -283,7 +283,7 @@ bool ProcLauncher::Terminate(const ProcRef &proc, bool graceful) {
//we do not remove it from the list until we have been notified
//that they have been terminated.
#ifdef _WIN32
#ifdef _WINDOWS
if(!TerminateProcess(res->second->proc_info.hProcess, 0)) {
return(false);
}
@@ -325,7 +325,7 @@ void ProcLauncher::TerminateAll(bool final) {
}
#ifndef _WIN32
#ifndef WIN32
void ProcLauncher::HandleSigChild(int signum) {
if(signum == SIGCHLD) {
ProcLauncher::get()->m_signalCount++;
+3 -3
View File
@@ -33,7 +33,7 @@ public:
static ProcLauncher *get() { return(&s_launcher); }
static void ProcessInThisThread();
#ifdef _WIN32
#ifdef WIN32
typedef DWORD ProcRef;
static const ProcRef ProcError;
#else
@@ -55,7 +55,7 @@ public:
std::string logFile; //empty = do not redirect output.
protected:
//None of these fields get copied around
#ifdef _WIN32
#ifdef WIN32
PROCESS_INFORMATION proc_info;
#endif
};
@@ -83,7 +83,7 @@ protected:
private:
static ProcLauncher s_launcher;
#ifndef _WIN32
#ifndef WIN32
uint32 m_signalCount;
static void HandleSigChild(int signum);
#endif
+1 -1
View File
@@ -23,7 +23,7 @@
#include "database.h"
#include "string_util.h"
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
int gettimeofday (timeval *tp, ...);
+5 -2
View File
@@ -121,8 +121,11 @@ private:
int m_activeRuleset;
std::string m_activeName;
int32 m_RuleIntValues [_IntRuleCount ];
#ifdef WIN64
uint32 m_RuleIntValues [_IntRuleCount ];
#else
int m_RuleIntValues [_IntRuleCount ];
#endif
float m_RuleRealValues[_RealRuleCount];
uint32 m_RuleBoolValues[_BoolRuleCount];
+1 -1
View File
@@ -77,7 +77,7 @@
#include "classes.h"
#include "spdat.h"
#ifndef _WIN32
#ifndef WIN32
#include <stdlib.h>
#include "unix.h"
#endif
+2 -23
View File
@@ -17,7 +17,7 @@
#include "string_util.h"
#include <algorithm>
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#define snprintf _snprintf
@@ -27,8 +27,6 @@
#else
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#endif
#ifndef va_copy
@@ -121,29 +119,10 @@ std::vector<std::string> SplitString(const std::string &str, char delim) {
while(std::getline(ss, item, delim)) {
ret.push_back(item);
}
return ret;
}
std::string implode(std::string glue, std::vector<std::string> src)
{
if (src.empty()) {
return {};
}
std::ostringstream output;
std::vector<std::string>::iterator src_iter;
for (src_iter = src.begin(); src_iter != src.end(); src_iter++) {
output << *src_iter << glue;
}
std::string final_output = output.str();
final_output.resize (output.str().size () - glue.size());
return final_output;
}
std::string EscapeString(const std::string &s) {
std::string ret;
-1
View File
@@ -30,7 +30,6 @@ const std::string ucfirst(std::string s);
std::vector<std::string> split(std::string str_to_split, char delimiter);
const std::string StringFormat(const char* format, ...);
const std::string vStringFormat(const char* format, va_list args);
std::string implode(std::string glue, std::vector<std::string> src);
std::vector<std::string> SplitString(const std::string &s, char delim);
std::string EscapeString(const char *src, size_t sz);
std::string EscapeString(const std::string &s);
+2 -2
View File
@@ -18,7 +18,7 @@
// Disgrace: for windows compile
#ifndef _WIN32
#ifndef WIN32
#include <sys/time.h>
#else
#include <sys/timeb.h>
@@ -64,7 +64,7 @@ Timer::Timer(uint32 start, uint32 timer, bool iUseAcurateTiming = false) {
}
/* Reimplemented for MSVC - Bounce */
#ifdef _WIN32
#ifdef _WINDOWS
int gettimeofday (timeval *tp, ...)
{
timeb tb;
+1 -1
View File
@@ -22,7 +22,7 @@
#include <chrono>
// Disgrace: for windows compile
#ifdef _WIN32
#ifdef _WINDOWS
#include "global_define.h"
int gettimeofday (timeval *tp, ...);
#endif
+5 -5
View File
@@ -29,7 +29,7 @@ typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
#ifdef _WIN32
#ifdef _WINDOWS
#pragma warning( disable : 4200 )
#endif
@@ -42,7 +42,7 @@ typedef unsigned short ushort;
typedef unsigned char uchar;
typedef const char Const_char; //for perl XS
#ifdef _WIN32
#ifdef _WINDOWS
#if (!defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER < 1900))
#define snprintf _snprintf
#endif
@@ -61,7 +61,7 @@ typedef const char Const_char; //for perl XS
#define H32(i) ((uint32) (i >> 32))
#define L16(i) ((uint16) i)
#ifndef _WIN32
#ifndef WIN32
// More WIN32 compatability
typedef unsigned long DWORD;
typedef unsigned char BYTE;
@@ -79,14 +79,14 @@ typedef const char Const_char; //for perl XS
#endif
#ifdef _WIN32
#ifdef _WINDOWS
#define DLLFUNC extern "C" __declspec(dllexport)
#else
#define DLLFUNC extern "C"
#endif
// htonll and ntohll already defined on windows
#ifndef _WIN32
#ifndef WIN32
# if defined(__linux__)
# include <endian.h>
# elif defined(__FreeBSD__) || defined(__NetBSD__)
+1 -1
View File
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _WIN32
#ifndef _WINDOWS
#include "unix.h"
#include <string.h>
+1 -1
View File
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _WIN32
#ifndef _WINDOWS
#ifndef __UNIX_H__
#define __UNIX_H__
#include <unistd.h>
+3 -3
View File
@@ -10,16 +10,16 @@
// this doesn't do shit for C++ but libc++ and GCC 6.1+ use it to define some macros
#include <ciso646>
#ifndef _WIN32
#ifndef WIN32
extern "C" { //the perl headers dont do this for us...
#endif
#include <perl.h>
#include <XSUB.h>
#ifndef _WIN32
#ifndef WIN32
};
#endif
#ifdef _WIN32
#ifdef WIN32
#ifndef snprintf
#define snprintf _snprintf
#endif
+1 -1
View File
@@ -40,7 +40,7 @@
#endif
#define COMPILE_DATE __DATE__
#define COMPILE_TIME __TIME__
#ifndef _WIN32
#ifndef WIN32
#define LAST_MODIFIED __TIME__
#else
#define LAST_MODIFIED __TIMESTAMP__
+2
View File
@@ -0,0 +1,2 @@
*.*
*
+1 -1
View File
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(eqlaunch_sources
eqlaunch.cpp
+2 -2
View File
@@ -70,7 +70,7 @@ int main(int argc, char *argv[]) {
Log(Logs::Detail, Logs::Launcher, "Could not set signal handler");
return 1;
}
#ifndef _WIN32
#ifndef WIN32
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
Log(Logs::Detail, Logs::Launcher, "Could not set signal handler");
return 1;
@@ -136,7 +136,7 @@ int main(int argc, char *argv[]) {
zones.erase(rem);
}
EQ::EventLoop::GetDefault().Process();
EQ::EventLoop::Get().Process();
Sleep(5);
}
+1 -1
View File
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(hc_sources
eq.cpp
+32 -55
View File
@@ -1,61 +1,38 @@
# Build for LuaBind
# Ryan Pavlik <rpavlik@iastate.edu>
# http://academic.cleardefinition.com/
# Iowa State University HCI Graduate Program/VRAC
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
cmake_minimum_required(VERSION 3.0)
project(LuaBind)
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "9")
set(CPACK_PACKAGE_VERSION_PATCH "1")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(NOT LUA_FOUND AND NOT LUA51_FOUND)
find_package(Lua51 REQUIRED)
set(LUA_INCLUDE_DIRS "${LUA_INCLUDE_DIR}")
endif()
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
# We are the top-level project
include(CTest)
option(LUABIND_INSTALL "Install the LuaBind library and headers" ON)
option(LUABIND_BUILD_DOCS "Build documentation files" OFF)
option(LUABIND_BUILD_SHARED "Build luabind as a shared library?" OFF)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Requiring C++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
if(MSVC)
# Requiring C++11
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++11")
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /std:c++11")
endif()
set(BUILD_SHARED_LIBS ${LUABIND_BUILD_SHARED})
if(BUILD_SHARED_LIBS)
add_definitions(-DLUABIND_DYNAMIC_LINK)
endif()
include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}"
${LUA_INCLUDE_DIRS}
SET(lb_sources
src/class.cpp
src/class_info.cpp
src/class_registry.cpp
src/class_rep.cpp
src/create_class.cpp
src/error.cpp
src/exception_handler.cpp
src/function.cpp
src/inheritance.cpp
src/link_compatibility.cpp
src/object_rep.cpp
src/open.cpp
src/pcall.cpp
src/scope.cpp
src/stack_content_by_name.cpp
src/weak_ref.cpp
src/wrapper_base.cpp
)
add_subdirectory(src)
SET(lb_headers
if(BUILD_TESTING)
add_subdirectory(test)
endif()
)
if(LUABIND_BUILD_DOCS)
add_subdirectory(doc)
endif()
ADD_LIBRARY(luabind ${lb_sources} ${lb_headers})
IF(UNIX)
set_source_files_properties(${lb_sources} PROPERTY COMPILE_FLAGS -Wno-deprecated-declarations)
ENDIF(UNIX)
IF(MSVC)
set_source_files_properties(${lb_sources} PROPERTY COMPILE_FLAGS " /W0 " )
ENDIF(MSVC)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
-54
View File
@@ -1,54 +0,0 @@
{
"configurations": [
{
"name": "x32-debug",
"generator": "Visual Studio 15 2017",
"buildRoot": "${projectDir}/temp/x32-debug",
"cmakeCommandArgs": "",
"configurationType": "Debug",
"variables": [
{
"name": "LUA_INCLUDE_DIR",
"value": "C:/gitprojects/LuaJIT-2.1.0-beta3/src"
},
{
"name": "LUA_LIBRARIES",
"value": "C:/gitprojects/LuaJIT-2.1.0-beta3/src/lua51.lib"
},
{
"name": "LUABIND_INSTALL",
"value": "ON"
},
{
"name": "CMAKE_INSTALL_PREFIX",
"value": "${projectDir}/build/debug"
}
]
},
{
"name": "x32-release",
"generator": "Visual Studio 15 2017",
"buildRoot": "${projectDir}/temp/x32-release",
"cmakeCommandArgs": "",
"configurationType": "Release",
"variables": [
{
"name": "LUA_INCLUDE_DIR",
"value": "C:/gitprojects/LuaJIT-2.1.0-beta3/src"
},
{
"name": "LUA_LIBRARIES",
"value": "C:/gitprojects/LuaJIT-2.1.0-beta3/src/lua51.lib"
},
{
"name": "LUABIND_INSTALL",
"value": "ON"
},
{
"name": "CMAKE_INSTALL_PREFIX",
"value": "${projectDir}/build/release"
}
]
}
]
}
+89 -86
View File
@@ -28,111 +28,114 @@
#include <luabind/wrapper_base.hpp>
#include <luabind/detail/policy.hpp>
#include <luabind/back_reference_fwd.hpp>
#include <luabind/wrapper_base.hpp>
#include <boost/type_traits/is_polymorphic.hpp>
namespace luabind {
namespace detail {
namespace luabind { namespace detail
{
template <class T>
void adjust_backref_ownership(T* ptr, mpl::true_)
{
if (wrap_base* p = dynamic_cast<wrap_base*>(ptr))
{
wrapped_self_t& wrapper = wrap_access::ref(*p);
wrapper.get(wrapper.state());
wrapper.m_strong_ref.set(wrapper.state());
}
}
template <class T>
void adjust_backref_ownership(T* ptr, std::true_type)
inline void adjust_backref_ownership(void*, mpl::false_)
{}
template<class Direction = lua_to_cpp>
struct adopt_pointer : pointer_converter
{
typedef adopt_pointer type;
int const consumed_args(...)
{
return 1;
}
template<class T>
T* apply(lua_State* L, by_pointer<T>, int index)
{
if(wrap_base* p = dynamic_cast<wrap_base*>(ptr))
{
wrapped_self_t& wrapper = wrap_access::ref(*p);
wrapper.get(wrapper.state());
wrapper.m_strong_ref.set(wrapper.state());
}
T* ptr = pointer_converter::apply(
L, LUABIND_DECORATE_TYPE(T*), index);
object_rep* obj = static_cast<object_rep*>(
lua_touserdata(L, index));
obj->release();
adjust_backref_ownership(ptr, boost::is_polymorphic<T>());
return ptr;
}
inline void adjust_backref_ownership(void*, std::false_type)
{}
template <class Pointer, class Direction = lua_to_cpp>
struct adopt_pointer : pointer_converter
template<class T>
int match(lua_State* L, by_pointer<T>, int index)
{
using type = adopt_pointer;
return pointer_converter::match(
L, LUABIND_DECORATE_TYPE(T*), index);
}
enum { consumed_args = 1 };
template<class T>
void converter_postcall(lua_State*, T, int) {}
};
template<class T>
T* to_cpp(lua_State* L, by_pointer<T>, int index)
template<>
struct adopt_pointer<cpp_to_lua>
{
typedef adopt_pointer type;
template<class T>
void apply(lua_State* L, T* ptr)
{
if (ptr == 0)
{
T* ptr = pointer_converter::to_cpp(L, decorate_type_t<T*>(), index);
object_rep* obj = static_cast<object_rep*>(lua_touserdata(L, index));
obj->release();
adjust_backref_ownership(ptr, std::is_polymorphic<T>());
return ptr;
lua_pushnil(L);
return;
}
template<class T>
int match(lua_State* L, by_pointer<T>, int index)
{
return pointer_converter::match(L, decorate_type_t<T*>(), index);
}
// if there is a back_reference, then the
// ownership will be removed from the
// back reference and put on the lua stack.
if (luabind::move_back_reference(L, ptr))
return;
template<class T>
void converter_postcall(lua_State*, T, int) {}
};
make_instance(L, std::auto_ptr<T>(ptr));
}
};
template <class Pointer, class T>
struct pointer_or_default
template<int N>
// struct adopt_policy : converter_policy_tag
struct adopt_policy : conversion_policy<N>
{
// BOOST_STATIC_CONSTANT(int, index = N);
static void precall(lua_State*, const index_map&) {}
static void postcall(lua_State*, const index_map&) {}
struct only_accepts_nonconst_pointers {};
template<class T, class Direction>
struct apply
{
using type = Pointer;
typedef luabind::detail::is_nonconst_pointer<T> is_nonconst_p;
typedef typename boost::mpl::if_<is_nonconst_p, adopt_pointer<Direction>, only_accepts_nonconst_pointers>::type type;
};
};
template <class T>
struct pointer_or_default<void, T>
{
using type = std::unique_ptr<T>;
};
template <class Pointer>
struct adopt_pointer<Pointer, cpp_to_lua>
{
using type = adopt_pointer;
template<class T>
void to_lua(lua_State* L, T* ptr)
{
if(ptr == 0)
{
lua_pushnil(L);
return;
}
// if there is a back_reference, then the
// ownership will be removed from the
// back reference and put on the lua stack.
if(luabind::move_back_reference(L, ptr))
return;
using pointer_type = typename pointer_or_default<Pointer, T>::type;
make_pointer_instance(L, pointer_type(ptr));
}
};
template <class Pointer>
struct adopt_policy_impl
{
template<class T, class Direction>
struct specialize
{
static_assert(detail::is_nonconst_pointer<T>::value, "Adopt policy only accepts non-const pointers");
using type = adopt_pointer<Pointer, Direction>;
};
};
}
}
}}
namespace luabind
{
// Caution: if we use the aliased type "policy_list" here, MSVC crashes.
template<unsigned int N, typename Pointer = void>
using adopt_policy = meta::type_list<converter_policy_injector<N, detail::adopt_policy_impl<Pointer>>>;
template<int N>
detail::policy_cons<detail::adopt_policy<N>, detail::null_type>
adopt(LUABIND_PLACEHOLDER_ARG(N))
{
return detail::policy_cons<detail::adopt_policy<N>, detail::null_type>();
}
}
#endif // LUABIND_ADOPT_POLICY_HPP_INCLUDE
+67 -65
View File
@@ -23,86 +23,88 @@
#ifndef LUABIND_BACK_REFERENCE_040510_HPP
#define LUABIND_BACK_REFERENCE_040510_HPP
#include <luabind/config.hpp>
#include <luabind/lua_state_fwd.hpp>
#include <type_traits>
#if !defined(LUABIND_NO_RTTI) && !defined(LUABIND_WRAPPER_BASE_HPP_INCLUDED)
#include <luabind/lua_include.hpp>
#include <luabind/wrapper_base.hpp>
#endif
#include <luabind/pointer_traits.hpp>
#include <luabind/detail/has_get_pointer.hpp>
#include <luabind/get_pointer.hpp>
#include <boost/type_traits/is_polymorphic.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/mpl/if.hpp>
namespace luabind {
struct wrap_base;
namespace detail
{
template<class T>
wrap_base const* get_back_reference_aux0(T const* p, std::true_type)
{
return dynamic_cast<wrap_base const*>(p);
}
namespace detail
{
namespace mpl = boost::mpl;
template<class T>
wrap_base const* get_back_reference_aux0(T const* p, mpl::true_)
{
return dynamic_cast<wrap_base const*>(p);
}
template<class T>
wrap_base const* get_back_reference_aux0(T const*, std::false_type)
{
return 0;
}
template<class T>
wrap_base const* get_back_reference_aux0(T const*, mpl::false_)
{
return 0;
}
template<class T>
wrap_base const* get_back_reference_aux1(T const* p)
{
return get_back_reference_aux0(p, std::is_polymorphic<T>());
}
template<class T>
wrap_base const* get_back_reference_aux1(T const* p)
{
return get_back_reference_aux0(p, boost::is_polymorphic<T>());
}
template<class T>
wrap_base const* get_back_reference_aux2(T const& x, std::true_type)
{
return get_back_reference_aux1(get_pointer(x));
}
template<class T>
wrap_base const* get_back_reference_aux2(T const& x, mpl::true_)
{
return get_back_reference_aux1(get_pointer(x));
}
template<class T>
wrap_base const* get_back_reference_aux2(T const& x, std::false_type)
{
return get_back_reference_aux1(&x);
}
template<class T>
wrap_base const* get_back_reference_aux2(T const& x, mpl::false_)
{
return get_back_reference_aux1(&x);
}
template<class T>
wrap_base const* get_back_reference(T const& x)
{
return detail::get_back_reference_aux2(x, has_get_pointer<T>());
}
template<class T>
wrap_base const* get_back_reference(T const& x)
{
return detail::get_back_reference_aux2(
x
, has_get_pointer<T>()
);
}
} // namespace detail
} // namespace detail
template<class T>
bool get_back_reference(lua_State* L, T const& x)
{
template<class T>
bool get_back_reference(lua_State* L, T const& x)
{
#ifndef LUABIND_NO_RTTI
if(wrap_base const* w = detail::get_back_reference(x))
{
detail::wrap_access::ref(*w).get(L);
return true;
}
if (wrap_base const* w = detail::get_back_reference(x))
{
detail::wrap_access::ref(*w).get(L);
return true;
}
#endif
return false;
}
return false;
}
template<class T>
bool move_back_reference(lua_State* L, T const& x)
{
template<class T>
bool move_back_reference(lua_State* L, T const& x)
{
#ifndef LUABIND_NO_RTTI
if(wrap_base* w = const_cast<wrap_base*>(detail::get_back_reference(x)))
{
assert(detail::wrap_access::ref(*w).m_strong_ref.is_valid());
detail::wrap_access::ref(*w).get(L);
detail::wrap_access::ref(*w).m_strong_ref.reset();
return true;
}
if (wrap_base* w = const_cast<wrap_base*>(detail::get_back_reference(x)))
{
assert(detail::wrap_access::ref(*w).m_strong_ref.is_valid());
detail::wrap_access::ref(*w).get(L);
detail::wrap_access::ref(*w).m_strong_ref.reset();
return true;
}
#endif
return false;
}
return false;
}
} // namespace luabind
+4 -6
View File
@@ -23,15 +23,13 @@
#ifndef LUABIND_BACK_REFERENCE_FWD_040510_HPP
#define LUABIND_BACK_REFERENCE_FWD_040510_HPP
#include <luabind/lua_state_fwd.hpp>
namespace luabind {
template<class T>
bool get_back_reference(lua_State* L, T const& x);
template<class T>
bool get_back_reference(lua_State* L, T const& x);
template<class T>
bool move_back_reference(lua_State* L, T const& x);
template<class T>
bool move_back_reference(lua_State* L, T const& x);
} // namespace luabind
File diff suppressed because it is too large Load Diff
+5 -4
View File
@@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef LUABIND_CLASS_INFO_HPP_INCLUDED
#define LUABIND_CLASS_INFO_HPP_INCLUDED
@@ -31,16 +32,16 @@
namespace luabind
{
struct LUABIND_API class_info
{
{
std::string name;
object methods;
object attributes;
};
LUABIND_API class_info get_class_info(argument const&);
LUABIND_API class_info get_class_info(argument const&);
// returns a table of bound class names
LUABIND_API object get_class_names(lua_State* L);
// returns a table of bound class names
LUABIND_API object get_class_names(lua_State* L);
LUABIND_API void bind_class_info(lua_State*);
}
+39 -24
View File
@@ -20,26 +20,57 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef LUABIND_CONFIG_HPP_INCLUDED
#define LUABIND_CONFIG_HPP_INCLUDED
#include <boost/config.hpp>
#ifdef BOOST_MSVC
#define LUABIND_ANONYMOUS_FIX static
#else
#define LUABIND_ANONYMOUS_FIX
#endif
#if defined (BOOST_MSVC) && (BOOST_MSVC <= 1200)
#define for if (false) {} else for
#include <cstring>
namespace std
{
using ::strlen;
using ::strcmp;
using ::type_info;
}
#endif
#if defined (BOOST_MSVC) && (BOOST_MSVC <= 1300)
#define LUABIND_MSVC_TYPENAME
#else
#define LUABIND_MSVC_TYPENAME typename
#endif
// the maximum number of arguments of functions that's
// registered. Must at least be 2
#ifndef LUABIND_MAX_ARITY
#define LUABIND_MAX_ARITY 100
#define LUABIND_MAX_ARITY 10
#elif LUABIND_MAX_ARITY <= 1
#undef LUABIND_MAX_ARITY
#define LUABIND_MAX_ARITY 2
#undef LUABIND_MAX_ARITY
#define LUABIND_MAX_ARITY 2
#endif
// the maximum number of classes one class
// can derive from
// max bases must at least be 1
#ifndef LUABIND_MAX_BASES
#define LUABIND_MAX_BASES 100
#define LUABIND_MAX_BASES 4
#elif LUABIND_MAX_BASES <= 0
#undef LUABIND_MAX_BASES
#define LUABIND_MAX_BASES 1
#undef LUABIND_MAX_BASES
#define LUABIND_MAX_BASES 1
#endif
// LUABIND_NO_ERROR_CHECKING
@@ -70,18 +101,12 @@
// C code has undefined behavior, lua is written in C).
#ifdef LUABIND_DYNAMIC_LINK
# if defined (_WIN32)
# ifdef BOOST_WINDOWS
# ifdef LUABIND_BUILDING
# define LUABIND_API __declspec(dllexport)
# else
# define LUABIND_API __declspec(dllimport)
# endif
# elif defined (__CYGWIN__)
# ifdef LUABIND_BUILDING
# define LUABIND_API __attribute__ ((dllexport))
# else
# define LUABIND_API __attribute__ ((dllimport))
# endif
# else
# if defined(_GNUC_) && _GNUC_ >=4
# define LUABIND_API __attribute__ ((visibility("default")))
@@ -93,19 +118,9 @@
# define LUABIND_API
#endif
// This switches between using tag arguments / structure specialization for code size tests
#define LUABIND_NO_INTERNAL_TAG_ARGUMENTS
namespace luabind {
LUABIND_API void disable_super_deprecation();
namespace detail {
const int max_argument_count = 100;
const int max_hierarchy_depth = 100;
}
const int no_match = -(detail::max_argument_count*detail::max_hierarchy_depth + 1);
LUABIND_API void disable_super_deprecation();
} // namespace luabind
+94 -81
View File
@@ -20,111 +20,124 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef LUABIND_CONTAINER_POLICY_HPP_INCLUDED
#define LUABIND_CONTAINER_POLICY_HPP_INCLUDED
#include <luabind/config.hpp>
#include <luabind/detail/policy.hpp>
#include <luabind/detail/decorate_type.hpp> // for decorated_type
#include <luabind/detail/primitives.hpp> // for null_type (ptr only), etc
#include <boost/mpl/apply_wrap.hpp>
namespace luabind {
namespace detail {
namespace luabind { namespace detail {
template<class Policies>
struct container_converter_lua_to_cpp
namespace mpl = boost::mpl;
template<class Policies>
struct container_converter_lua_to_cpp
{
int const consumed_args(...)
{
return 1;
}
template<class T>
T apply(lua_State* L, by_const_reference<T>, int index)
{
enum { consumed_args = 1 };
typedef typename T::value_type value_type;
template<class T>
T to_cpp(lua_State* L, by_const_reference<T>, int index)
typedef typename find_conversion_policy<1, Policies>::type converter_policy;
typename mpl::apply_wrap2<converter_policy,value_type,lua_to_cpp>::type converter;
T container;
lua_pushnil(L);
while (lua_next(L, index))
{
using value_type = typename T::value_type;
specialized_converter_policy_n<1, Policies, value_type, lua_to_cpp> converter;
T container;
lua_pushnil(L);
while(lua_next(L, index - 1))
{
container.push_back(converter.apply(L, decorated_type<value_type>(), -1));
lua_pop(L, 1); // pop value
}
return container;
container.push_back(converter.apply(L, LUABIND_DECORATE_TYPE(value_type), -1));
lua_pop(L, 1); // pop value
}
template<class T>
T to_cpp(lua_State* L, by_value<T>, int index)
{
return to_cpp(L, by_const_reference<T>(), index);
}
return container;
}
template<class T>
static int match(lua_State* L, by_const_reference<T>, int index)
{
if(lua_istable(L, index)) return 0; else return no_match;
}
template<class T>
static int match(lua_State* L, by_value<T>, int index)
{
return match(L, by_const_reference<T>(), index);
}
template<class T>
void converter_postcall(lua_State*, T, int) {}
};
template<class Policies>
struct container_converter_cpp_to_lua
template<class T>
T apply(lua_State* L, by_value<T>, int index)
{
template<class T>
void to_lua(lua_State* L, const T& container)
{
using value_type = typename T::value_type;
specialized_converter_policy_n<1, Policies, value_type, lua_to_cpp> converter;
return apply(L, by_const_reference<T>(), index);
}
lua_newtable(L);
int index = 1;
for(const auto& element : container)
{
converter.apply(L, element);
lua_rawseti(L, -2, index);
++index;
}
}
};
template<class Policies = no_policies>
struct container_policy
template<class T>
static int match(lua_State* L, by_const_reference<T>, int index)
{
struct only_accepts_nonconst_pointers {};
if (lua_istable(L, index)) return 0; else return -1;
}
template<class T, class Direction>
struct specialize;
template<class T>
void converter_postcall(lua_State*, T, int) {}
};
template<class T>
struct specialize<T, lua_to_cpp> {
using type = container_converter_lua_to_cpp<Policies>;
};
template<class Policies>
struct container_converter_cpp_to_lua
{
template<class T>
void apply(lua_State* L, const T& container)
{
typedef typename T::value_type value_type;
template<class T>
struct specialize<T, cpp_to_lua> {
using type = container_converter_cpp_to_lua<Policies>;
};
typedef typename find_conversion_policy<1, Policies>::type converter_policy;
typename mpl::apply_wrap2<converter_policy,value_type,lua_to_cpp>::type converter;
lua_newtable(L);
int index = 1;
for (typename T::const_iterator i = container.begin(); i != container.end(); ++i)
{
converter.apply(L, *i);
lua_rawseti(L, -2, index);
++index;
}
}
};
template<int N, class Policies>
// struct container_policy : converter_policy_tag
struct container_policy : conversion_policy<N>
{
// BOOST_STATIC_CONSTANT(int, index = N);
static void precall(lua_State*, const index_map&) {}
static void postcall(lua_State*, const index_map&) {}
struct only_accepts_nonconst_pointers {};
template<class T, class Direction>
struct apply
{
typedef typename boost::mpl::if_<boost::is_same<lua_to_cpp, Direction>
, container_converter_lua_to_cpp<Policies>
, container_converter_cpp_to_lua<Policies>
>::type type;
};
};
}
}
}}
namespace luabind
{
template<unsigned int N, typename ElementPolicies = no_policies >
using container_policy = meta::type_list<converter_policy_injector<N, detail::container_policy<ElementPolicies>>>;
template<int N>
detail::policy_cons<detail::container_policy<N, detail::null_type>, detail::null_type>
container(LUABIND_PLACEHOLDER_ARG(N))
{
return detail::policy_cons<detail::container_policy<N, detail::null_type>, detail::null_type>();
}
template<int N, class Policies>
detail::policy_cons<detail::container_policy<N, Policies>, detail::null_type>
container(LUABIND_PLACEHOLDER_ARG(N), const Policies&)
{
return detail::policy_cons<detail::container_policy<N, Policies>, detail::null_type>();
}
}
#endif // LUABIND_CONTAINER_POLICY_HPP_INCLUDED
+41 -30
View File
@@ -8,41 +8,52 @@
# include <luabind/detail/policy.hpp>
namespace luabind {
namespace detail {
struct copy_converter
{
template <class T>
void to_lua(lua_State* L, T const& x)
{
value_converter().to_lua(L, x);
}
namespace detail
{
template <class T>
void to_lua(lua_State* L, T* x)
{
if(!x)
lua_pushnil(L);
else
to_lua(L, *x);
}
};
struct copy_converter
{
template <class T>
void apply(lua_State* L, T const& x)
{
value_converter().apply(L, x);
}
struct copy_policy
{
template <class T, class Direction>
struct specialize
{
static_assert(std::is_same<Direction, cpp_to_lua>::value, "Copy policy only supports cpp -> lua");
using type = copy_converter;
};
};
template <class T>
void apply(lua_State* L, T* x)
{
if (!x)
lua_pushnil(L);
else
apply(L, *x);
}
};
} // namespace detail
template <int N>
struct copy_policy : conversion_policy<N>
{
static void precall(lua_State*, index_map const&)
{}
// Caution: If we use the aliased type "policy_list" here, MSVC crashes.
template< unsigned int N >
using copy_policy = meta::type_list< converter_policy_injector< N, detail::copy_policy > >;
static void postcall(lua_State*, index_map const&)
{}
template <class T, class Direction>
struct apply
{
typedef copy_converter type;
};
};
} // namespace detail
template <int N>
detail::policy_cons<detail::copy_policy<N>, detail::null_type>
copy(LUABIND_PLACEHOLDER_ARG(N))
{
return detail::policy_cons<detail::copy_policy<N>, detail::null_type>();
}
} // namespace luabind
+77 -57
View File
@@ -25,75 +25,95 @@
#define LUABIND_DEPENDENCY_POLICY_HPP_INCLUDED
#include <luabind/config.hpp>
#include <luabind/detail/policy.hpp> // for policy_cons, etc
#include <luabind/detail/object_rep.hpp> // for object_rep
#include <luabind/detail/primitives.hpp> // for null_type
#include <luabind/detail/policy.hpp>
namespace luabind {
namespace detail {
// makes A dependent on B, meaning B will outlive A.
// internally A stores a reference to B
template<int A, int B>
struct dependency_policy
namespace luabind { namespace detail
{
// makes A dependent on B, meaning B will outlive A.
// internally A stores a reference to B
template<int A, int B>
struct dependency_policy
{
static void postcall(lua_State* L, const index_map& indices)
{
template< unsigned int... StackIndices >
static void postcall(lua_State* L, int results, meta::index_list<StackIndices...>)
{
object_rep* nurse = static_cast<object_rep*>(lua_touserdata(L, meta::get<meta::index_list<StackIndices...>, A>::value));
int nurse_index = indices[A];
int patient = indices[B];
// If the nurse isn't an object_rep, just make this a nop.
if(nurse == 0)
return;
object_rep* nurse = static_cast<object_rep*>(lua_touserdata(L, nurse_index));
nurse->add_dependency(L, meta::get<meta::index_list<StackIndices...>, B>::value);
}
};
// If the nurse isn't an object_rep, just make this a nop.
if (nurse == 0)
return;
template<int B>
struct dependency_policy<0, B>
{
template< unsigned int... StackIndices >
static void postcall(lua_State* L, int results, meta::index_list<StackIndices...>)
{
object_rep* nurse = static_cast<object_rep*>(lua_touserdata(L, meta::get<meta::index_list<StackIndices...>, 0>::value + results));
nurse->add_dependency(L, patient);
}
};
// If the nurse isn't an object_rep, just make this a nop.
if(nurse == 0)
return;
}}
nurse->add_dependency(L, meta::get<meta::index_list<StackIndices...>, B>::value);
}
};
template<int A>
struct dependency_policy<A, 0>
{
template< unsigned int... StackIndices >
static void postcall(lua_State* L, int results, meta::index_list<StackIndices...>)
{
object_rep* nurse = static_cast<object_rep*>(lua_touserdata(L, meta::get<meta::index_list<StackIndices...>, A>::value));
// If the nurse isn't an object_rep, just make this a nop.
if(nurse == 0)
return;
nurse->add_dependency(L, meta::get<meta::index_list<StackIndices...>, 0>::value + results);
}
};
}
}
#if defined (BOOST_MSVC) && (BOOST_MSVC <= 1200)
namespace luabind
{
// Caution: If we use the aliased type "policy_list" here, MSVC crashes.
template<unsigned int A, unsigned int B>
using dependency_policy = meta::type_list<call_policy_injector<detail::dependency_policy<A, B>>>;
// most absurd workaround of all time?
namespace detail
{
template<int N>
struct size_char_array
{
char storage[N + 2];
};
template<unsigned int A>
using return_internal_reference = meta::type_list<call_policy_injector<detail::dependency_policy<0, A>>>;
template<int N>
size_char_array<N> deduce_size(LUABIND_PLACEHOLDER_ARG(N));
template<class T>
struct get_index_workaround
{
static T t;
BOOST_STATIC_CONSTANT(int, value = sizeof(deduce_size(t)) - 2);
};
}
template<class A, class B>
detail::policy_cons<detail::dependency_policy<detail::get_index_workaround<A>::value
, detail::get_index_workaround<B>::value>, detail::null_type> dependency(A,B)
{
return detail::policy_cons<detail::dependency_policy<
detail::get_index_workaround<A>::value, detail::get_index_workaround<B>::value>
, detail::null_type>();
}
template<class A>
detail::policy_cons<detail::dependency_policy<0
, detail::get_index_workaround<A>::value>, detail::null_type>
return_internal_reference(A)
{
return detail::policy_cons<detail::dependency_policy<0
, detail::get_index_workaround<A>::value>, detail::null_type>();
}
}
#else
namespace luabind
{
template<int A, int B>
detail::policy_cons<detail::dependency_policy<A, B>, detail::null_type>
dependency(LUABIND_PLACEHOLDER_ARG(A), LUABIND_PLACEHOLDER_ARG(B))
{
return detail::policy_cons<detail::dependency_policy<A, B>, detail::null_type>();
}
template<int A>
detail::policy_cons<detail::dependency_policy<0, A>, detail::null_type>
return_internal_reference(LUABIND_PLACEHOLDER_ARG(A))
{
return detail::policy_cons<detail::dependency_policy<0, A>, detail::null_type>();
}
}
#endif
#endif // LUABIND_DEPENDENCY_POLICY_HPP_INCLUDED
@@ -20,46 +20,42 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef LUABIND_CALL_SHARED_HPP_INCLUDED
#define LUABIND_CALL_SHARED_HPP_INCLUDED
#if !BOOST_PP_IS_ITERATING
namespace luabind {
namespace detail {
# include <luabind/detail/signature_match.hpp>
inline void call_error(lua_State* L)
#ifndef LUABIND_CALC_ARITY_HPP_INCLUDED
#define LUABIND_CALC_ARITY_HPP_INCLUDED
#define LUABIND_FIND_CONV(z,n,text) typedef typename find_conversion_policy<n + 1, Policies>::type p##n;
#define LUABIND_CALC_ARITY(z,n,text) + BOOST_PP_CAT(p,n)::has_arg
namespace luabind { namespace detail
{
template<int N> struct calc_arity;
#define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/detail/calc_arity.hpp>, 1))
#include BOOST_PP_ITERATE()
}}
#undef LUABIND_CALC_ARITY
#undef LUABIND_FIND_CONV
#endif // LUABIND_CALC_ARITY_HPP_INCLUDED
#else // BOOST_PP_ITERATE
template<>
struct calc_arity<BOOST_PP_ITERATION()>
{
template<BOOST_PP_ENUM_PARAMS(LUABIND_MAX_ARITY, class A), class Policies>
static int apply(constructor<BOOST_PP_ENUM_PARAMS(LUABIND_MAX_ARITY, A)>, Policies*)
{
#ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L);
#else
error_callback_fun e = get_error_callback();
if(e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled."
" If you want to handle the error you can use luabind::set_error_callback()");
std::terminate();
#endif
BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_FIND_CONV, _)
return 0 BOOST_PP_REPEAT(BOOST_PP_ITERATION(), LUABIND_CALC_ARITY, _);
}
template<typename T>
void cast_error(lua_State* L)
{
#ifndef LUABIND_NO_EXCEPTIONS
throw cast_failed(L, typeid(T));
#else
cast_failed_callback_fun e = get_cast_failed_callback();
if(e) e(L, typeid(T));
assert(0 && "the lua function's return value could not be converted."
" If you want to handle the error you can use luabind::set_cast_failed_callback()");
std::terminate();
#endif
}
template< typename... Args >
void expand_hack(Args... /*args*/)
{}
}
}
};
#endif
+317 -541
View File
@@ -1,547 +1,323 @@
// Copyright Daniel Wallin 208.Use, modification and distribution is
// Copyright Daniel Wallin 2008. Use, modification and distribution is
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef LUABIND_CALL2_080911_HPP
#define LUABIND_CALL2_080911_HPP
#include <luabind/config.hpp>
#include <typeinfo>
#include <luabind/detail/meta.hpp>
#include <luabind/detail/policy.hpp>
#include <luabind/yield_policy.hpp>
#include <luabind/detail/decorate_type.hpp>
#include <luabind/detail/object.hpp>
#ifdef LUABIND_NO_INTERNAL_TAG_ARGUMENTS
#include <tuple>
#endif
namespace luabind {
namespace detail {
struct invoke_context;
struct LUABIND_API function_object
{
function_object(lua_CFunction entry)
: entry(entry)
, next(0)
{}
virtual ~function_object()
{}
virtual int call(lua_State* L, invoke_context& ctx) /* const */ = 0;
virtual void format_signature(lua_State* L, char const* function) const = 0;
lua_CFunction entry;
std::string name;
function_object* next;
object keepalive;
};
struct LUABIND_API invoke_context
{
invoke_context()
: best_score((std::numeric_limits<int>::max)())
//This need to avoid static analyzer's treats
, candidates{ nullptr,nullptr,nullptr,nullptr,nullptr,
nullptr,nullptr,nullptr,nullptr,nullptr }
, candidate_index(0)
{}
operator bool() const
{
return candidate_index == 1;
}
void format_error(lua_State* L, function_object const* overloads) const;
int best_score;
function_object const* candidates[10]; // This looks like it could crash if you provide too many overloads?
int candidate_index;
};
namespace call_detail_new {
/*
Compute Stack Indices
Given the list of argument converter arities, computes the stack indices that each converter addresses.
*/
template< typename ConsumedList, unsigned int CurrentSum, unsigned int... StackIndices >
struct compute_stack_indices;
template< unsigned int Consumed0, unsigned int... Consumeds, unsigned int CurrentSum, unsigned int... StackIndices >
struct compute_stack_indices< meta::index_list< Consumed0, Consumeds... >, CurrentSum, StackIndices... >
{
using type = typename compute_stack_indices< meta::index_list< Consumeds... >, CurrentSum + Consumed0, StackIndices..., CurrentSum >::type;
};
template< unsigned int CurrentSum, unsigned int... StackIndices >
struct compute_stack_indices< meta::index_list< >, CurrentSum, StackIndices... >
{
using type = meta::index_list< StackIndices... >;
};
template< typename Foo >
struct FooFoo { // Foo!
enum { consumed_args = Foo::consumed_args };
};
template< typename PolicyList, typename StackIndexList >
struct policy_list_postcall;
template< typename Policy0, typename... Policies, typename StackIndexList >
struct policy_list_postcall< meta::type_list< call_policy_injector<Policy0>, Policies... >, StackIndexList > {
static void postcall(lua_State* L, int results) {
Policy0::postcall(L, results, StackIndexList());
policy_list_postcall< meta::type_list< Policies... >, StackIndexList >::postcall(L, results);
}
};
template< typename ConverterPolicy, typename StackIndexList, bool has_postcall >
struct converter_policy_postcall {
static void postcall(lua_State* L, int results) {
ConverterPolicy::postcall(L, results, StackIndexList());
}
};
template< typename ConverterPolicy, typename StackIndexList >
struct converter_policy_postcall< ConverterPolicy, StackIndexList, false > {
static void postcall(lua_State* /*L*/, int /*results*/) {
}
};
template< unsigned int Index, typename Policy, typename... Policies, typename StackIndexList >
struct policy_list_postcall< meta::type_list< converter_policy_injector< Index, Policy >, Policies... >, StackIndexList > {
static void postcall(lua_State* L, int results) {
converter_policy_postcall < Policy, StackIndexList, converter_policy_injector< Index, Policy >::has_postcall >::postcall(L, results);
policy_list_postcall< meta::type_list< Policies... >, StackIndexList >::postcall(L, results);
}
};
template< typename StackIndexList >
struct policy_list_postcall< meta::type_list< >, StackIndexList > {
static void postcall(lua_State* /*L*/, int /*results*/) {}
};
#ifndef LUABIND_NO_INTERNAL_TAG_ARGUMENTS
template< typename... ArgumentConverters >
struct compute_invoke_values {
using consumed_list = meta::index_list< FooFoo<ArgumentConverters>::consumed_args... >;
using stack_index_list = typename compute_stack_indices< consumed_list, 1 >::type;
enum { arity = meta::sum<consumed_list>::value };
};
#endif
}
#ifndef LUABIND_NO_INTERNAL_TAG_ARGUMENTS
inline int match_deferred(lua_State* L, meta::index_list<>, meta::type_list<>)
{
return 0;
}
template< unsigned int StackIndex0, unsigned int... StackIndices,
typename ArgumentType0, typename... ArgumentTypes,
typename ArgumentConverter0, typename... ArgumentConverters >
int match_deferred(lua_State* L,
meta::index_list< StackIndex0, StackIndices... >,
meta::type_list< ArgumentType0, ArgumentTypes... >,
ArgumentConverter0& converter0, ArgumentConverters&... converters
)
{
const int this_match = converter0.match(L, decorated_type<ArgumentType0>(), StackIndex0);
const int other_match = match_deferred(L, meta::index_list<StackIndices...>(), meta::type_list<ArgumentTypes...>(), converters...);
return (this_match >= 0) ? // could also sum them all up unconditionally
this_match + match_deferred(L, meta::index_list<StackIndices...>(), meta::type_list<ArgumentTypes...>(), converters...)
: no_match;
}
template< typename T, bool isvoid, bool memfun = std::is_member_function_pointer<T>::value > struct do_call_struct;
template< typename T >
struct do_call_struct< T, true, true /*memfun*/> {
template< typename F, typename ArgumentType0, typename... ArgumentTypes, unsigned int StackIndex0, unsigned int... StackIndices, typename ReturnConverter, typename Argument0Converter, typename... ArgumentConverters >
static void do_call(lua_State* L, F& f,
meta::index_list<StackIndex0, StackIndices...>, meta::type_list<ArgumentType0, ArgumentTypes...>,
ReturnConverter& result_converter, Argument0Converter& arg0_converter, ArgumentConverters&... arg_converters
)
{
((arg0_converter.to_cpp(L, decorated_type<ArgumentType0>(), StackIndex0)).*f)(
arg_converters.to_cpp(L, decorated_type<ArgumentTypes>(), StackIndices)...
);
}
};
template< typename T >
struct do_call_struct< T, false, true /*memfun*/> {
template< typename F, typename ArgumentType0, typename... ArgumentTypes, unsigned int StackIndex0, unsigned int... StackIndices, typename ReturnConverter, typename Argument0Converter, typename... ArgumentConverters >
static void do_call(lua_State* L, F& f,
meta::index_list<StackIndex0, StackIndices...>, meta::type_list<ArgumentType0, ArgumentTypes...>,
ReturnConverter& result_converter, Argument0Converter& arg0_converter, ArgumentConverters&... arg_converters
)
{
result_converter.to_lua(L,
((arg0_converter.to_cpp(L, decorated_type<ArgumentType0>(), StackIndex0)).*f)(
arg_converters.to_cpp(L, decorated_type<ArgumentTypes>(), StackIndices)...
)
);
}
};
template< typename T >
struct do_call_struct< T, true, false > {
template<
typename F,
typename... ArgumentTypes, unsigned int... StackIndices,
typename ReturnConverter, typename... ArgumentConverters
>
static void do_call(lua_State* L, F& f,
meta::index_list<StackIndices...>, meta::type_list<ArgumentTypes...>,
ReturnConverter& result_converter, ArgumentConverters&... arg_converters)
{
f(arg_converters.to_cpp(L, decorated_type<ArgumentTypes>(), StackIndices)...);
}
};
template< typename T >
struct do_call_struct< T, false, false > {
template<
typename F,
typename... ArgumentTypes, unsigned int... StackIndices,
typename ReturnConverter, typename... ArgumentConverters
>
static void do_call(lua_State* L, F& f,
meta::index_list<StackIndices...>, meta::type_list<ArgumentTypes...>,
ReturnConverter& result_converter, ArgumentConverters&... arg_converters)
{
result_converter.to_lua(L,
f(arg_converters.to_cpp(L, decorated_type<ArgumentTypes>(), StackIndices)...)
);
}
};
template< typename F, typename ReturnType, typename... Arguments,
typename ReturnConverter, typename... ArgumentConverters,
unsigned int Index0, unsigned int... Indices, typename PolicyList
>
int invoke3(lua_State* L, function_object const& self, invoke_context& ctx, F& f,
PolicyList, meta::index_list< Index0, Indices... > index_list, meta::type_list<ReturnType, Arguments...> signature_list,
ReturnConverter return_converter, ArgumentConverters... argument_converters)
{
using invoke_values = typename call_detail_new::compute_invoke_values< ArgumentConverters... >;
using argument_list_type = meta::type_list<Arguments...>;
using argument_index_list = meta::index_list<Indices...>;
int const arguments = lua_gettop(L);
int score = no_match;
if(invoke_values::arity == arguments) {
score = match_deferred(L, typename invoke_values::stack_index_list(), argument_list_type(), argument_converters...);
}
if(score >= 0 && score < ctx.best_score) {
ctx.best_score = score;
ctx.candidates[0] = &self;
ctx.candidate_index = 1;
} else if(score == ctx.best_score) {
ctx.candidates[ctx.candidate_index++] = &self;
}
int results = 0;
if(self.next)
{
results = self.next->call(L, ctx);
}
if(score == ctx.best_score && ctx.candidate_index == 1)
{
do_call_struct<F, std::is_void<ReturnType>::value>::do_call(L, f, typename invoke_values::stack_index_list(), argument_list_type(), return_converter, argument_converters...);
meta::init_order{ (argument_converters.converter_postcall(L, decorated_type<Arguments>(), meta::get< typename invoke_values::stack_index_list, Indices - 1 >::value), 0)... };
results = lua_gettop(L) - invoke_values::arity;
if(has_call_policy<PolicyList, yield_policy>::value) {
results = lua_yield(L, results);
}
// call policiy list postcall
call_detail_new::policy_list_postcall < PolicyList, typename meta::push_front< typename invoke_values::stack_index_list, meta::index<invoke_values::arity> >::type >::postcall(L, results);
}
return results;
}
template< typename F, typename ReturnType, typename... Arguments, unsigned int Index0, unsigned int... Indices, typename PolicyList >
int invoke2(lua_State* L, function_object const& self, invoke_context& ctx, F& f,
meta::type_list<ReturnType, Arguments...> signature, meta::index_list<Index0, Indices...>, PolicyList)
{
using signature_type = meta::type_list<ReturnType, Arguments...>;
using return_converter = specialized_converter_policy_n<0, PolicyList, ReturnType, cpp_to_lua>;
return invoke3(L, self, ctx, f,
PolicyList(), meta::index_list<Index0, Indices...>(), signature,
return_converter(), specialized_converter_policy_n<Indices, PolicyList, Arguments, lua_to_cpp>()...
);
}
template <class F, class Signature, typename... PolicyInjectors>
// boost::bind's operator() is const, std::bind's is not
inline int invoke(lua_State* L, function_object const& self, invoke_context& ctx, F& f, Signature,
meta::type_list< PolicyInjectors... > const& injectors)
{
return invoke2(L, self, ctx, f, Signature(), typename meta::make_index_range<0, meta::size<Signature>::value>::type(), injectors);
}
#endif
#ifdef LUABIND_NO_INTERNAL_TAG_ARGUMENTS
// VC2013RC doesn't support expanding a template and its member template in one expression, that's why we have to to incrementally build
// the converter list instead of a single combined expansion.
template< typename ArgumentList, typename PolicyList, typename CurrentList = meta::type_list<>, unsigned int Counter = 1 >
struct compute_argument_converter_list;
template< typename Argument0, typename... Arguments, typename PolicyList, typename... CurrentConverters, unsigned int Counter >
struct compute_argument_converter_list< meta::type_list<Argument0, Arguments... >, PolicyList, meta::type_list<CurrentConverters...>, Counter >
{
using converter_type = typename policy_detail::get_converter_policy<Counter, PolicyList>::type;
using this_specialized = typename converter_type::template specialize<Argument0, lua_to_cpp >::type;
using type = typename compute_argument_converter_list<meta::type_list<Arguments...>, PolicyList, meta::type_list<CurrentConverters..., this_specialized>, Counter + 1>::type;
};
template<typename PolicyList, typename... CurrentConverters, unsigned int Counter >
struct compute_argument_converter_list< meta::type_list<>, PolicyList, meta::type_list<CurrentConverters...>, Counter >
{
using type = meta::type_list<CurrentConverters...>;
};
template< typename ConverterList >
struct build_consumed_list;
template< typename... Converters >
struct build_consumed_list< meta::type_list< Converters... > > {
using consumed_list = meta::index_list< call_detail_new::FooFoo<Converters>::consumed_args... >;
};
template< typename SignatureList, typename PolicyList >
struct invoke_traits;
// Specialization for free functions
template< typename ResultType, typename... Arguments, typename PolicyList >
struct invoke_traits< meta::type_list<ResultType, Arguments... >, PolicyList >
{
using signature_list = meta::type_list<ResultType, Arguments...>;
using policy_list = PolicyList;
using result_type = ResultType;
using result_converter = specialized_converter_policy_n<0, PolicyList, result_type, cpp_to_lua >;
using argument_list = meta::type_list<Arguments...>;
using decorated_argument_list = meta::type_list< decorate_type_t<Arguments>... >;
// note that this is 0-based, so whenever you want to fetch from the converter list, you need to add 1
using argument_index_list = typename meta::make_index_range< 0, sizeof...(Arguments) >::type;
using argument_converter_list = typename compute_argument_converter_list<argument_list, PolicyList>::type;
using argument_converter_tuple_type = typename meta::make_tuple<argument_converter_list>::type;
using consumed_list = typename build_consumed_list<argument_converter_list>::consumed_list;
using stack_index_list = typename call_detail_new::compute_stack_indices< consumed_list, 1 >::type;
enum { arity = meta::sum<consumed_list>::value };
};
template< typename StackIndexList, typename SignatureList, unsigned int End = meta::size<SignatureList>::value, unsigned int Index = 1 >
struct match_struct {
template< typename TupleType >
static int match(lua_State* L, TupleType& tuple)
{
const int this_match = std::get<Index - 1>(tuple).match(L, decorate_type_t<typename SignatureList::template at<Index>>(), meta::get<StackIndexList, Index - 1>::value);
return this_match >= 0 ? // could also sum them up unconditionally
this_match + match_struct<StackIndexList, SignatureList, End, Index + 1>::match(L, tuple)
: no_match;
}
};
template< typename StackIndexList, typename SignatureList, unsigned int Index >
struct match_struct< StackIndexList, SignatureList, Index, Index >
{
template< typename TupleType >
static int match(lua_State* /*L*/, TupleType&) {
return 0;
}
};
template< typename PolicyList, typename Signature, typename F >
struct invoke_struct
{
using traits = invoke_traits< Signature, PolicyList >;
template< bool IsMember, bool IsVoid, typename IndexList >
struct call_struct;
template< unsigned int... ArgumentIndices >
struct call_struct< false /*member*/, false /*void*/, meta::index_list<ArgumentIndices...> >
{
static void call(lua_State* L, F& f, typename traits::argument_converter_tuple_type& argument_tuple)
{
using decorated_list = typename traits::decorated_argument_list;
using stack_indices = typename traits::stack_index_list;
using result_converter = typename traits::result_converter;
result_converter().to_lua(L,
f((std::get<ArgumentIndices>(argument_tuple).to_cpp(L,
typename meta::get<decorated_list, ArgumentIndices>::type(),
meta::get<stack_indices, ArgumentIndices>::value))...
)
);
meta::init_order{
(std::get<ArgumentIndices>(argument_tuple).converter_postcall(L,
typename meta::get<typename traits::decorated_argument_list, ArgumentIndices>::type(),
meta::get<typename traits::stack_index_list, ArgumentIndices>::value), 0)...
};
}
};
template< unsigned int... ArgumentIndices >
struct call_struct< false /*member*/, true /*void*/, meta::index_list<ArgumentIndices...> >
{
static void call(lua_State* L, F& f, typename traits::argument_converter_tuple_type& argument_tuple)
{
using decorated_list = typename traits::decorated_argument_list;
using stack_indices = typename traits::stack_index_list;
// This prevents unused warnings with empty parameter lists
(void)L;
f(std::get<ArgumentIndices>(argument_tuple).to_cpp(L,
typename meta::get<decorated_list, ArgumentIndices>::type(),
meta::get<stack_indices, ArgumentIndices>::value)...
);
meta::init_order{
(std::get<ArgumentIndices>(argument_tuple).converter_postcall(L,
typename meta::get<typename traits::decorated_argument_list, ArgumentIndices>::type(),
meta::get<typename traits::stack_index_list, ArgumentIndices>::value), 0)...
};
}
};
template< unsigned int ClassIndex, unsigned int... ArgumentIndices >
struct call_struct< true /*member*/, false /*void*/, meta::index_list<ClassIndex, ArgumentIndices...> >
{
static void call(lua_State* L, F& f, typename traits::argument_converter_tuple_type& argument_tuple)
{
using decorated_list = typename traits::decorated_argument_list;
using stack_indices = typename traits::stack_index_list;
using result_converter = typename traits::result_converter;
auto& object = std::get<0>(argument_tuple).to_cpp(L,
typename meta::get<typename traits::decorated_argument_list, 0>::type(), 1);
result_converter().to_lua(L,
(object.*f)(std::get<ArgumentIndices>(argument_tuple).to_cpp(L,
typename meta::get<decorated_list, ArgumentIndices>::type(),
meta::get<stack_indices, ArgumentIndices>::value)...
)
);
meta::init_order{
(std::get<ArgumentIndices>(argument_tuple).converter_postcall(L,
typename meta::get<typename traits::decorated_argument_list, ArgumentIndices>::type(),
meta::get<typename traits::stack_index_list, ArgumentIndices>::value), 0)...
};
}
};
template< unsigned int ClassIndex, unsigned int... ArgumentIndices >
struct call_struct< true /*member*/, true /*void*/, meta::index_list<ClassIndex, ArgumentIndices...> >
{
static void call(lua_State* L, F& f, typename traits::argument_converter_tuple_type& argument_tuple)
{
using decorated_list = typename traits::decorated_argument_list;
using stack_indices = typename traits::stack_index_list;
auto& object = std::get<0>(argument_tuple).to_cpp(L, typename meta::get<typename traits::decorated_argument_list, 0>::type(), 1);
(object.*f)(std::get<ArgumentIndices>(argument_tuple).to_cpp(L,
typename meta::get<decorated_list, ArgumentIndices>::type(),
meta::get<stack_indices, ArgumentIndices>::value)...
);
meta::init_order{
(std::get<ArgumentIndices>(argument_tuple).converter_postcall(L,
typename meta::get<typename traits::decorated_argument_list, ArgumentIndices>::type(),
meta::get<typename traits::stack_index_list, ArgumentIndices>::value), 0)...
};
}
};
static int invoke(lua_State* L, function_object const& self, invoke_context& ctx, F& f) {
int const arguments = lua_gettop(L);
int score = no_match;
// Even match needs the tuple, since pointer_converters buffer the cast result
typename traits::argument_converter_tuple_type converter_tuple;
if(traits::arity == arguments) {
// Things to remember:
// 0 is the perfect match. match > 0 means that objects had to be casted, where the value
// is the total distance of all arguments to their given types (graph distance).
// This is why we can say MaxArguments = 100, MaxDerivationDepth = 100, so no match will be > 100*100=10k and -10k1 absorbs every match.
// This gets rid of the awkward checks during converter match traversal.
using struct_type = match_struct< typename traits::stack_index_list, typename traits::signature_list >;
score = struct_type::match(L, converter_tuple);
}
if(score >= 0 && score < ctx.best_score) {
ctx.best_score = score;
ctx.candidates[0] = &self;
ctx.candidate_index = 1;
} else if(score == ctx.best_score) {
ctx.candidates[ctx.candidate_index++] = &self;
}
int results = 0;
if(self.next)
{
results = self.next->call(L, ctx);
}
if(score == ctx.best_score && ctx.candidate_index == 1)
{
call_struct<
std::is_member_function_pointer<F>::value,
std::is_void<typename traits::result_type>::value,
typename traits::argument_index_list
>::call(L, f, converter_tuple);
results = lua_gettop(L) - traits::arity;
if(has_call_policy<PolicyList, yield_policy>::value) {
results = lua_yield(L, results);
}
call_detail_new::policy_list_postcall < PolicyList, typename meta::push_front< typename traits::stack_index_list, meta::index<traits::arity> >::type >::postcall(L, results);
}
return results;
}
};
template< typename PolicyList, typename Signature, typename F>
inline int invoke(lua_State* L, function_object const& self, invoke_context& ctx, F& f)
{
return invoke_struct<PolicyList, Signature, F>::invoke(L, self, ctx, f);
}
#endif
}
} // namespace luabind::detail
#if !BOOST_PP_IS_ITERATING
# ifndef LUABIND_CALL2_080911_HPP
# define LUABIND_CALL2_080911_HPP
# include <boost/mpl/apply_wrap.hpp>
# include <boost/mpl/begin_end.hpp>
# include <boost/mpl/deref.hpp>
# include <boost/mpl/front.hpp>
# include <boost/mpl/long.hpp>
# include <boost/mpl/size.hpp>
# include <boost/preprocessor/control/if.hpp>
# include <boost/preprocessor/iteration/iterate.hpp>
# include <boost/preprocessor/iteration/local.hpp>
# include <boost/preprocessor/repetition/enum.hpp>
# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
# include <boost/type_traits/is_void.hpp>
# include <luabind/config.hpp>
# include <luabind/detail/policy.hpp>
# include <luabind/yield_policy.hpp>
namespace luabind { namespace detail {
struct invoke_context;
struct LUABIND_API function_object
{
function_object(lua_CFunction entry)
: entry(entry)
, next(0)
{}
virtual ~function_object()
{}
virtual int call(
lua_State* L, invoke_context& ctx) const = 0;
virtual void format_signature(lua_State* L, char const* function) const = 0;
lua_CFunction entry;
std::string name;
function_object* next;
object keepalive;
};
struct LUABIND_API invoke_context
{
invoke_context()
: best_score((std::numeric_limits<int>::max)())
, candidate_index(0)
{}
operator bool() const
{
return candidate_index == 1;
}
void format_error(lua_State* L, function_object const* overloads) const;
int best_score;
function_object const* candidates[10];
int candidate_index;
};
template <class F, class Signature, class Policies, class IsVoid>
inline int invoke0(
lua_State* L, function_object const& self, invoke_context& ctx
, F const& f, Signature, Policies const& policies, IsVoid, mpl::true_)
{
return invoke_member(
L, self, ctx, f, Signature(), policies
, mpl::long_<mpl::size<Signature>::value - 1>(), IsVoid()
);
}
template <class F, class Signature, class Policies, class IsVoid>
inline int invoke0(
lua_State* L, function_object const& self, invoke_context& ctx,
F const& f, Signature, Policies const& policies, IsVoid, mpl::false_)
{
return invoke_normal(
L, self, ctx, f, Signature(), policies
, mpl::long_<mpl::size<Signature>::value - 1>(), IsVoid()
);
}
template <class F, class Signature, class Policies>
inline int invoke(
lua_State* L, function_object const& self, invoke_context& ctx
, F const& f, Signature, Policies const& policies)
{
return invoke0(
L, self, ctx, f, Signature(), policies
, boost::is_void<typename mpl::front<Signature>::type>()
, boost::is_member_function_pointer<F>()
);
}
inline int maybe_yield_aux(lua_State*, int results, mpl::false_)
{
return results;
}
inline int maybe_yield_aux(lua_State* L, int results, mpl::true_)
{
return lua_yield(L, results);
}
template <class Policies>
int maybe_yield(lua_State* L, int results, Policies*)
{
return maybe_yield_aux(
L, results, mpl::bool_<has_yield<Policies>::value>());
}
inline int sum_scores(int const* first, int const* last)
{
int result = 0;
for (; first != last; ++first)
{
if (*first < 0)
return *first;
result += *first;
}
return result;
}
# define LUABIND_INVOKE_NEXT_ITER(n) \
typename mpl::next< \
BOOST_PP_IF( \
n, BOOST_PP_CAT(iter,BOOST_PP_DEC(n)), first) \
>::type
# define LUABIND_INVOKE_NEXT_INDEX(n) \
BOOST_PP_IF( \
n \
, BOOST_PP_CAT(index,BOOST_PP_DEC(n)) + \
BOOST_PP_CAT(c,BOOST_PP_DEC(n)).consumed_args() \
, 1 \
)
# define LUABIND_INVOKE_COMPUTE_ARITY(n) + BOOST_PP_CAT(c,n).consumed_args()
# define LUABIND_INVOKE_DECLARE_CONVERTER(n) \
typedef LUABIND_INVOKE_NEXT_ITER(n) BOOST_PP_CAT(iter,n); \
typedef typename mpl::deref<BOOST_PP_CAT(iter,n)>::type \
BOOST_PP_CAT(a,n); \
typedef typename find_conversion_policy<n + 1, Policies>::type \
BOOST_PP_CAT(p,n); \
typename mpl::apply_wrap2< \
BOOST_PP_CAT(p,n), BOOST_PP_CAT(a,n), lua_to_cpp>::type BOOST_PP_CAT(c,n); \
int const BOOST_PP_CAT(index,n) = LUABIND_INVOKE_NEXT_INDEX(n);
# define LUABIND_INVOKE_COMPUTE_SCORE(n) \
, BOOST_PP_CAT(c,n).match( \
L, LUABIND_DECORATE_TYPE(BOOST_PP_CAT(a,n)), BOOST_PP_CAT(index,n))
# define LUABIND_INVOKE_ARG(z, n, base) \
BOOST_PP_CAT(c,base(n)).apply( \
L, LUABIND_DECORATE_TYPE(BOOST_PP_CAT(a,base(n))), BOOST_PP_CAT(index,base(n)))
# define LUABIND_INVOKE_CONVERTER_POSTCALL(n) \
BOOST_PP_CAT(c,n).converter_postcall( \
L, LUABIND_DECORATE_TYPE(BOOST_PP_CAT(a,n)), BOOST_PP_CAT(index,n));
# define BOOST_PP_ITERATION_PARAMS_1 \
(3, (0, LUABIND_MAX_ARITY, <luabind/detail/call.hpp>))
# include BOOST_PP_ITERATE()
# define LUABIND_INVOKE_VOID
# define BOOST_PP_ITERATION_PARAMS_1 \
(3, (0, LUABIND_MAX_ARITY, <luabind/detail/call.hpp>))
# include BOOST_PP_ITERATE()
# undef LUABIND_INVOKE_VOID
# define LUABIND_INVOKE_MEMBER
# define BOOST_PP_ITERATION_PARAMS_1 \
(3, (0, LUABIND_MAX_ARITY, <luabind/detail/call.hpp>))
# include BOOST_PP_ITERATE()
# define LUABIND_INVOKE_VOID
# define BOOST_PP_ITERATION_PARAMS_1 \
(3, (0, LUABIND_MAX_ARITY, <luabind/detail/call.hpp>))
# include BOOST_PP_ITERATE()
}} // namespace luabind::detail
# endif // LUABIND_CALL2_080911_HPP
#else // BOOST_PP_IS_ITERATING
# ifdef LUABIND_INVOKE_MEMBER
# define N BOOST_PP_INC(BOOST_PP_ITERATION())
# else
# define N BOOST_PP_ITERATION()
# endif
template <class F, class Signature, class Policies>
inline int
# ifdef LUABIND_INVOKE_MEMBER
invoke_member
# else
invoke_normal
# endif
(
lua_State* L, function_object const& self, invoke_context& ctx
, F const& f, Signature, Policies const&, mpl::long_<N>
# ifdef LUABIND_INVOKE_VOID
, mpl::true_
# else
, mpl::false_
# endif
)
{
typedef typename mpl::begin<Signature>::type first;
# ifndef LUABIND_INVOKE_VOID
typedef typename mpl::deref<first>::type result_type;
typedef typename find_conversion_policy<0, Policies>::type result_policy;
typename mpl::apply_wrap2<
result_policy, result_type, cpp_to_lua>::type result_converter;
# endif
# if N > 0
# define BOOST_PP_LOCAL_MACRO(n) LUABIND_INVOKE_DECLARE_CONVERTER(n)
# define BOOST_PP_LOCAL_LIMITS (0,N-1)
# include BOOST_PP_LOCAL_ITERATE()
# endif
int const arity = 0
# if N > 0
# define BOOST_PP_LOCAL_MACRO(n) LUABIND_INVOKE_COMPUTE_ARITY(n)
# define BOOST_PP_LOCAL_LIMITS (0,N-1)
# include BOOST_PP_LOCAL_ITERATE()
# endif
;
int const arguments = lua_gettop(L);
int score = -1;
if (arity == arguments)
{
int const scores[] = {
0
# if N > 0
# define BOOST_PP_LOCAL_MACRO(n) LUABIND_INVOKE_COMPUTE_SCORE(n)
# define BOOST_PP_LOCAL_LIMITS (0,N-1)
# include BOOST_PP_LOCAL_ITERATE()
# endif
};
score = sum_scores(scores + 1, scores + 1 + N);
}
if (score >= 0 && score < ctx.best_score)
{
ctx.best_score = score;
ctx.candidates[0] = &self;
ctx.candidate_index = 1;
}
else if (score == ctx.best_score)
{
ctx.candidates[ctx.candidate_index++] = &self;
}
int results = 0;
if (self.next)
{
results = self.next->call(L, ctx);
}
if (score == ctx.best_score && ctx.candidate_index == 1)
{
# ifndef LUABIND_INVOKE_VOID
result_converter.apply(
L,
# endif
# ifdef LUABIND_INVOKE_MEMBER
(c0.apply(L, LUABIND_DECORATE_TYPE(a0), index0).*f)(
BOOST_PP_ENUM(BOOST_PP_DEC(N), LUABIND_INVOKE_ARG, BOOST_PP_INC)
)
# else
# define LUABIND_INVOKE_IDENTITY(x) x
f(
BOOST_PP_ENUM(N, LUABIND_INVOKE_ARG, LUABIND_INVOKE_IDENTITY)
)
# undef LUABIND_INVOKE_IDENTITY
# endif
# ifndef LUABIND_INVOKE_VOID
)
# endif
;
# if N > 0
# define BOOST_PP_LOCAL_MACRO(n) LUABIND_INVOKE_CONVERTER_POSTCALL(n)
# define BOOST_PP_LOCAL_LIMITS (0,N-1)
# include BOOST_PP_LOCAL_ITERATE()
# endif
results = maybe_yield(L, lua_gettop(L) - arguments, (Policies*)0);
int const indices[] = {
arguments + results BOOST_PP_ENUM_TRAILING_PARAMS(N, index)
};
policy_list_postcall<Policies>::apply(L, indices);
}
return results;
}
# undef N
#endif
+373 -125
View File
@@ -20,175 +20,423 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#if !BOOST_PP_IS_ITERATING
#ifndef LUABIND_CALL_FUNCTION_HPP_INCLUDED
#define LUABIND_CALL_FUNCTION_HPP_INCLUDED
#include <luabind/config.hpp>
#include <boost/mpl/if.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/mpl/or.hpp>
#include <boost/preprocessor/repeat.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <luabind/error.hpp>
#include <luabind/detail/push_to_lua.hpp>
#include <luabind/detail/convert_to_lua.hpp>
#include <luabind/detail/pcall.hpp>
#include <luabind/detail/call_shared.hpp>
#include <luabind/detail/stack_utils.hpp>
namespace luabind
{
namespace adl {
class object;
}
namespace detail
{
using adl::object;
// if the proxy_function_caller returns non-void
template<class Ret, class Tuple>
class proxy_function_caller
{
// friend class luabind::object;
public:
namespace detail {
typedef int(*function_t)(lua_State*, int, int);
template< typename PolicyList, unsigned int pos >
void push_arguments(lua_State* /*L*/) {}
proxy_function_caller(
lua_State* L
, int params
, function_t fun
, const Tuple args)
: m_state(L)
, m_params(params)
, m_fun(fun)
, m_args(args)
, m_called(false)
{
}
template< typename PolicyList, unsigned int Pos, typename Arg0, typename... Args >
void push_arguments(lua_State* L, Arg0&& arg0, Args&&... args)
{
using converter_type = specialized_converter_policy< fetched_converter_policy<Pos, PolicyList>, Arg0, cpp_to_lua >;
converter_type().to_lua(L, unwrapped<Arg0>::get(std::forward<Arg0>(arg0)));
push_arguments<PolicyList, Pos + 1>(L, std::forward<Args>(args)...);
}
proxy_function_caller(const proxy_function_caller& rhs)
: m_state(rhs.m_state)
, m_params(rhs.m_params)
, m_fun(rhs.m_fun)
, m_args(rhs.m_args)
, m_called(rhs.m_called)
{
rhs.m_called = true;
}
#ifndef LUABIND_NO_INTERNAL_TAG_ARGUMENTS
template<typename Ret, typename PolicyList, typename... Args, unsigned int... Indices, typename Fn>
void call_function_impl(lua_State* L, int m_params, Fn fn, std::true_type /* void */, meta::index_list<Indices...>, Args&&... args)
{
int top = lua_gettop(L);
~proxy_function_caller()
{
if (m_called) return;
push_arguments<PolicyList, 1>(L, std::forward<Args>(args)...);
m_called = true;
lua_State* L = m_state;
if(fn(L, sizeof...(Args), 0)) {
assert(lua_gettop(L) == top - m_params + 1);
call_error(L);
}
// pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + m_params);
}
int top = lua_gettop(L);
template<typename Ret, typename PolicyList, typename... Args, unsigned int... Indices, typename Fn>
Ret call_function_impl(lua_State* L, int m_params, Fn fn, std::false_type /* void */, meta::index_list<Indices...>, Args&&... args)
{
int top = lua_gettop(L);
push_arguments<PolicyList, 1>(L, std::forward<Args>(args)...);
if(fn(L, sizeof...(Args), 1)) {
assert(lua_gettop(L) == top - m_params + 1);
call_error(L);
}
// pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + m_params);
specialized_converter_policy_n<0, PolicyList, Ret, lua_to_cpp> converter;
if(converter.match(L, decorate_type_t<Ret>(), -1) < 0) {
cast_error<Ret>(L);
}
return converter.to_cpp(L, decorate_type_t<Ret>(), -1);
}
push_args_from_tuple<1>::apply(L, m_args);
if (m_fun(L, boost::tuples::length<Tuple>::value, 0))
{
assert(lua_gettop(L) == top - m_params + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L);
#else
template<typename Ret, typename PolicyList, typename IndexList, unsigned int NumParams, int(*Function)(lua_State*, int, int), bool IsVoid = std::is_void<Ret>::value>
struct call_function_struct;
error_callback_fun e = get_error_callback();
if (e) e(L);
template<typename Ret, typename PolicyList, unsigned int NumParams, int(*Function)(lua_State*, int, int), unsigned int... Indices >
struct call_function_struct< Ret, PolicyList, meta::index_list<Indices...>, NumParams, Function, true /* void */ >
{
template< typename... Args >
static void call(lua_State* L, Args&&... args) {
int top = lua_gettop(L);
assert(0 && "the lua function threw an error and exceptions are disabled."
" If you want to handle the error you can use luabind::set_error_callback()");
std::terminate();
push_arguments<PolicyList, 1>(L, std::forward<Args>(args)...);
if(Function(L, sizeof...(Args), 0)) {
if(Function == &detail::pcall) {
assert(lua_gettop(L) == static_cast<int>(top - NumParams + 1));
#endif
}
call_error(L);
// pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + m_params);
}
// pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + NumParams);
}
};
template<typename Ret, typename PolicyList, unsigned int NumParams, int(*Function)(lua_State*, int, int), unsigned int... Indices >
struct call_function_struct< Ret, PolicyList, meta::index_list<Indices...>, NumParams, Function, false /* void */ >
{
template< typename... Args >
static Ret call(lua_State* L, Args&&... args) {
int top = lua_gettop(L);
operator Ret()
{
typename mpl::apply_wrap2<default_policy,Ret,lua_to_cpp>::type converter;
push_arguments<PolicyList, 1>(L, std::forward<Args>(args)...);
m_called = true;
lua_State* L = m_state;
if(Function(L, sizeof...(Args), 1)) {
if(Function == &detail::pcall) {
assert(lua_gettop(L) == static_cast<int>(top - NumParams + 1));
int top = lua_gettop(L);
push_args_from_tuple<1>::apply(L, m_args);
if (m_fun(L, boost::tuples::length<Tuple>::value, 1))
{
assert(lua_gettop(L) == top - m_params + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L);
#else
error_callback_fun e = get_error_callback();
if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled."
" If you want to handle the error you can use luabind::set_error_callback()");
std::terminate();
#endif
}
call_error(L);
}
// pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + NumParams);
specialized_converter_policy_n<0, PolicyList, Ret, lua_to_cpp> converter;
if(converter.match(L, decorate_type_t<Ret>(), -1) < 0) {
cast_error<Ret>(L);
// pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + m_params);
#ifndef LUABIND_NO_ERROR_CHECKING
if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
{
#ifndef LUABIND_NO_EXCEPTIONS
throw cast_failed(L, typeid(Ret));
#else
cast_failed_callback_fun e = get_cast_failed_callback();
if (e) e(L, typeid(Ret));
assert(0 && "the lua function's return value could not be converted."
" If you want to handle the error you can use luabind::set_error_callback()");
std::terminate();
#endif
}
#endif
return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
}
return converter.to_cpp(L, decorate_type_t<Ret>(), -1);
}
};
#endif
}
template<class Policies>
Ret operator[](const Policies& p)
{
typedef typename detail::find_conversion_policy<0, Policies>::type converter_policy;
typename mpl::apply_wrap2<converter_policy,Ret,lua_to_cpp>::type converter;
template<class R, typename PolicyList = no_policies, typename... Args>
R call_pushed_function(lua_State* L, Args&&... args)
{
#ifndef LUABIND_NO_INTERNAL_TAG_ARGUMENTS
return detail::call_function_impl<R, PolicyList>(L, 1, &detail::pcall, std::is_void<R>(), meta::index_range<1, sizeof...(Args)+1>(), std::forward<Args>(args)...);
m_called = true;
lua_State* L = m_state;
int top = lua_gettop(L);
detail::push_args_from_tuple<1>::apply(L, m_args, p);
if (m_fun(L, boost::tuples::length<Tuple>::value, 1))
{
assert(lua_gettop(L) == top - m_params + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw error(L);
#else
return detail::call_function_struct<R, PolicyList, meta::index_range<1, sizeof...(Args)+1>, 1, &detail::pcall >::call(L, std::forward<Args>(args)...);
error_callback_fun e = get_error_callback();
if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled."
" If you want to handle the error you can use luabind::set_error_callback()");
std::terminate();
#endif
}
}
template<class R, typename PolicyList = no_policies, typename... Args>
R call_function(lua_State* L, const char* name, Args&&... args)
{
assert(name && "luabind::call_function() expects a function name");
lua_getglobal(L, name);
return call_pushed_function<R, PolicyList>(L, std::forward<Args>(args)...);
}
// pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + m_params);
template<class R, typename PolicyList = no_policies, typename... Args>
R resume_pushed_function(lua_State* L, Args&&... args)
{
#ifndef LUABIND_NO_INTERNAL_TAG_ARGUMENTS
return detail::call_function_impl<R, PolicyList>(L, 1, &detail::resume_impl, std::is_void<R>(), meta::index_range<1, sizeof...(Args)+1>(), std::forward<Args>(args)...);
#ifndef LUABIND_NO_ERROR_CHECKING
if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
{
#ifndef LUABIND_NO_EXCEPTIONS
throw cast_failed(L, typeid(Ret));
#else
return detail::call_function_struct<R, PolicyList, meta::index_range<1, sizeof...(Args)+1>, 1, &detail::resume_impl >::call(L, std::forward<Args>(args)...);
cast_failed_callback_fun e = get_cast_failed_callback();
if (e) e(L, typeid(Ret));
assert(0 && "the lua function's return value could not be converted."
" If you want to handle the error you can use luabind::set_error_callback()");
std::terminate();
#endif
}
}
#endif
return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
}
template<class R, typename PolicyList = no_policies, typename... Args>
R resume_function(lua_State* L, const char* name, Args&&... args)
{
assert(name && "luabind::resume_function() expects a function name");
lua_getglobal(L, name);
return resume_pushed_function<R, PolicyList>(L, std::forward<Args>(args)...);
}
private:
template<class R, typename PolicyList = no_policies, typename... Args>
R resume(lua_State* L, Args&&... args)
{
#ifndef LUABIND_NO_INTERNAL_TAG_ARGUMENTS
return detail::call_function_impl<R, PolicyList>(L, 0, &detail::resume_impl, std::is_void<R>(), meta::index_range<1, sizeof...(Args)+1>(), std::forward<Args>(args)...);
lua_State* m_state;
int m_params;
function_t m_fun;
Tuple m_args;
mutable bool m_called;
};
// if the proxy_member_caller returns void
template<class Tuple>
class proxy_function_void_caller
{
friend class luabind::object;
public:
typedef int(*function_t)(lua_State*, int, int);
proxy_function_void_caller(
lua_State* L
, int params
, function_t fun
, const Tuple args)
: m_state(L)
, m_params(params)
, m_fun(fun)
, m_args(args)
, m_called(false)
{
}
proxy_function_void_caller(const proxy_function_void_caller& rhs)
: m_state(rhs.m_state)
, m_params(rhs.m_params)
, m_fun(rhs.m_fun)
, m_args(rhs.m_args)
, m_called(rhs.m_called)
{
rhs.m_called = true;
}
~proxy_function_void_caller()
{
if (m_called) return;
m_called = true;
lua_State* L = m_state;
int top = lua_gettop(L);
push_args_from_tuple<1>::apply(L, m_args);
if (m_fun(L, boost::tuples::length<Tuple>::value, 0))
{
assert(lua_gettop(L) == top - m_params + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L);
#else
return detail::call_function_struct<R, PolicyList, meta::index_range<1, sizeof...(Args)+1>, 0, &detail::resume_impl >::call(L, std::forward<Args>(args)...);
error_callback_fun e = get_error_callback();
if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled."
" If you want to handle the error you can use luabind::set_error_callback()");
std::terminate();
#endif
}
// pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + m_params);
}
template<class Policies>
void operator[](const Policies& p)
{
m_called = true;
lua_State* L = m_state;
int top = lua_gettop(L);
detail::push_args_from_tuple<1>::apply(L, m_args, p);
if (m_fun(L, boost::tuples::length<Tuple>::value, 0))
{
assert(lua_gettop(L) == top - m_params + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw error(L);
#else
error_callback_fun e = get_error_callback();
if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled."
" If you want to handle the error you can use luabind::set_error_callback()");
std::terminate();
#endif
}
// pops the return values from the function call
stack_pop pop(L, lua_gettop(L) - top + m_params);
}
private:
lua_State* m_state;
int m_params;
function_t m_fun;
Tuple m_args;
mutable bool m_called;
};
}
#define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/detail/call_function.hpp>, 1))
#include BOOST_PP_ITERATE()
}
#endif // LUABIND_CALL_FUNCTION_HPP_INCLUDED
#else
#if BOOST_PP_ITERATION_FLAGS() == 1
#define LUABIND_TUPLE_PARAMS(z, n, data) const A##n *
#define LUABIND_OPERATOR_PARAMS(z, n, data) const A##n & a##n
template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
call_function(lua_State* L, const char* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
{
assert(name && "luabind::call_function() expects a function name");
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
#if BOOST_PP_ITERATION() == 0
tuple_t args;
#else
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
#endif
typedef typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
lua_getglobal(L, name);
return proxy_type(L, 1, &detail::pcall, args);
}
template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
call_function(luabind::object const& obj BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
{
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
#if BOOST_PP_ITERATION() == 0
tuple_t args;
#else
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
#endif
typedef typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
obj.push(obj.interpreter());
return proxy_type(obj.interpreter(), 1, &detail::pcall, args);
}
template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
resume_function(lua_State* L, const char* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
{
assert(name && "luabind::resume_function() expects a function name");
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
#if BOOST_PP_ITERATION() == 0
tuple_t args;
#else
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
#endif
typedef typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
lua_getglobal(L, name);
return proxy_type(L, 1, &detail::resume_impl, args);
}
template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
resume_function(luabind::object const& obj BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
{
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
#if BOOST_PP_ITERATION() == 0
tuple_t args;
#else
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
#endif
typedef typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
obj.push(obj.interpreter());
return proxy_type(obj.interpreter(), 1, &detail::resume_impl, args);
}
template<class Ret BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
resume(lua_State* L BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
{
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
#if BOOST_PP_ITERATION() == 0
tuple_t args;
#else
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
#endif
typedef typename boost::mpl::if_<boost::is_void<Ret>
, luabind::detail::proxy_function_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_function_caller<Ret, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
return proxy_type(L, 0, &detail::resume_impl, args);
}
#undef LUABIND_OPERATOR_PARAMS
#undef LUABIND_TUPLE_PARAMS
#endif
#endif
+299 -61
View File
@@ -20,82 +20,325 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#if !BOOST_PP_IS_ITERATING
#ifndef LUABIND_CALL_MEMBER_HPP_INCLUDED
#define LUABIND_CALL_MEMBER_HPP_INCLUDED
#include <luabind/config.hpp>
#include <luabind/detail/push_to_lua.hpp>
#include <luabind/detail/convert_to_lua.hpp>
#include <luabind/detail/pcall.hpp>
#include <luabind/error.hpp>
#include <luabind/detail/stack_utils.hpp>
#include <luabind/detail/call_shared.hpp>
#include <luabind/object.hpp>
#include <luabind/object.hpp> // TODO: REMOVE DEPENDENCY
#include <boost/tuple/tuple.hpp>
#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/facilities/expand.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#include <boost/mpl/apply_wrap.hpp>
namespace luabind
{
using adl::object;
namespace detail
{
namespace detail {
namespace mpl = boost::mpl;
template<class R, typename PolicyList, unsigned int... Indices, typename... Args>
R call_member_impl(lua_State* L, std::true_type /*void*/, meta::index_list<Indices...>, Args&&... args)
{
// don't count the function and self-reference
// since those will be popped by pcall
int top = lua_gettop(L) - 2;
// if the proxy_member_caller returns non-void
template<class Ret, class Tuple>
class proxy_member_caller
{
// friend class luabind::object;
public:
// pcall will pop the function and self reference
// and all the parameters
proxy_member_caller(lua_State* L_, const Tuple args)
: L(L_)
, m_args(args)
, m_called(false)
{
}
proxy_member_caller(const proxy_member_caller& rhs)
: L(rhs.L)
, m_args(rhs.m_args)
, m_called(rhs.m_called)
{
rhs.m_called = true;
}
~proxy_member_caller()
{
if (m_called) return;
m_called = true;
// don't count the function and self-reference
// since those will be popped by pcall
int top = lua_gettop(L) - 2;
// pcall will pop the function and self reference
// and all the parameters
push_args_from_tuple<1>::apply(L, m_args);
if (pcall(L, boost::tuples::length<Tuple>::value + 1, 0))
{
assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L);
#else
error_callback_fun e = get_error_callback();
if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled."
"If you want to handle this error use luabind::set_error_callback()");
std::terminate();
#endif
}
// pops the return values from the function
stack_pop pop(L, lua_gettop(L) - top);
}
operator Ret()
{
typename mpl::apply_wrap2<default_policy,Ret,lua_to_cpp>::type converter;
m_called = true;
// don't count the function and self-reference
// since those will be popped by pcall
int top = lua_gettop(L) - 2;
// pcall will pop the function and self reference
// and all the parameters
push_args_from_tuple<1>::apply(L, m_args);
if (pcall(L, boost::tuples::length<Tuple>::value + 1, 1))
{
assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L);
#else
error_callback_fun e = get_error_callback();
if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled."
"If you want to handle this error use luabind::set_error_callback()");
std::terminate();
#endif
}
// pops the return values from the function
stack_pop pop(L, lua_gettop(L) - top);
#ifndef LUABIND_NO_ERROR_CHECKING
if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
{
assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw cast_failed(L, typeid(Ret));
#else
cast_failed_callback_fun e = get_cast_failed_callback();
if (e) e(L, typeid(Ret));
assert(0 && "the lua function's return value could not be converted."
"If you want to handle this error use luabind::set_error_callback()");
std::terminate();
#endif
}
#endif
return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
}
template<class Policies>
Ret operator[](const Policies& p)
{
typedef typename find_conversion_policy<0, Policies>::type converter_policy;
typename mpl::apply_wrap2<converter_policy,Ret,lua_to_cpp>::type converter;
m_called = true;
// don't count the function and self-reference
// since those will be popped by pcall
int top = lua_gettop(L) - 2;
// pcall will pop the function and self reference
// and all the parameters
detail::push_args_from_tuple<1>::apply(L, m_args, p);
if (pcall(L, boost::tuples::length<Tuple>::value + 1, 1))
{
assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw error(L);
#else
error_callback_fun e = get_error_callback();
if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled."
"If you want to handle this error use luabind::set_error_callback()");
std::terminate();
#endif
}
// pops the return values from the function
stack_pop pop(L, lua_gettop(L) - top);
#ifndef LUABIND_NO_ERROR_CHECKING
if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
{
assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw cast_failed(L, typeid(Ret));
#else
cast_failed_callback_fun e = get_cast_failed_callback();
if (e) e(L, typeid(Ret));
assert(0 && "the lua function's return value could not be converted."
"If you want to handle this error use luabind::set_error_callback()");
std::terminate();
#endif
}
#endif
return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
}
private:
lua_State* L;
Tuple m_args;
mutable bool m_called;
meta::init_order{ (
specialized_converter_policy_n<Indices, PolicyList, typename unwrapped<Args>::type, cpp_to_lua>().to_lua(L, unwrapped<Args>::get(std::forward<Args>(args))), 0)...
};
if(pcall(L, sizeof...(Args)+1, 0))
// if the proxy_member_caller returns void
template<class Tuple>
class proxy_member_void_caller
{
assert(lua_gettop(L) == top + 1);
call_error(L);
}
// pops the return values from the function
stack_pop pop(L, lua_gettop(L) - top);
}
friend class luabind::object;
public:
template<class R, typename PolicyList, unsigned int... Indices, typename... Args>
R call_member_impl(lua_State* L, std::false_type /*void*/, meta::index_list<Indices...>, Args&&... args)
{
// don't count the function and self-reference
// since those will be popped by pcall
int top = lua_gettop(L) - 2;
proxy_member_void_caller(lua_State* L_, const Tuple args)
: L(L_)
, m_args(args)
, m_called(false)
{
}
// pcall will pop the function and self reference
// and all the parameters
proxy_member_void_caller(const proxy_member_void_caller& rhs)
: L(rhs.L)
, m_args(rhs.m_args)
, m_called(rhs.m_called)
{
rhs.m_called = true;
}
~proxy_member_void_caller()
{
if (m_called) return;
m_called = true;
// don't count the function and self-reference
// since those will be popped by pcall
int top = lua_gettop(L) - 2;
// pcall will pop the function and self reference
// and all the parameters
push_args_from_tuple<1>::apply(L, m_args);
if (pcall(L, boost::tuples::length<Tuple>::value + 1, 0))
{
assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw luabind::error(L);
#else
error_callback_fun e = get_error_callback();
if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled."
"If you want to handle this error use luabind::set_error_callback()");
std::terminate();
#endif
}
// pops the return values from the function
stack_pop pop(L, lua_gettop(L) - top);
}
template<class Policies>
void operator[](const Policies& p)
{
m_called = true;
// don't count the function and self-reference
// since those will be popped by pcall
int top = lua_gettop(L) - 2;
// pcall will pop the function and self reference
// and all the parameters
detail::push_args_from_tuple<1>::apply(L, m_args, p);
if (pcall(L, boost::tuples::length<Tuple>::value + 1, 0))
{
assert(lua_gettop(L) == top + 1);
#ifndef LUABIND_NO_EXCEPTIONS
throw error(L);
#else
error_callback_fun e = get_error_callback();
if (e) e(L);
assert(0 && "the lua function threw an error and exceptions are disabled."
"If you want to handle this error use luabind::set_error_callback()");
std::terminate();
#endif
}
// pops the return values from the function
stack_pop pop(L, lua_gettop(L) - top);
}
private:
lua_State* L;
Tuple m_args;
mutable bool m_called;
meta::init_order{ (
specialized_converter_policy_n<Indices, PolicyList, typename unwrapped<Args>::type, cpp_to_lua>().to_lua(L, unwrapped<Args>::get(std::forward<Args>(args))), 0)...
};
if(pcall(L, sizeof...(Args)+1, 1))
{
assert(lua_gettop(L) == top + 1);
call_error(L);
}
// pops the return values from the function
stack_pop pop(L, lua_gettop(L) - top);
specialized_converter_policy_n<0, PolicyList, R, lua_to_cpp> converter;
if(converter.match(L, decorate_type_t<R>(), -1) < 0) {
cast_error<R>(L);
}
return converter.to_cpp(L, decorate_type_t<R>(), -1);
}
} // detail
template<class R, typename PolicyList = no_policies, typename... Args>
R call_member(object const& obj, const char* name, Args&&... args)
#define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, <luabind/detail/call_member.hpp>, 1))
#include BOOST_PP_ITERATE()
}
#endif // LUABIND_CALL_MEMBER_HPP_INCLUDED
#else
#if BOOST_PP_ITERATION_FLAGS() == 1
#define LUABIND_TUPLE_PARAMS(z, n, data) const A##n *
#define LUABIND_OPERATOR_PARAMS(z, n, data) const A##n & a##n
template<class R BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A)>
typename boost::mpl::if_<boost::is_void<R>
, luabind::detail::proxy_member_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_member_caller<R, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type
call_member(object const& obj, const char* name BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _))
{
typedef boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> tuple_t;
#if BOOST_PP_ITERATION() == 0
tuple_t args;
#else
tuple_t args(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), &a));
#endif
typedef typename boost::mpl::if_<boost::is_void<R>
, luabind::detail::proxy_member_void_caller<boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> >
, luabind::detail::proxy_member_caller<R, boost::tuples::tuple<BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_TUPLE_PARAMS, _)> > >::type proxy_type;
// this will be cleaned up by the proxy object
// once the call has been made
@@ -111,17 +354,12 @@ namespace luabind
// now the function and self objects
// are on the stack. These will both
// be popped by pcall
return detail::call_member_impl<R, PolicyList>(obj.interpreter(), std::is_void<R>(), meta::index_range<1, sizeof...(Args)+1>(), std::forward<Args>(args)...);
return proxy_type(obj.interpreter(), args);
}
template <class R, typename... Args>
R call_member(wrap_base const* self, char const* fn, Args&&... args)
{
return self->call<R>(fn, std::forward<Args>(args)...);
}
#undef LUABIND_OPERATOR_PARAMS
#undef LUABIND_TUPLE_PARAMS
}
#endif // LUABIND_CALL_MEMBER_HPP_INCLUDED
#endif
#endif
@@ -0,0 +1,66 @@
// Copyright (c) 2004 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#define N BOOST_PP_ITERATION()
#define LUABIND_UNWRAP_PARAMETER(z, n, _) \
typename detail::unwrap_parameter_type<T, BOOST_PP_CAT(A, n)>::type \
BOOST_PP_CAT(_, n)
template<class Self BOOST_PP_ENUM_TRAILING_PARAMS(N, class A)>
struct BOOST_PP_CAT(call_operator, N)
: detail::operator_<
BOOST_PP_CAT(call_operator, N)<
Self BOOST_PP_ENUM_TRAILING_PARAMS(N, A)
>
>
{
BOOST_PP_CAT(call_operator, N)(int) {}
template<class T, class Policies>
struct apply
{
static void execute(
lua_State* L
, typename detail::unwrap_parameter_type<T, Self>::type self
BOOST_PP_ENUM_TRAILING(N, LUABIND_UNWRAP_PARAMETER, _)
)
{
using namespace detail;
operator_result(
L
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
, self(BOOST_PP_ENUM_PARAMS(N, _))
#else
, (self(BOOST_PP_ENUM_PARAMS(N, _)), detail::operator_void_return())
#endif
, (Policies*)0
);
}
};
static char const* name() { return "__call"; }
};
#undef LUABIND_UNWRAP_PARAMETER
#undef N
-113
View File
@@ -1,113 +0,0 @@
// This has been stripped from boost minus the compatibility for borland etc.
// (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
// Use, modification and distribution are subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt).
//
// See http://www.boost.org/libs/utility for most recent version including documentation.
// call_traits: defines typedefs for function usage
// (see libs/utility/call_traits.htm)
/* Release notes:
23rd July 2000:
Fixed array specialization. (JM)
Added Borland specific fixes for reference types
(issue raised by Steve Cleary).
*/
#ifndef LUABIND_CALL_TRAITS_HPP_INCLUDED
#define LUABIND_CALL_TRAITS_HPP_INCLUDED
namespace luabind {
namespace detail {
template <typename T, bool small_>
struct ct_imp2
{
using param_type = const T&;
};
template <typename T>
struct ct_imp2<T, true>
{
using param_type = const T;
};
template <typename T, bool isp, bool b1, bool b2>
struct ct_imp
{
using param_type = const T&;
};
template <typename T, bool isp, bool b2>
struct ct_imp<T, isp, true, b2>
{
using param_type = typename ct_imp2<T, sizeof(T) <= sizeof(void*)>::param_type;
};
template <typename T, bool isp, bool b1>
struct ct_imp<T, isp, b1, true>
{
using param_type = typename ct_imp2<T, sizeof(T) <= sizeof(void*)>::param_type;
};
template <typename T, bool b1, bool b2>
struct ct_imp<T, true, b1, b2>
{
using param_type = const T;
};
template <typename T>
struct call_traits
{
public:
using value_type = T;
using reference = T&;
using const_reference = const T&;
using param_type = typename ct_imp<
T,
std::is_pointer<T>::value,
std::is_integral<T>::value || std::is_floating_point<T>::value,
std::is_enum<T>::value
>::param_type;
};
template <typename T>
struct call_traits<T&>
{
using value_type = T&;
using reference = T&;
using const_reference = const T&;
using param_type = T&;
};
template <typename T, std::size_t N>
struct call_traits<T[N]>
{
private:
using array_type = T[N];
public:
using value_type = const T*;
using reference = array_type&;
using const_reference = const array_type&;
using param_type = const T* const;
};
template <typename T, std::size_t N>
struct call_traits<const T[N]>
{
private:
using array_type = const T[N];
public:
using value_type = const T*;
using reference = array_type&;
using const_reference = const array_type&;
using param_type = const T* const;
};
}
}
#endif
@@ -0,0 +1,89 @@
// Copyright (c) 2004 Daniel Wallin
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef CLASS_CACHE_040218_HPP
#define CLASS_CACHE_040218_HPP
#include <luabind/prefix.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/add_const.hpp>
namespace luabind { namespace detail {
#ifdef LUABIND_NOT_THREADSAFE
class class_rep;
template<class T>
struct class_cache_impl
{
static lua_State* state;
static class_rep* class_;
};
template<class T>
lua_State* class_cache_impl<T>::state = 0;
template<class T>
class_rep* class_cache_impl<T>::class_ = 0;
template<class T>
struct class_cache
: class_cache_impl<
typename boost::add_reference<
typename boost::add_const<
T
>::type
>::type
>
{
};
template<class T>
class_rep* get_class_rep(lua_State* L, void(*)(T*) = 0)
{
if (class_cache<T>::state != L)
{
class_cache<T>::state = L;
class_registry* registry = class_registry::get_registry(L);
class_cache<T>::class_ = registry->find_class(typeid(T));
}
return class_cache<T>::class_;
}
#else
template<class T>
class_rep* get_class_rep(lua_State* L, void(*)(T*) = 0)
{
class_registry* registry = class_registry::get_registry(L);
return registry->find_class(typeid(T));
}
#endif
}} // namespace luabind::detail
#endif // CLASS_CACHE_040218_HPP
+35 -37
View File
@@ -30,58 +30,56 @@
#include <luabind/open.hpp>
#include <luabind/typeid.hpp>
namespace luabind {
namespace detail {
namespace luabind { namespace detail
{
class class_rep;
class class_rep;
struct LUABIND_API class_registry
{
class_registry(lua_State* L);
struct LUABIND_API class_registry
{
class_registry(lua_State* L);
static class_registry* get_registry(lua_State* L);
static class_registry* get_registry(lua_State* L);
int cpp_instance() const { return m_instance_metatable; }
int cpp_class() const { return m_cpp_class_metatable; }
int cpp_instance() const { return m_instance_metatable; }
int cpp_class() const { return m_cpp_class_metatable; }
int lua_instance() const { return m_instance_metatable; }
int lua_class() const { return m_lua_class_metatable; }
int lua_function() const { return m_lua_function_metatable; }
int lua_instance() const { return m_instance_metatable; }
int lua_class() const { return m_lua_class_metatable; }
int lua_function() const { return m_lua_function_metatable; }
void add_class(type_id const& info, class_rep* crep);
void add_class(type_id const& info, class_rep* crep);
class_rep* find_class(type_id const& info) const;
class_rep* find_class(type_id const& info) const;
std::map<type_id, class_rep*> const& get_classes() const
{
return m_classes;
}
std::map<type_id, class_rep*> const& get_classes() const
{
return m_classes;
}
private:
private:
std::map<type_id, class_rep*> m_classes;
std::map<type_id, class_rep*> m_classes;
// this is a lua reference that points to the lua table
// that is to be used as meta table for all C++ class
// instances. It is a kind of v-table.
int m_instance_metatable;
// this is a lua reference that points to the lua table
// that is to be used as meta table for all C++ class
// instances. It is a kind of v-table.
int m_instance_metatable;
// this is a lua reference to the metatable to be used
// for all classes defined in C++.
int m_cpp_class_metatable;
// this is a lua reference to the metatable to be used
// for all classes defined in C++.
int m_cpp_class_metatable;
// this is a lua reference to the metatable to be used
// for all classes defined in lua
int m_lua_class_metatable;
// this is a lua reference to the metatable to be used
// for all classes defined in lua
int m_lua_class_metatable;
// this metatable only contains a destructor
// for luabind::Detail::free_functions::function_rep
int m_lua_function_metatable;
// this metatable only contains a destructor
// for luabind::Detail::free_functions::function_rep
int m_lua_function_metatable;
};
};
}
}
}}
#endif // LUABIND_CLASS_REGISTRY_HPP_INCLUDED
+160 -159
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2003 Daniel Wallin and Arvid Norberg
// Copyright (c) 2003 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
@@ -24,12 +24,16 @@
#ifndef LUABIND_CLASS_REP_HPP_INCLUDED
#define LUABIND_CLASS_REP_HPP_INCLUDED
#include <boost/limits.hpp>
#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
#include <string>
#include <utility>
#include <vector>
#include <luabind/config.hpp>
#include <luabind/lua_include.hpp>
#include <luabind/detail/object_rep.hpp>
#include <luabind/detail/garbage_collector.hpp>
#include <luabind/detail/operator_id.hpp>
#include <luabind/detail/class_registry.hpp>
@@ -39,174 +43,171 @@
#include <luabind/typeid.hpp>
#include <luabind/detail/ref.hpp>
namespace luabind {
namespace detail {
namespace luabind { namespace detail
{
LUABIND_API std::string stack_content_by_name(lua_State* L, int start_index);
LUABIND_API std::string stack_content_by_name(lua_State* L, int start_index);
struct class_registration;
struct class_registration;
struct conversion_storage;
struct conversion_storage;
// This function is used as a tag to identify "properties".
LUABIND_API int property_tag(lua_State*);
// This function is used as a tag to identify "properties".
LUABIND_API int property_tag(lua_State*);
// this is class-specific information, poor man's vtable
// this is allocated statically (removed by the compiler)
// a pointer to this structure is stored in the lua tables'
// metatable with the name __classrep
// it is used when matching parameters to function calls
// to determine possible implicit casts
// it is also used when finding the best match for overloaded
// methods
// this is class-specific information, poor man's vtable
// this is allocated statically (removed by the compiler)
// a pointer to this structure is stored in the lua tables'
// metatable with the name __classrep
// it is used when matching parameters to function calls
// to determine possible implicit casts
// it is also used when finding the best match for overloaded
// methods
class cast_graph;
class class_id_map;
class cast_graph;
class class_id_map;
class LUABIND_API class_rep
class LUABIND_API class_rep
{
friend struct class_registration;
friend int super_callback(lua_State*);
//TODO: avoid the lua-prefix
friend int lua_class_gettable(lua_State*);
friend int lua_class_settable(lua_State*);
friend int static_class_gettable(lua_State*);
public:
enum class_type
{
friend struct class_registration;
friend int super_callback(lua_State*);
//TODO: avoid the lua-prefix
friend int lua_class_gettable(lua_State*);
friend int lua_class_settable(lua_State*);
friend int static_class_gettable(lua_State*);
public:
enum class_type
{
cpp_class = 0,
lua_class = 1
};
// EXPECTS THE TOP VALUE ON THE LUA STACK TO
// BE THE USER DATA WHERE THIS CLASS IS BEING
// INSTANTIATED!
class_rep(type_id const& type
, const char* name
, lua_State* L
);
// used when creating a lua class
// EXPECTS THE TOP VALUE ON THE LUA STACK TO
// BE THE USER DATA WHERE THIS CLASS IS BEING
// INSTANTIATED!
class_rep(lua_State* L, const char* name);
~class_rep();
std::pair<void*, void*> allocate(lua_State* L) const;
// this is called as metamethod __call on the class_rep.
static int constructor_dispatcher(lua_State* L);
struct base_info
{
int pointer_offset; // the offset added to the pointer to obtain a basepointer (due to multiple-inheritance)
class_rep* base;
};
void add_base_class(const base_info& binfo);
const std::vector<base_info>& bases() const throw() { return m_bases; }
void set_type(type_id const& t) { m_type = t; }
type_id const& type() const throw() { return m_type; }
const char* name() const throw() { return m_name; }
// the lua reference to the metatable for this class' instances
int metatable_ref() const throw() { return m_instance_metatable; }
void get_table(lua_State* L) const { m_table.push(L); }
void get_default_table(lua_State* L) const { m_default_table.push(L); }
class_type get_class_type() const { return m_class_type; }
void add_static_constant(const char* name, int val);
static int super_callback(lua_State* L);
static int lua_settable_dispatcher(lua_State* L);
// called from the metamethod for __index
// obj is the object pointer
static int static_class_gettable(lua_State* L);
bool has_operator_in_lua(lua_State*, int id);
cast_graph const& casts() const
{
return *m_casts;
}
class_id_map const& classes() const
{
return *m_classes;
}
private:
// Code common to both constructors
void shared_init(lua_State * L);
void cache_operators(lua_State*);
// this is a pointer to the type_info structure for
// this type
// warning: this may be a problem when using dll:s, since
// typeid() may actually return different pointers for the same
// type.
type_id m_type;
// a list of info for every class this class derives from
// the information stored here is sufficient to do
// type casts to the base classes
std::vector<base_info> m_bases;
// the class' name (as given when registered to lua with class_)
const char* m_name;
// a reference to this structure itself. Since this struct
// is kept inside lua (to let lua collect it when lua_close()
// is called) we need to lock it to prevent collection.
// the actual reference is not currently used.
detail::lua_reference m_self_ref;
// this should always be used when accessing
// members in instances of a class.
// this table contains c closures for all
// member functions in this class, they
// may point to both static and virtual functions
handle m_table;
// this table contains default implementations of the
// virtual functions in m_table.
handle m_default_table;
// the type of this class.. determines if it's written in c++ or lua
class_type m_class_type;
// this is a lua reference that points to the lua table
// that is to be used as meta table for all instances
// of this class.
int m_instance_metatable;
std::map<const char*, int, ltstr> m_static_constants;
// the first time an operator is invoked
// we check the associated lua table
// and cache the result
int m_operator_cache;
cast_graph* m_casts;
class_id_map* m_classes;
cpp_class = 0,
lua_class = 1
};
LUABIND_API bool is_class_rep(lua_State* L, int index);
// EXPECTS THE TOP VALUE ON THE LUA STACK TO
// BE THE USER DATA WHERE THIS CLASS IS BEING
// INSTANTIATED!
class_rep(type_id const& type
, const char* name
, lua_State* L
);
}
}
// used when creating a lua class
// EXPECTS THE TOP VALUE ON THE LUA STACK TO
// BE THE USER DATA WHERE THIS CLASS IS BEING
// INSTANTIATED!
class_rep(lua_State* L, const char* name);
~class_rep();
std::pair<void*,void*> allocate(lua_State* L) const;
// this is called as metamethod __call on the class_rep.
static int constructor_dispatcher(lua_State* L);
struct base_info
{
int pointer_offset; // the offset added to the pointer to obtain a basepointer (due to multiple-inheritance)
class_rep* base;
};
void add_base_class(const base_info& binfo);
const std::vector<base_info>& bases() const throw() { return m_bases; }
void set_type(type_id const& t) { m_type = t; }
type_id const& type() const throw() { return m_type; }
const char* name() const throw() { return m_name; }
// the lua reference to the metatable for this class' instances
int metatable_ref() const throw() { return m_instance_metatable; }
void get_table(lua_State* L) const { m_table.push(L); }
void get_default_table(lua_State* L) const { m_default_table.push(L); }
class_type get_class_type() const { return m_class_type; }
void add_static_constant(const char* name, int val);
static int super_callback(lua_State* L);
static int lua_settable_dispatcher(lua_State* L);
// called from the metamethod for __index
// obj is the object pointer
static int static_class_gettable(lua_State* L);
bool has_operator_in_lua(lua_State*, int id);
cast_graph const& casts() const
{
return *m_casts;
}
class_id_map const& classes() const
{
return *m_classes;
}
private:
void cache_operators(lua_State*);
// this is a pointer to the type_info structure for
// this type
// warning: this may be a problem when using dll:s, since
// typeid() may actually return different pointers for the same
// type.
type_id m_type;
// a list of info for every class this class derives from
// the information stored here is sufficient to do
// type casts to the base classes
std::vector<base_info> m_bases;
// the class' name (as given when registered to lua with class_)
const char* m_name;
// a reference to this structure itself. Since this struct
// is kept inside lua (to let lua collect it when lua_close()
// is called) we need to lock it to prevent collection.
// the actual reference is not currently used.
detail::lua_reference m_self_ref;
// this should always be used when accessing
// members in instances of a class.
// this table contains c closures for all
// member functions in this class, they
// may point to both static and virtual functions
handle m_table;
// this table contains default implementations of the
// virtual functions in m_table.
handle m_default_table;
// the type of this class.. determines if it's written in c++ or lua
class_type m_class_type;
// this is a lua reference that points to the lua table
// that is to be used as meta table for all instances
// of this class.
int m_instance_metatable;
std::map<const char*, int, ltstr> m_static_constants;
// the first time an operator is invoked
// we check the associated lua table
// and cache the result
int m_operator_cache;
cast_graph* m_casts;
class_id_map* m_classes;
};
bool is_class_rep(lua_State* L, int index);
}}
//#include <luabind/detail/overload_rep_impl.hpp>
#endif // LUABIND_CLASS_REP_HPP_INCLUDED
@@ -0,0 +1,73 @@
// Copyright Daniel Wallin 2008. Use, modification and distribution is
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef LUABIND_COMPUTE_RANK_081006_HPP
# define LUABIND_COMPUTE_RANK_081006_HPP
# include <luabind/config.hpp>
# include <luabind/detail/policy.hpp>
# include <boost/mpl/apply_wrap.hpp>
# include <boost/mpl/begin_end.hpp>
# include <boost/mpl/int.hpp>
# include <boost/mpl/next.hpp>
namespace luabind { namespace detail {
namespace mpl = boost::mpl;
template <class Idx, class Iter, class End, class Policies>
int compute_score_aux(
lua_State*L, int index, Idx, Iter, End end, Policies const& policies)
{
typedef typename Iter::type arg_type;
typedef typename find_conversion_policy<Idx::value, Policies>::type
conversion_policy;
typedef typename mpl::apply_wrap2<
conversion_policy, arg_type, lua_to_cpp>::type converter;
int score = converter::match(L, LUABIND_DECORATE_TYPE(arg_type), index);
if (score < 0)
return score;
if (conversion_policy::has_arg)
++index;
int next = compute_score_aux(
L
, index
, typename mpl::next<Idx>::type()
, typename mpl::next<Iter>::type()
, end
, policies
);
if (next < 0)
return next;
return score + next;
}
template <class Idx, class End, class Policies>
int compute_score_aux(lua_State*, int, Idx, End, End, Policies const&)
{
return 0;
}
template <class Signature, class Policies>
int compute_score(lua_State* L, Signature, Policies const& policies)
{
return compute_score_aux(
L
, 1
, mpl::int_<1>()
, typename mpl::next<typename mpl::begin<Signature>::type>::type()
, typename mpl::end<Signature>::type()
, policies
);
}
}} // namespace luabind::detail
#endif // LUABIND_COMPUTE_RANK_081006_HPP
+89 -43
View File
@@ -2,64 +2,110 @@
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef LUABIND_DETAIL_CONSTRUCTOR_081018_HPP
#define LUABIND_DETAIL_CONSTRUCTOR_081018_HPP
#if !BOOST_PP_IS_ITERATING
#include <luabind/get_main_thread.hpp>
#include <luabind/lua_argument_proxy.hpp>
#include <luabind/wrapper_base.hpp>
#include <luabind/detail/inheritance.hpp>
# ifndef LUABIND_DETAIL_CONSTRUCTOR_081018_HPP
# define LUABIND_DETAIL_CONSTRUCTOR_081018_HPP
namespace luabind {
namespace detail {
# include <luabind/get_main_thread.hpp>
# include <luabind/object.hpp>
# include <luabind/wrapper_base.hpp>
# include <luabind/detail/inheritance.hpp>
inline void inject_backref(lua_State*, void*, void*)
{}
# include <boost/preprocessor/iteration/iterate.hpp>
# include <boost/preprocessor/iteration/local.hpp>
# include <boost/preprocessor/repetition/enum_params.hpp>
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
template <class T>
void inject_backref(lua_State* L, T* p, wrap_base*)
{
weak_ref(get_main_thread(L), L, 1).swap(wrap_access::ref(*p));
}
namespace luabind { namespace detail {
template< class T, class Pointer, class Signature, class Arguments, class ArgumentIndices >
struct construct_aux_helper;
inline void inject_backref(lua_State*, void*, void*)
{}
template< class T, class Pointer, class Signature, typename... Arguments, unsigned int... ArgumentIndices >
struct construct_aux_helper< T, Pointer, Signature, meta::type_list< Arguments... >, meta::index_list< ArgumentIndices... > >
{
using holder_type = pointer_holder<Pointer, T>;
template <class T>
void inject_backref(lua_State* L, T* p, wrap_base*)
{
weak_ref(get_main_thread(L), L, 1).swap(wrap_access::ref(*p));
}
void operator()(argument const& self_, Arguments... args) const
{
object_rep* self = touserdata<object_rep>(self_);
template <std::size_t Arity, class T, class Pointer, class Signature>
struct construct_aux;
std::unique_ptr<T> instance(new T(args...));
inject_backref(self_.interpreter(), instance.get(), instance.get());
template <class T, class Pointer, class Signature>
struct construct
: construct_aux<mpl::size<Signature>::value - 2, T, Pointer, Signature>
{};
void* naked_ptr = instance.get();
Pointer ptr(instance.release());
template <class T, class Pointer, class Signature>
struct construct_aux<0, T, Pointer, Signature>
{
typedef pointer_holder<Pointer, T> holder_type;
void* storage = self->allocate(sizeof(holder_type));
void operator()(argument const& self_) const
{
object_rep* self = touserdata<object_rep>(self_);
class_rep* cls = self->crep();
self->set_instance(new (storage) holder_type(std::move(ptr), registered_class<T>::id, naked_ptr));
}
};
std::auto_ptr<T> instance(new T);
inject_backref(self_.interpreter(), instance.get(), instance.get());
void* naked_ptr = instance.get();
Pointer ptr(instance.release());
template< class T, class Pointer, class Signature >
struct construct :
public construct_aux_helper <
T,
Pointer,
Signature, typename meta::sub_range< Signature, 2, meta::size<Signature>::value >::type,
typename meta::make_index_range<0, meta::size<Signature>::value - 2>::type >
{
};
void* storage = self->allocate(sizeof(holder_type));
} // namespace detail
self->set_instance(new (storage) holder_type(
ptr, registered_class<T>::id, naked_ptr, cls));
}
};
} // namespace luabind
# define BOOST_PP_ITERATION_PARAMS_1 \
(3, (1, LUABIND_MAX_ARITY, <luabind/detail/constructor.hpp>))
# include BOOST_PP_ITERATE()
}} // namespace luabind::detail
# endif // LUABIND_DETAIL_CONSTRUCTOR_081018_HPP
#else // !BOOST_PP_IS_ITERATING
# define N BOOST_PP_ITERATION()
template <class T, class Pointer, class Signature>
struct construct_aux<N, T, Pointer, Signature>
{
typedef typename mpl::begin<Signature>::type first;
typedef typename mpl::next<first>::type iter0;
# define BOOST_PP_LOCAL_MACRO(n) \
typedef typename mpl::next< \
BOOST_PP_CAT(iter,BOOST_PP_DEC(n))>::type BOOST_PP_CAT(iter,n); \
typedef typename BOOST_PP_CAT(iter,n)::type BOOST_PP_CAT(a,BOOST_PP_DEC(n));
# define BOOST_PP_LOCAL_LIMITS (1,N)
# include BOOST_PP_LOCAL_ITERATE()
typedef pointer_holder<Pointer, T> holder_type;
void operator()(argument const& self_, BOOST_PP_ENUM_BINARY_PARAMS(N,a,_)) const
{
object_rep* self = touserdata<object_rep>(self_);
class_rep* cls = self->crep();
std::auto_ptr<T> instance(new T(BOOST_PP_ENUM_PARAMS(N,_)));
inject_backref(self_.interpreter(), instance.get(), instance.get());
void* naked_ptr = instance.get();
Pointer ptr(instance.release());
void* storage = self->allocate(sizeof(holder_type));
self->set_instance(new (storage) holder_type(
ptr, registered_class<T>::id, naked_ptr, cls));
}
};
# undef N
#endif
@@ -1,81 +0,0 @@
// Copyright (c) 2003 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef LUABIND_CONVERSION_BASE_HPP_INCLUDED
#define LUABIND_CONVERSION_BASE_HPP_INCLUDED
#include <type_traits>
#include <luabind/lua_include.hpp>
#include <luabind/detail/decorate_type.hpp>
#include <luabind/detail/make_instance.hpp>
#include <luabind/pointer_traits.hpp>
#include <luabind/from_stack.hpp>
namespace luabind {
namespace detail {
// Something's strange with the references here... need to know when to copy :(
template <class T, class Clone>
void make_pointee_instance(lua_State* L, T&& x, std::true_type, Clone)
{
if(get_pointer(x))
{
make_pointer_instance(L, std::forward<T>(x));
}
else
{
lua_pushnil(L);
}
}
template <class T>
void make_pointee_instance(lua_State* L, T&& x, std::false_type, std::true_type)
{
using value_type = typename std::remove_reference<T>::type;
std::unique_ptr<value_type> ptr(new value_type(std::move(x)));
make_pointer_instance(L, std::move(ptr));
}
template <class T>
void make_pointee_instance(lua_State* L, T&& x, std::false_type, std::false_type)
{
// need a second make_instance that moves x into place
make_pointer_instance(L, &x);
}
template <class T, class Clone>
void make_pointee_instance(lua_State* L, T&& x, Clone)
{
make_pointee_instance(L, std::forward<T>(x), has_get_pointer<T>(), Clone());
}
}
template <class T, class Enable>
struct default_converter;
}
#endif
@@ -1,89 +0,0 @@
// Copyright (c) 2003 Daniel Wallin and Arvid Norberg
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef LUABIND_CONVERSION_POLICIES_HPP_INCLUDED
#define LUABIND_CONVERSION_POLICIES_HPP_INCLUDED
#include <luabind/detail/type_traits.hpp>
#include <luabind/detail/meta.hpp>
#include <luabind/detail/policy.hpp>
#include <luabind/detail/conversion_policies/conversion_base.hpp>
#include <luabind/detail/conversion_policies/enum_converter.hpp>
#include <luabind/detail/conversion_policies/pointer_converter.hpp>
#include <luabind/detail/conversion_policies/reference_converter.hpp>
#include <luabind/detail/conversion_policies/value_converter.hpp>
#include <luabind/detail/conversion_policies/lua_proxy_converter.hpp>
#include <luabind/detail/conversion_policies/native_converter.hpp>
#include <luabind/detail/conversion_policies/function_converter.hpp>
#include <luabind/shared_ptr_converter.hpp>
namespace luabind {
template <>
struct default_converter<lua_State*>
{
enum { consumed_args = 0 };
template <class U>
lua_State* to_cpp(lua_State* L, U, int /*index*/)
{
return L;
}
template <class U>
static int match(lua_State*, U, int /*index*/)
{
return 0;
}
template <class U>
void converter_postcall(lua_State*, U, int) {}
};
namespace detail {
// This is the one that gets hit, if default_policy doesn't hit one of the specializations defined all over the place
template< class T >
struct default_converter_generator
: public meta::select_ <
meta::case_< is_lua_proxy_arg<T>, lua_proxy_converter<T> >,
meta::case_< std::is_enum<typename std::remove_reference<T>::type>, enum_converter >,
meta::case_< is_nonconst_pointer<T>, pointer_converter >,
meta::case_< is_const_pointer<T>, const_pointer_converter >,
meta::case_< is_nonconst_reference<T>, ref_converter >,
meta::case_< is_const_reference<T>, const_ref_converter >,
meta::default_< value_converter >
> ::type
{
};
}
template <class T, class Enable>
struct default_converter
: detail::default_converter_generator<T>::type
{};
}
#endif

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