This update allows for many more definition macros and teh use of a configuration header to be combined with the single.py

Allow for configuration macros to aid in fixing #631
This commit is contained in:
ThePhD 2018-04-17 12:29:03 -04:00
parent 2de6447e73
commit 479575c0ca
48 changed files with 1851 additions and 1684 deletions

15
.style.yapf Normal file
View File

@ -0,0 +1,15 @@
[style]
based_on_style = pep8
use_tabs = true
indent_width = 5
spaces_before_comment = 1
spaces_around_power_operator = true
space_between_ending_comma_and_closing_bracket = true
continuation_align_style = SPACE
split_before_first_argument = false
split_complex_comprehension = true
dedent_closing_brackets = false
coalesce_brackets = true
align_closing_bracket_with_visual_indent = false

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

View File

@ -14,8 +14,16 @@ except ImportError:
description = "Converts sol to a single file for convenience." description = "Converts sol to a single file for convenience."
# command line parser # command line parser
parser = argparse.ArgumentParser(usage='%(prog)s [options...]', description=description) parser = argparse.ArgumentParser(
parser.add_argument('--output', '-o', nargs='+', help='name and location of where to place file (and forward declaration file)', metavar='file', default='sol.hpp') usage='%(prog)s [options...]', description=description)
parser.add_argument(
'--output',
'-o',
nargs='+',
help=
'name and location of where to place file (and forward declaration file)',
metavar='file',
default='sol.hpp')
parser.add_argument('--quiet', help='suppress all output', action='store_true') parser.add_argument('--quiet', help='suppress all output', action='store_true')
args = parser.parse_args() args = parser.parse_args()
@ -67,33 +75,49 @@ module_path = os.path.join(script_path)
includes = set([]) includes = set([])
standard_include = re.compile(r'#include <(.*?)>') standard_include = re.compile(r'#include <(.*?)>')
local_include = re.compile(r'#(\s*?)include "(.*?)"') local_include = re.compile(r'#(\s*?)include "(.*?)"')
project_include = re.compile(r'#(\s*?)include <sol/(.*?)>')
pragma_once_cpp = re.compile(r'(\s*)#(\s*)pragma(\s+)once')
ifndef_cpp = re.compile(r'#ifndef SOL_.*?_HPP') ifndef_cpp = re.compile(r'#ifndef SOL_.*?_HPP')
define_cpp = re.compile(r'#define SOL_.*?_HPP') define_cpp = re.compile(r'#define SOL_.*?_HPP')
endif_cpp = re.compile(r'#endif // SOL_.*?_HPP') endif_cpp = re.compile(r'#endif // SOL_.*?_HPP')
def get_include(line, base_path): def get_include(line, base_path):
local_match = local_include.match(line) local_match = local_include.match(line)
if local_match: if local_match:
# local include found # local include found
full_path = os.path.normpath(os.path.join(base_path, local_match.group(2))).replace('\\', '/') full_path = os.path.normpath(
os.path.join(base_path, local_match.group(2))).replace(
'\\', '/')
return full_path
project_match = project_include.match(line)
if project_match:
# local include found
full_path = os.path.normpath(
os.path.join(base_path, project_match.group(2))).replace(
'\\', '/')
return full_path return full_path
return None return None
def is_include_guard(line): def is_include_guard(line):
return ifndef_cpp.match(line) or define_cpp.match(line) or endif_cpp.match(line) return ifndef_cpp.match(line) or define_cpp.match(
line) or endif_cpp.match(line) or pragma_once_cpp.match(line)
def get_revision(): def get_revision():
return os.popen('git rev-parse --short HEAD').read().strip() return os.popen('git rev-parse --short HEAD').read().strip()
def get_version(): def get_version():
return os.popen('git describe --tags --abbrev=0').read().strip() return os.popen('git describe --tags --abbrev=0').read().strip()
def process_file(filename, out): def process_file(filename, out):
global includes global includes
filename = os.path.normpath(filename) filename = os.path.normpath(filename)
relativefilename = filename.replace(script_path + os.sep, "").replace("\\", "/") relativefilename = filename.replace(script_path + os.sep, "").replace(
"\\", "/")
if filename in includes: if filename in includes:
return return
@ -153,17 +177,24 @@ include_guard = 'SOL_SINGLE_INCLUDE_HPP'
forward_include_guard = 'SOL_SINGLE_INCLUDE_FORWARD_HPP' forward_include_guard = 'SOL_SINGLE_INCLUDE_FORWARD_HPP'
processed_files = [os.path.join(script_path, x) for x in ['sol.hpp']] processed_files = [os.path.join(script_path, x) for x in ['sol.hpp']]
forward_processed_files = [os.path.join(script_path, x) for x in ['sol/forward.hpp']] forward_processed_files = [
os.path.join(script_path, x) for x in ['sol/forward.hpp']
]
result = '' result = ''
forward_result = '' forward_result = ''
if not args.quiet: if not args.quiet:
print('Current version: {version} (revision {revision})\n'.format(version = version, revision = revision)) print('Current version: {version} (revision {revision})\n'.format(
version=version, revision=revision))
print('Creating single header for sol') print('Creating single header for sol')
ss = StringIO() ss = StringIO()
ss.write(intro.format(time=dt.datetime.utcnow(), revision=revision, version=version, guard=include_guard)) ss.write(
intro.format(
time=dt.datetime.utcnow(),
revision=revision,
version=version,
guard=include_guard))
for processed_file in processed_files: for processed_file in processed_files:
process_file(processed_file, ss) process_file(processed_file, ss)
@ -179,7 +210,12 @@ if not args.quiet:
includes = set([]) includes = set([])
forward_ss = StringIO() forward_ss = StringIO()
forward_ss.write(intro.format(time=dt.datetime.utcnow(), revision=revision, version=version, guard=forward_include_guard)) forward_ss.write(
intro.format(
time=dt.datetime.utcnow(),
revision=revision,
version=version,
guard=forward_include_guard))
for forward_processed_file in forward_processed_files: for forward_processed_file in forward_processed_files:
process_file(forward_processed_file, forward_ss) process_file(forward_processed_file, forward_ss)

14
sol.hpp
View File

@ -23,24 +23,24 @@
#define SOL_HPP #define SOL_HPP
#if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) #if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER)
#define SOL_INSIDE_UNREAL #define SOL_INSIDE_UNREAL 1
#endif // Unreal Engine 4 bullshit #endif // Unreal Engine 4 bullshit
#ifdef SOL_INSIDE_UNREAL #if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL
#ifdef check #ifdef check
#define SOL_INSIDE_UNREAL_REMOVED_CHECK #define SOL_INSIDE_UNREAL_REMOVED_CHECK
#undef check #undef check
#endif #endif
#endif // Unreal Engine 4 Bullshit #endif // Unreal Engine 4 Bullshit
#ifdef __GNUC__ #if defined(__GNUC__)
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow" #pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wconversion" #pragma GCC diagnostic ignored "-Wconversion"
#if __GNUC__ > 6 #if __GNUC__ > 6
#pragma GCC diagnostic ignored "-Wnoexcept-type" #pragma GCC diagnostic ignored "-Wnoexcept-type"
#endif #endif
#elif defined __clang__ #elif defined(__clang__)
// we'll just let this alone for now // we'll just let this alone for now
#elif defined _MSC_VER #elif defined _MSC_VER
#pragma warning( push ) #pragma warning( push )
@ -61,14 +61,14 @@
#include "sol/variadic_args.hpp" #include "sol/variadic_args.hpp"
#include "sol/variadic_results.hpp" #include "sol/variadic_results.hpp"
#ifdef __GNUC__ #if defined(__GNUC__)
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#elif defined _MSC_VER #elif defined _MSC_VER
#pragma warning( push ) #pragma warning( push )
#endif // g++ #endif // g++
#ifdef SOL_INSIDE_UNREAL #if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL
#ifdef SOL_INSIDE_UNREAL_REMOVED_CHECK #if defined(SOL_INSIDE_UNREAL_REMOVED_CHECK) && SOL_INSIDE_UNREAL_REMOVED_CHECK
#if DO_CHECK #if DO_CHECK
#define check(expr) { if(UNLIKELY(!(expr))) { FDebug::LogAssertFailedMessage( #expr, __FILE__, __LINE__ ); _DebugBreakAndPromptForRemote(); FDebug::AssertFailed( #expr, __FILE__, __LINE__ ); CA_ASSUME(false); } } #define check(expr) { if(UNLIKELY(!(expr))) { FDebug::LogAssertFailedMessage( #expr, __FILE__, __LINE__ ); _DebugBreakAndPromptForRemote(); FDebug::AssertFailed( #expr, __FILE__, __LINE__ ); CA_ASSUME(false); } }
#else #else

View File

@ -200,7 +200,7 @@ namespace meta {
typedef R (T::*function_pointer_type)(Args..., ...) const volatile&&; typedef R (T::*function_pointer_type)(Args..., ...) const volatile&&;
}; };
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
template <typename R, typename... Args> template <typename R, typename... Args>
struct fx_traits<R(Args...) noexcept, false> : basic_traits<true, false, void, R, Args...> { struct fx_traits<R(Args...) noexcept, false> : basic_traits<true, false, void, R, Args...> {
@ -373,7 +373,7 @@ namespace meta {
typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&&; typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&&;
}; };
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
template <typename R, typename... Args> template <typename R, typename... Args>
struct fx_traits<R __stdcall(Args...) noexcept, false> : basic_traits<true, false, void, R, Args...> { struct fx_traits<R __stdcall(Args...) noexcept, false> : basic_traits<true, false, void, R, Args...> {

View File

@ -314,7 +314,7 @@ namespace sol {
} }
}; };
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
template <bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C> template <bool is_index, bool is_variable, bool checked, int boost, bool clean_stack, typename C>
struct agnostic_lua_call_wrapper<detail::lua_CFunction_noexcept, is_index, is_variable, checked, boost, clean_stack, C> { struct agnostic_lua_call_wrapper<detail::lua_CFunction_noexcept, is_index, is_variable, checked, boost, clean_stack, C> {
static int call(lua_State* L, detail::lua_CFunction_noexcept f) { static int call(lua_State* L, detail::lua_CFunction_noexcept f) {
@ -371,7 +371,7 @@ namespace sol {
template <typename Fx> template <typename Fx>
static int call(lua_State* L, Fx&& f) { static int call(lua_State* L, Fx&& f) {
typedef std::conditional_t<std::is_void<T>::value, object_type, T> Ta; typedef std::conditional_t<std::is_void<T>::value, object_type, T> Ta;
#ifdef SOL_SAFE_USERTYPE #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
auto maybeo = stack::check_get<Ta*>(L, 1); auto maybeo = stack::check_get<Ta*>(L, 1);
if (!maybeo || maybeo.value() == nullptr) { if (!maybeo || maybeo.value() == nullptr) {
return luaL_error(L, "sol: received nil for 'self' argument (use ':' for accessing member functions, make sure member variables are preceeded by the actual object with '.' syntax)"); return luaL_error(L, "sol: received nil for 'self' argument (use ':' for accessing member functions, make sure member variables are preceeded by the actual object with '.' syntax)");
@ -401,7 +401,7 @@ namespace sol {
template <typename V> template <typename V>
static int call_assign(std::true_type, lua_State* L, V&& f) { static int call_assign(std::true_type, lua_State* L, V&& f) {
typedef std::conditional_t<std::is_void<T>::value, object_type, T> Ta; typedef std::conditional_t<std::is_void<T>::value, object_type, T> Ta;
#ifdef SOL_SAFE_USERTYPE #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
auto maybeo = stack::check_get<Ta*>(L, 1); auto maybeo = stack::check_get<Ta*>(L, 1);
if (!maybeo || maybeo.value() == nullptr) { if (!maybeo || maybeo.value() == nullptr) {
if (is_variable) { if (is_variable) {
@ -461,7 +461,7 @@ namespace sol {
template <typename V> template <typename V>
static int call(lua_State* L, V&& f) { static int call(lua_State* L, V&& f) {
typedef std::conditional_t<std::is_void<T>::value, object_type, T> Ta; typedef std::conditional_t<std::is_void<T>::value, object_type, T> Ta;
#ifdef SOL_SAFE_USERTYPE #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
auto maybeo = stack::check_get<Ta*>(L, 1); auto maybeo = stack::check_get<Ta*>(L, 1);
if (!maybeo || maybeo.value() == nullptr) { if (!maybeo || maybeo.value() == nullptr) {
if (is_variable) { if (is_variable) {
@ -642,7 +642,7 @@ namespace sol {
typedef meta::pop_front_type_t<typename traits_type::free_args_list> args_list; typedef meta::pop_front_type_t<typename traits_type::free_args_list> args_list;
typedef T Ta; typedef T Ta;
typedef std::remove_pointer_t<object_type> Oa; typedef std::remove_pointer_t<object_type> Oa;
#ifdef SOL_SAFE_USERTYPE #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
auto maybeo = stack::check_get<Ta*>(L, 1); auto maybeo = stack::check_get<Ta*>(L, 1);
if (!maybeo || maybeo.value() == nullptr) { if (!maybeo || maybeo.value() == nullptr) {
if (is_variable) { if (is_variable) {

View File

@ -32,15 +32,17 @@
#include "feature_test.hpp" #include "feature_test.hpp"
#include "compatibility/version.hpp" #include "compatibility/version.hpp"
#ifndef SOL_NO_COMPAT #if !defined(SOL_NO_COMPAT) || !(SOL_NO_COMPAT)
#if defined(SOL_USING_CXX_LUA) #if defined(SOL_USING_CXX_LUA) && SOL_USING_CXX_LUA
#ifndef COMPAT53_LUA_CPP #ifndef COMPAT53_LUA_CPP
#define COMPAT53_LUA_CPP 1 #define COMPAT53_LUA_CPP 1
#endif // Build Lua Compat layer as C++
#endif #endif
#endif #ifndef COMPAT53_INCLUDE_SOURCE
#define COMPAT53_INCLUDE_SOURCE 1
#include "compatibility//compat-5.3.h" #endif // Build Compat Layer Inline
#include "compatibility/compat-5.3.h"
#endif // SOL_NO_COMPAT #endif // SOL_NO_COMPAT

View File

@ -7,8 +7,8 @@
#include "compat-5.3.h" #include "compat-5.3.h"
/* don't compile it again if it already is included via compat53.h */ /* don't compile it again if it already is included via compat53.h */
#ifndef COMPAT53_C_ #ifndef KEPLER_PROJECT_COMPAT53_C_
#define COMPAT53_C_ #define KEPLER_PROJECT_COMPAT53_C_
@ -204,15 +204,6 @@ COMPAT53_API void lua_rawsetp (lua_State *L, int i, const void *p) {
} }
COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) {
lua_Integer n = lua_tointeger(L, i);
if (isnum != NULL) {
*isnum = (n != 0 || lua_isnumber(L, i));
}
return n;
}
COMPAT53_API lua_Number lua_tonumberx(lua_State *L, int i, int *isnum) { COMPAT53_API lua_Number lua_tonumberx(lua_State *L, int i, int *isnum) {
lua_Number n = lua_tonumber(L, i); lua_Number n = lua_tonumber(L, i);
if (isnum != NULL) { if (isnum != NULL) {
@ -450,7 +441,8 @@ static const char *compat53_reader (lua_State *L, void *ud, size_t *size) {
data->has_peeked_data = 0; data->has_peeked_data = 0;
*size = data->peeked_data_size; *size = data->peeked_data_size;
return data->peeked_data; return data->peeked_data;
} else }
else
return data->reader(L, data->ud, size); return data->reader(L, data->ud, size);
} }
@ -740,6 +732,22 @@ COMPAT53_API int lua_isinteger (lua_State *L, int index) {
} }
COMPAT53_API lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum) {
int ok = 0;
lua_Number n = lua_tonumberx(L, i, &ok);
if (ok) {
if (n == (lua_Integer)n) {
if (isnum)
*isnum = 1;
return (lua_Integer)n;
}
}
if (isnum)
*isnum = 0;
return 0;
}
static void compat53_reverse(lua_State *L, int a, int b) { static void compat53_reverse(lua_State *L, int a, int b) {
for (; a < b; ++a, --b) { for (; a < b; ++a, --b) {
lua_pushvalue(L, a); lua_pushvalue(L, a);
@ -820,7 +828,8 @@ COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
lua_replace(L, -2); lua_replace(L, -2);
break; break;
} }
} else { }
else {
if (!lua_isstring(L, -1)) if (!lua_isstring(L, -1))
luaL_error(L, "'__tostring' must return a string"); luaL_error(L, "'__tostring' must return a string");
} }
@ -851,7 +860,7 @@ COMPAT53_API void luaL_requiref (lua_State *L, const char *modname,
#endif /* Lua 5.1 and 5.2 */ #endif /* Lua 5.1 and 5.2 */
#endif /* COMPAT53_C_ */ #endif /* KEPLER_PROJECT_COMPAT53_C_ */
/********************************************************************* /*********************************************************************

View File

@ -1,5 +1,5 @@
#ifndef COMPAT53_H_ #ifndef KEPLER_PROJECT_COMPAT53_H_
#define COMPAT53_H_ #define KEPLER_PROJECT_COMPAT53_H_
#include <stddef.h> #include <stddef.h>
#include <limits.h> #include <limits.h>
@ -14,29 +14,28 @@ extern "C" {
} }
#endif #endif
#ifndef COMPAT53_PREFIX
/* we chose this name because many other lua bindings / libs have
* their own compatibility layer, and that use the compat53 declaration
* frequently, causing all kinds of linker / compiler issues
*/
# define COMPAT53_PREFIX kp_compat53
#endif // COMPAT53_PREFIX
#undef COMPAT53_INCLUDE_SOURCE #ifndef COMPAT53_API
#if defined(COMPAT53_PREFIX) # if defined(COMPAT53_INCLUDE_SOURCE) && COMPAT53_INCLUDE_SOURCE
/* - change the symbol names of functions to avoid linker conflicts
* - compat-5.3.c needs to be compiled (and linked) separately
*/
# if !defined(COMPAT53_API)
# define COMPAT53_API extern
# endif
#else /* COMPAT53_PREFIX */
/* - make all functions static and include the source.
* - compat-5.3.c doesn't need to be compiled (and linked) separately
*/
# define COMPAT53_PREFIX compat53
# undef COMPAT53_API
# if defined(__GNUC__) || defined(__clang__) # if defined(__GNUC__) || defined(__clang__)
# define COMPAT53_API __attribute__((__unused__)) static # define COMPAT53_API __attribute__((__unused__)) static
# else # else
# define COMPAT53_API static # define COMPAT53_API static
# endif # endif /* Clang/GCC */
# define COMPAT53_INCLUDE_SOURCE # else /* COMPAT53_INCLUDE_SOURCE */
/* we are not including source, so everything is extern */
# define COMPAT53_API extern
# endif /* COMPAT53_INCLUDE_SOURCE */
#endif /* COMPAT53_PREFIX */ #endif /* COMPAT53_PREFIX */
#define COMPAT53_CONCAT_HELPER(a, b) a##b #define COMPAT53_CONCAT_HELPER(a, b) a##b
#define COMPAT53_CONCAT(a, b) COMPAT53_CONCAT_HELPER(a, b) #define COMPAT53_CONCAT(a, b) COMPAT53_CONCAT_HELPER(a, b)
@ -165,8 +164,7 @@ COMPAT53_API void lua_rawsetp(lua_State *L, int i, const void *p);
#define lua_rawlen(L, i) lua_objlen((L), (i)) #define lua_rawlen(L, i) lua_objlen((L), (i))
#define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx) #define lua_tointeger(L, i) lua_tointegerx((L), (i), NULL)
COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum);
#define lua_tonumberx COMPAT53_CONCAT(COMPAT53_PREFIX, _tonumberx) #define lua_tonumberx COMPAT53_CONCAT(COMPAT53_PREFIX, _tonumberx)
COMPAT53_API lua_Number lua_tonumberx(lua_State *L, int i, int *isnum); COMPAT53_API lua_Number lua_tonumberx(lua_State *L, int i, int *isnum);
@ -297,6 +295,9 @@ COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i);
#define lua_isinteger COMPAT53_CONCAT(COMPAT53_PREFIX, _isinteger) #define lua_isinteger COMPAT53_CONCAT(COMPAT53_PREFIX, _isinteger)
COMPAT53_API int lua_isinteger(lua_State *L, int index); COMPAT53_API int lua_isinteger(lua_State *L, int index);
#define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx_53)
COMPAT53_API lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum);
#define lua_numbertointeger(n, p) \ #define lua_numbertointeger(n, p) \
((*(p) = (lua_Integer)(n)), 1) ((*(p) = (lua_Integer)(n)), 1)
@ -411,10 +412,10 @@ COMPAT53_API void luaL_requiref (lua_State *L, const char *modname,
#endif #endif
#if defined(COMPAT53_INCLUDE_SOURCE) #if defined(COMPAT53_INCLUDE_SOURCE) && COMPAT53_INCLUDE_SOURCE == 1
# include "compat-5.3.c" # include "compat-5.3.c"
#endif #endif
#endif /* COMPAT53_H_ */ #endif /* KEPLER_PROJECT_COMPAT53_H_ */

View File

@ -26,15 +26,15 @@
#include "../feature_test.hpp" #include "../feature_test.hpp"
#if defined(SOL_USING_CXX_LUA) #if defined(SOL_USING_CXX_LUA) && SOL_USING_CXX_LUA
#include <lua.h> #include <lua.h>
#include <lualib.h> #include <lualib.h>
#include <lauxlib.h> #include <lauxlib.h>
#ifdef SOL_USING_CXX_LUAJIT #if defined(SOL_USING_CXX_LUAJIT) && SOL_USING_CXX_LUAJIT
#include <luajit.h> #include <luajit.h>
#endif // C++ LuaJIT ... whatever that means #endif // C++ LuaJIT ... whatever that means
#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE) #if (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !(SOL_EXCEPTIONS_SAFE_PROPAGATION)) && (!defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE) || !(SOL_EXCEPTIONS_ALWAYS_UNSAFE))
#define SOL_EXCEPTIONS_SAFE_PROPAGATION #define SOL_EXCEPTIONS_SAFE_PROPAGATION 1
#endif // Exceptions can be propagated safely using C++-compiled Lua #endif // Exceptions can be propagated safely using C++-compiled Lua
#else #else
#include <lua.hpp> #include <lua.hpp>
@ -51,7 +51,7 @@
#define SOL_LUA_VERSION LUA_VERSION_NUM #define SOL_LUA_VERSION LUA_VERSION_NUM
#elif defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 #elif defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501
#define SOL_LUA_VERSION LUA_VERSION_NUM #define SOL_LUA_VERSION LUA_VERSION_NUM
#elif !defined(LUA_VERSION_NUM) #elif !defined(LUA_VERSION_NUM) || !(LUA_VERSION_NUM)
// Definitely 5.0 // Definitely 5.0
#define SOL_LUA_VERSION 500 #define SOL_LUA_VERSION 500
#else #else

220
sol/config.hpp Normal file
View File

@ -0,0 +1,220 @@
// sol2
// The MIT License (MIT)
// Copyright (c) 2013-2018 Rapptz, ThePhD and contributors
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef SOL_CONFIG_HPP
#define SOL_CONFIG_HPP
#ifdef _MSC_VER
#if defined(_DEBUG) && !defined(NDEBUG)
#ifndef SOL_IN_DEBUG_DETECTED
#define SOL_IN_DEBUG_DETECTED 1
#endif
#endif // VC++ Debug macros
#ifndef _CPPUNWIND
#ifndef SOL_NO_EXCEPTIONS
#define SOL_NO_EXCEPTIONS 1
#endif
#endif // Automatic Exceptions
#ifndef _CPPRTTI
#ifndef SOL_NO_RTTI
#define SOL_NO_RTTI 1
#endif
#endif // Automatic RTTI
#elif defined(__GNUC__) || defined(__clang__)
#if !defined(NDEBUG) && !defined(__OPTIMIZE__)
#ifndef SOL_IN_DEBUG_DETECTED
#define SOL_IN_DEBUG_DETECTED 1
#endif
#endif // Not Debug && g++ optimizer flag
#ifndef __EXCEPTIONS
#ifndef SOL_NO_EXCEPTIONS
#define SOL_NO_EXCEPTIONS 1
#endif
#endif // No Exceptions
#ifndef __GXX_RTTI
#ifndef SOL_NO_RTII
#define SOL_NO_RTTI 1
#endif
#endif // No RTTI
#endif // vc++ || clang++/g++
// If this is defined, turn on all the safety checks automatically
#if defined(SOL_CHECK_ARGUMENTS) && SOL_CHECK_ARGUMENTS
// Checks low-level getter function
// (and thusly, affects nearly entire framework)
#if !defined(SOL_SAFE_GETTER)
#define SOL_SAFE_GETTER 1
#endif
// Checks access on usertype functions
// local my_obj = my_type.new()
// my_obj.my_member_function()
// -- bad syntax and crash
#if !defined(SOL_SAFE_USERTYPE)
#define SOL_SAFE_USERTYPE 1
#endif
// Checks sol::reference derived boundaries
// sol::function ref(L, 1);
// sol::userdata sref(L, 2);
#if !defined(SOL_SAFE_REFERENCES)
#define SOL_SAFE_REFERENCES 1
#endif
// Changes all typedefs of sol::function to point to the
// protected_function version, instead of unsafe_function
#if !defined(SOL_SAFE_FUNCTION)
#define SOL_SAFE_FUNCTION 1
#endif
// Checks function parameters and
// returns upon call into/from Lua
// local a = 1
// local b = "woof"
// my_c_function(a, b)
#if !defined(SOL_SAFE_FUNCTION_CALLS)
#define SOL_SAFE_FUNCTION_CALLS 1
#endif
// Checks conversions
// int v = lua["bark"];
// int v2 = my_sol_function();
#if !defined(SOL_SAFE_PROXIES)
#define SOL_SAFE_PROXIES 1
#endif
// Check overflowing number conversions
// for things like 64 bit integers that don't fit in a typical lua_Number
// for Lua 5.1 and 5.2
#if !defined(SOL_SAFE_NUMERICS)
#define SOL_SAFE_NUMERICS 1
#endif
// Turn off Number Precision Checks
// if this is defined, we do not do range
// checks on integers / unsigned integers that might
// be bigger than what Lua can represent
#if !defined(SOL_NO_CHECK_NUMBER_PRECISION)
// off by default
#define SOL_NO_CHECK_NUMBER_PRECISION 0
#endif
#endif // Turn on Safety for all if top-level macro is defined
// If we are in debug, turn on certain safety checks
#if defined(SOL_IN_DEBUG_DETECTED) && SOL_IN_DEBUG_DETECTED
#if !defined(SOL_SAFE_REFERENCES)
// Ensure that references are forcefully type-checked upon construction
#define SOL_SAFE_REFERENCES 1
#endif
// Safe usertypes checks for errors such as
// obj = my_type.new()
// obj.f() -- note the '.' instead of ':'
// usertypes should be safe no matter what
#if !defined(SOL_SAFE_USERTYPE)
#define SOL_SAFE_USERTYPE 1
#endif
#if !defined(SOL_SAFE_FUNCTION_CALLS)
// Function calls from Lua should be automatically safe in debug mode
#define SOL_SAFE_FUNCTION_CALLS 1
#endif
// Print any exceptions / errors that occur
// in debug mode to the default error stream / console
#if !defined(SOL_PRINT_ERRORS)
#define SOL_PRINT_ERRORS 1
#endif
#endif // DEBUG: Turn on all debug safety features for VC++ / g++ / clang++ and similar
// Print any exceptions / errors that occur
// This is normally off due to relying on
// <iostream> to get std::cerr / std::cout
// so it is only defined in debug modes
#if !defined(SOL_PRINT_ERRORS)
// off by default here
#define SOL_PRINT_ERRORS 0
#endif
// The default on_error handler should not throw/assert/print/abort,
// but simply pass the value through back to the user
// problematic due to not having a stable [[nodiscard]] attribute in C++11,
// off by default
#if !defined(SOL_DEFAULT_PASS_ON_ERROR)
// off by default here
#define SOL_DEFAULT_PASS_ON_ERROR 0
#endif
// Interop allows userdata from external systems
// with external memory layout and metatable names
// to be registered. It costs something to perform
// the checker / differentiation for sol2 usertypes versus
// external ones however, so this is off by default
#if !defined(SOL_ENABLE_INTEROP)
// off by default here
#define SOL_ENABLE_INTEROP 0
#endif
// Mac OSX and Objective C define a nil keyword
// we cannot use that for the sol::type::nil define
#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil)
#if !defined(SOL_NO_NIL)
#define SOL_NO_NIL 1
#endif
#endif // avoiding nil defines / keywords
// If we are using boost, there are a number of optimizations we can perform
// Boost has unordered_map with Compatible Key and CompatibleHash
// Boost also has a decent optional, and we check for this later
// and define our optional to use boost in that scenario
#if defined(SOL_USE_BOOST) && SOL_USE_BOOST
#ifndef SOL_UNORDERED_MAP_COMPATIBLE_HASH
#define SOL_UNORDERED_MAP_COMPATIBLE_HASH 1
#endif // SOL_UNORDERED_MAP_COMPATIBLE_HASH
#endif
// For strings being serialized and
// deserialized from and to utf8
// this controls the size of the buffer we create on the stack,
// in # of utf8 code units
// a buffer of 1KB covers almost all the strings
// we care about: anything larger and the user should know better
#ifndef SOL_STACK_STRING_OPTIMIZATION_SIZE
#define SOL_STACK_STRING_OPTIMIZATION_SIZE 1024
#endif // Optimized conversion routines using a KB or so off the stack
#endif // SOL_CONFIG_HPP

View File

@ -596,7 +596,7 @@ namespace sol {
}; };
static auto& get_src(lua_State* L) { static auto& get_src(lua_State* L) {
#ifdef SOL_SAFE_USERTYPE #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
auto p = stack::check_get<T*>(L, 1); auto p = stack::check_get<T*>(L, 1);
if (!p) { if (!p) {
luaL_error(L, "sol: 'self' is not of type '%s' (pass 'self' as first argument with ':' or call on proper type)", detail::demangle<T>().c_str()); luaL_error(L, "sol: 'self' is not of type '%s' (pass 'self' as first argument with ':' or call on proper type)", detail::demangle<T>().c_str());
@ -1313,7 +1313,7 @@ namespace sol {
static auto& get_src(lua_State* L) { static auto& get_src(lua_State* L) {
auto p = stack::check_get<T*>(L, 1); auto p = stack::check_get<T*>(L, 1);
#ifdef SOL_SAFE_USERTYPE #if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
if (!p) { if (!p) {
luaL_error(L, "sol: 'self' is not of type '%s' (pass 'self' as first argument with ':' or call on proper type)", detail::demangle<T>().c_str()); luaL_error(L, "sol: 'self' is not of type '%s' (pass 'self' as first argument with ':' or call on proper type)", detail::demangle<T>().c_str());
} }
@ -1438,7 +1438,11 @@ namespace sol {
} }
static std::ptrdiff_t index_adjustment(lua_State*, T&) { static std::ptrdiff_t index_adjustment(lua_State*, T&) {
#if defined(SOL_CONTAINERS_START_INDEX)
return (SOL_CONTAINERS_START) == 0 ? 0 : -(SOL_CONTAINERS_START);
#else
return -1; return -1;
#endif
} }
static iterator begin(lua_State*, T& self) { static iterator begin(lua_State*, T& self) {

View File

@ -63,7 +63,7 @@ namespace sol {
auto maybenameview = stack::check_get<string_view>(L, 2); auto maybenameview = stack::check_get<string_view>(L, 2);
if (maybenameview) { if (maybenameview) {
const string_view& nameview = *maybenameview; const string_view& nameview = *maybenameview;
#ifdef SOL_UNORDERED_MAP_COMPATIBLE_HASH #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
auto it = calls.find(nameview, string_view_hash(), std::equal_to<string_view>()); auto it = calls.find(nameview, string_view_hash(), std::equal_to<string_view>());
#else #else
std::string name(nameview.data(), nameview.size()); std::string name(nameview.data(), nameview.size());

View File

@ -85,7 +85,7 @@ namespace sol {
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_coroutine>>, meta::neg<std::is_base_of<proxy_base_tag, meta::unqualified_t<T>>>, meta::neg<std::is_same<base_t, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_coroutine>>, meta::neg<std::is_base_of<proxy_base_tag, meta::unqualified_t<T>>>, meta::neg<std::is_same<base_t, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_coroutine(T&& r) noexcept basic_coroutine(T&& r) noexcept
: base_t(std::forward<T>(r)), error_handler(detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) { : base_t(std::forward<T>(r)), error_handler(detail::get_default_handler<reference, is_main_threaded<base_t>::value>(r.lua_state())) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
if (!is_function<meta::unqualified_t<T>>::value) { if (!is_function<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
@ -142,7 +142,7 @@ namespace sol {
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_coroutine(lua_State* L, T&& r, handler_t eh) basic_coroutine(lua_State* L, T&& r, handler_t eh)
: base_t(L, std::forward<T>(r)), error_handler(std::move(eh)) { : base_t(L, std::forward<T>(r)), error_handler(std::move(eh)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_coroutine>(lua_state(), -1, handler); stack::check<basic_coroutine>(lua_state(), -1, handler);
@ -168,7 +168,7 @@ namespace sol {
} }
basic_coroutine(lua_State* L, absolute_index index, handler_t eh) basic_coroutine(lua_State* L, absolute_index index, handler_t eh)
: base_t(L, index), error_handler(std::move(eh)) { : base_t(L, index), error_handler(std::move(eh)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_coroutine>(L, index, handler); stack::check<basic_coroutine>(L, index, handler);
#endif // Safety #endif // Safety
@ -178,7 +178,7 @@ namespace sol {
} }
basic_coroutine(lua_State* L, raw_index index, handler_t eh) basic_coroutine(lua_State* L, raw_index index, handler_t eh)
: base_t(L, index), error_handler(std::move(eh)) { : base_t(L, index), error_handler(std::move(eh)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_coroutine>(L, index, handler); stack::check<basic_coroutine>(L, index, handler);
#endif // Safety #endif // Safety
@ -188,7 +188,7 @@ namespace sol {
} }
basic_coroutine(lua_State* L, ref_index index, handler_t eh) basic_coroutine(lua_State* L, ref_index index, handler_t eh)
: base_t(L, index), error_handler(std::move(eh)) { : base_t(L, index), error_handler(std::move(eh)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_coroutine>(lua_state(), -1, handler); stack::check<basic_coroutine>(lua_state(), -1, handler);

View File

@ -62,7 +62,7 @@ namespace sol {
basic_environment(env_t, const stack_reference& extraction_target) basic_environment(env_t, const stack_reference& extraction_target)
: base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) { : base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<env_t>(this->lua_state(), -1, handler); stack::check<env_t>(this->lua_state(), -1, handler);
#endif // Safety #endif // Safety
@ -71,7 +71,7 @@ namespace sol {
template <bool b> template <bool b>
basic_environment(env_t, const basic_reference<b>& extraction_target) basic_environment(env_t, const basic_reference<b>& extraction_target)
: base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) { : base_t(detail::no_safety, extraction_target.lua_state(), (stack::push_environment_of(extraction_target), -1)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<env_t>(this->lua_state(), -1, handler); stack::check<env_t>(this->lua_state(), -1, handler);
#endif // Safety #endif // Safety
@ -79,14 +79,14 @@ namespace sol {
} }
basic_environment(lua_State* L, int index = -1) basic_environment(lua_State* L, int index = -1)
: base_t(detail::no_safety, L, index) { : base_t(detail::no_safety, L, index) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_environment>(L, index, handler); stack::check<basic_environment>(L, index, handler);
#endif // Safety #endif // Safety
} }
basic_environment(lua_State* L, ref_index index) basic_environment(lua_State* L, ref_index index)
: base_t(detail::no_safety, L, index) { : base_t(detail::no_safety, L, index) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_environment>(L, -1, handler); stack::check<basic_environment>(L, -1, handler);
@ -95,7 +95,7 @@ namespace sol {
template <typename T, meta::enable<meta::neg<meta::any_same<meta::unqualified_t<T>, basic_environment>>, meta::neg<std::is_same<base_type, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<meta::neg<meta::any_same<meta::unqualified_t<T>, basic_environment>>, meta::neg<std::is_same<base_type, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_environment(T&& r) noexcept basic_environment(T&& r) noexcept
: base_t(detail::no_safety, std::forward<T>(r)) { : base_t(detail::no_safety, std::forward<T>(r)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
if (!is_environment<meta::unqualified_t<T>>::value) { if (!is_environment<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
@ -110,7 +110,7 @@ namespace sol {
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_environment(lua_State* L, T&& r) noexcept basic_environment(lua_State* L, T&& r) noexcept
: base_t(detail::no_safety, L, std::forward<T>(r)) { : base_t(detail::no_safety, L, std::forward<T>(r)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
if (!is_environment<meta::unqualified_t<T>>::value) { if (!is_environment<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};

View File

@ -35,7 +35,7 @@ namespace sol {
class error : public std::runtime_error { class error : public std::runtime_error {
private: private:
// Because VC++ is a fuccboi // Because VC++ is upsetting, most of the time!
std::string w; std::string w;
public: public:

View File

@ -30,7 +30,7 @@
#endif // C++17 features macro #endif // C++17 features macro
#endif // C++17 features check #endif // C++17 features check
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
// TODO: there is a bug in the VC++ compiler?? // TODO: there is a bug in the VC++ compiler??
// on /std:c++latest under x86 conditions (VS 15.5.2), // on /std:c++latest under x86 conditions (VS 15.5.2),
// compiler errors are tossed for noexcept markings being on function types // compiler errors are tossed for noexcept markings being on function types
@ -51,138 +51,6 @@
#endif // Clang screws up variant #endif // Clang screws up variant
#endif // C++17 only #endif // C++17 only
#ifdef _MSC_VER #include <sol/config.hpp>
#if defined(_DEBUG) && !defined(NDEBUG)
#ifndef SOL_IN_DEBUG_DETECTED
#define SOL_IN_DEBUG_DETECTED 1
#endif
#endif // VC++ Debug macros
#ifndef _CPPUNWIND
#ifndef SOL_NO_EXCEPTIONS
#define SOL_NO_EXCEPTIONS 1
#endif
#endif // Automatic Exceptions
#ifndef _CPPRTTI
#ifndef SOL_NO_RTTI
#define SOL_NO_RTTI 1
#endif
#endif // Automatic RTTI
#elif defined(__GNUC__) || defined(__clang__)
#if !defined(NDEBUG) && !defined(__OPTIMIZE__)
#ifndef SOL_IN_DEBUG_DETECTED
#define SOL_IN_DEBUG_DETECTED 1
#endif
#endif // Not Debug && g++ optimizer flag
#ifndef __EXCEPTIONS
#ifndef SOL_NO_EXCEPTIONS
#define SOL_NO_EXCEPTIONS 1
#endif
#endif // No Exceptions
#ifndef __GXX_RTTI
#ifndef SOL_NO_RTII
#define SOL_NO_RTTI 1
#endif
#endif // No RTTI
#endif // vc++ || clang++/g++
#if defined(SOL_CHECK_ARGUMENTS)
// turn things on automatically
// Checks low-level getter function
// (and thusly, affects nearly entire framework)
#if !defined(SOL_SAFE_GETTER)
#define SOL_SAFE_GETTER 1
#endif
// Checks access on usertype functions
// local my_obj = my_type.new()
// my_obj.my_member_function()
// -- bad syntax and crash
#if !defined(SOL_SAFE_USERTYPE)
#define SOL_SAFE_USERTYPE 1
#endif
// Checks sol::reference derived boundaries
// sol::function ref(L, 1);
// sol::userdata sref(L, 2);
#if !defined(SOL_SAFE_REFERENCES)
#define SOL_SAFE_REFERENCES 1
#endif
// Changes all typedefs of sol::function to point to the
// protected_function version, instead of unsafe_function
#if !defined(SOL_SAFE_FUNCTION)
#define SOL_SAFE_FUNCTION 1
#endif
// Checks function parameters and
// returns upon call into/from Lua
// local a = 1
// local b = "woof"
// my_c_function(a, b)
#if !defined(SOL_SAFE_FUNCTION_CALLS)
#define SOL_SAFE_FUNCTION_CALLS 1
#endif
// Checks conversions
// int v = lua["bark"];
// int v2 = my_sol_function();
#if !defined(SOL_SAFE_PROXIES)
#define SOL_SAFE_PROXIES 1
#endif
// Check overflowing number conversions
// for things like 64 bit integers that don't fit in a typical lua_Number
// for Lua 5.1 and 5.2
#if !defined(SOL_SAFE_NUMERICS)
#define SOL_SAFE_NUMERICS 1
#endif
#endif // Turn on Safety for all if top-level macro is defined
#ifdef SOL_IN_DEBUG_DETECTED
#if !defined(SOL_SAFE_REFERENCES)
// Ensure that references are forcefully type-checked upon construction
#define SOL_SAFE_REFERENCES 1
#endif
#if !defined(SOL_SAFE_USERTYPE)
// Usertypes should be safe no matter what
#define SOL_SAFE_USERTYPE 1
#endif
#if !defined(SOL_SAFE_FUNCTION_CALLS)
// Function calls from Lua should be automatically safe in debug mode
#define SOL_SAFE_FUNCTION_CALLS 1
#endif
#endif // Turn on all debug safety features for VC++ / g++ / clang++ and similar
#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil)
#if !defined(SOL_NO_NIL)
#define SOL_NO_NIL 1
#endif
#endif // avoiding nil defines / keywords
#ifdef SOL_USE_BOOST
#ifndef SOL_UNORDERED_MAP_COMPATIBLE_HASH
#define SOL_UNORDERED_MAP_COMPATIBLE_HASH
#endif // SOL_UNORDERED_MAP_COMPATIBLE_HASH
#endif // Boost has unordered_map with Compatible Key and CompatibleHash
#ifndef SOL_STACK_STRING_OPTIMIZATION_SIZE
#define SOL_STACK_STRING_OPTIMIZATION_SIZE 1024
#endif // Optimized conversion routines using a KB or so off the stack
#endif // SOL_FEATURE_TEST_HPP #endif // SOL_FEATURE_TEST_HPP

View File

@ -81,7 +81,7 @@ namespace sol {
using main_protected_function = main_safe_function; using main_protected_function = main_safe_function;
using stack_protected_function = stack_safe_function; using stack_protected_function = stack_safe_function;
using stack_aligned_protected_function = stack_aligned_safe_function; using stack_aligned_protected_function = stack_aligned_safe_function;
#ifdef SOL_SAFE_FUNCTION #if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION
using function = protected_function; using function = protected_function;
using main_function = main_protected_function; using main_function = main_protected_function;
using stack_function = stack_protected_function; using stack_function = stack_protected_function;
@ -96,7 +96,7 @@ namespace sol {
struct unsafe_function_result; struct unsafe_function_result;
struct protected_function_result; struct protected_function_result;
using safe_function_result = protected_function_result; using safe_function_result = protected_function_result;
#ifdef SOL_SAFE_FUNCTION #if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION
using function_result = safe_function_result; using function_result = safe_function_result;
#else #else
using function_result = unsafe_function_result; using function_result = unsafe_function_result;

View File

@ -31,7 +31,7 @@
namespace sol { namespace sol {
namespace detail { namespace detail {
const bool default_safe_function_calls = const bool default_safe_function_calls =
#ifdef SOL_SAFE_FUNCTION_CALLS #if defined(SOL_SAFE_FUNCTION_CALLS) && SOL_SAFE_FUNCTION_CALLS
true; true;
#else #else
false; false;

View File

@ -199,7 +199,7 @@ namespace sol {
stack::push(L, f); stack::push(L, f);
} }
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
template <bool is_yielding> template <bool is_yielding>
static void select_function(std::true_type, lua_State* L, detail::lua_CFunction_noexcept f) { static void select_function(std::true_type, lua_State* L, detail::lua_CFunction_noexcept f) {
// TODO: support yielding // TODO: support yielding
@ -299,7 +299,7 @@ namespace sol {
template <typename Signature> template <typename Signature>
struct pusher<Signature, std::enable_if_t<meta::all<std::is_function<std::remove_pointer_t<Signature>>, meta::neg<std::is_same<Signature, lua_CFunction>>, meta::neg<std::is_same<Signature, std::remove_pointer_t<lua_CFunction>>> struct pusher<Signature, std::enable_if_t<meta::all<std::is_function<std::remove_pointer_t<Signature>>, meta::neg<std::is_same<Signature, lua_CFunction>>, meta::neg<std::is_same<Signature, std::remove_pointer_t<lua_CFunction>>>
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
, ,
meta::neg<std::is_same<Signature, detail::lua_CFunction_noexcept>>, meta::neg<std::is_same<Signature, std::remove_pointer_t<detail::lua_CFunction_noexcept>>> meta::neg<std::is_same<Signature, detail::lua_CFunction_noexcept>>, meta::neg<std::is_same<Signature, std::remove_pointer_t<detail::lua_CFunction_noexcept>>>
#endif // noexcept function types #endif // noexcept function types

View File

@ -120,7 +120,7 @@ namespace sol {
inline int c_call(lua_State* L) { inline int c_call(lua_State* L) {
typedef meta::unqualified_t<F> Fu; typedef meta::unqualified_t<F> Fu;
typedef std::integral_constant<bool, std::is_same<Fu, lua_CFunction>::value typedef std::integral_constant<bool, std::is_same<Fu, lua_CFunction>::value
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
|| std::is_same<Fu, detail::lua_CFunction_noexcept>::value || std::is_same<Fu, detail::lua_CFunction_noexcept>::value
#endif #endif
> is_raw; > is_raw;

View File

@ -29,7 +29,7 @@
namespace sol { namespace sol {
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
using in_place_t = std::in_place_t; using in_place_t = std::in_place_t;
constexpr std::in_place_t in_place{}; constexpr std::in_place_t in_place{};
constexpr std::in_place_t in_place_of{}; constexpr std::in_place_t in_place_of{};

View File

@ -48,7 +48,7 @@ namespace sol {
template <typename T> template <typename T>
decltype(auto) tagged_get(types<T>) const { decltype(auto) tagged_get(types<T>) const {
#ifdef SOL_SAFE_PROXIES #if defined(SOL_SAFE_PROXIES) && SOL_SAFE_PROXIES != 0
if (!valid()) { if (!valid()) {
type_panic_c_str(L, index, type_of(L, index), type::none); type_panic_c_str(L, index, type_of(L, index), type::none);
} }
@ -64,7 +64,7 @@ namespace sol {
} }
error tagged_get(types<error>) const { error tagged_get(types<error>) const {
#ifdef SOL_SAFE_PROXIES #if defined(SOL_SAFE_PROXIES) && SOL_SAFE_PROXIES != 0
if (valid()) { if (valid()) {
type_panic_c_str(L, index, type_of(L, index), type::none, "expecting an error type (a string, from Lua)"); type_panic_c_str(L, index, type_of(L, index), type::none, "expecting an error type (a string, from Lua)");
} }

View File

@ -26,7 +26,7 @@
#include "compatibility.hpp" #include "compatibility.hpp"
#include "in_place.hpp" #include "in_place.hpp"
#if defined(SOL_USE_BOOST) #if defined(SOL_USE_BOOST) && SOL_USE_BOOST
#include <boost/optional.hpp> #include <boost/optional.hpp>
#else #else
#include "optional_implementation.hpp" #include "optional_implementation.hpp"
@ -34,7 +34,7 @@
namespace sol { namespace sol {
#if defined(SOL_USE_BOOST) #if defined(SOL_USE_BOOST) && SOL_USE_BOOST
template <typename T> template <typename T>
using optional = boost::optional<T>; using optional = boost::optional<T>;
using nullopt_t = boost::none_t; using nullopt_t = boost::none_t;

View File

@ -41,7 +41,7 @@
#include <functional> #include <functional>
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#ifdef SOL_NO_EXCEPTIONS #if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
#include <cstdlib> #include <cstdlib>
#endif // Exceptions #endif // Exceptions

View File

@ -77,7 +77,7 @@ namespace sol {
int firstreturn = 1; int firstreturn = 1;
int returncount = 0; int returncount = 0;
call_status code = call_status::ok; call_status code = call_status::ok;
#ifndef SOL_NO_EXCEPTIONS #if !defined(SOL_NO_EXCEPTIONS) || !SOL_NO_EXCEPTIONS
auto onexcept = [&](optional<const std::exception&> maybe_ex, const char* error) { auto onexcept = [&](optional<const std::exception&> maybe_ex, const char* error) {
h.stackindex = 0; h.stackindex = 0;
if (b) { if (b) {
@ -90,7 +90,7 @@ namespace sol {
} }
}; };
(void)onexcept; (void)onexcept;
#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || defined(SOL_LUAJIT) #if (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !SOL_NO_EXCEPTIONS_SAFE_PROPAGATION) || (defined(SOL_LUAJIT) && SOL_LUAJIT)
try { try {
#endif // Safe Exception Propagation #endif // Safe Exception Propagation
#endif // No Exceptions #endif // No Exceptions
@ -99,7 +99,7 @@ namespace sol {
poststacksize = lua_gettop(lua_state()) - static_cast<int>(h.valid()); poststacksize = lua_gettop(lua_state()) - static_cast<int>(h.valid());
returncount = poststacksize - (firstreturn - 1); returncount = poststacksize - (firstreturn - 1);
#ifndef SOL_NO_EXCEPTIONS #ifndef SOL_NO_EXCEPTIONS
#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || defined(SOL_LUAJIT) #if (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !SOL_NO_EXCEPTIONS_SAFE_PROPAGATION) || (defined(SOL_LUAJIT) && SOL_LUAJIT)
} }
// Handle C++ errors thrown from C++ functions bound inside of lua // Handle C++ errors thrown from C++ functions bound inside of lua
catch (const char* error) { catch (const char* error) {
@ -117,7 +117,7 @@ namespace sol {
firstreturn = lua_gettop(lua_state()); firstreturn = lua_gettop(lua_state());
return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime); return protected_function_result(lua_state(), firstreturn, 0, 1, call_status::runtime);
} }
#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) #if (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !SOL_NO_EXCEPTIONS_SAFE_PROPAGATION)
// LuaJIT cannot have the catchall when the safe propagation is on // LuaJIT cannot have the catchall when the safe propagation is on
// but LuaJIT will swallow all C++ errors // but LuaJIT will swallow all C++ errors
// if we don't at least catch std::exception ones // if we don't at least catch std::exception ones
@ -143,7 +143,7 @@ namespace sol {
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_protected_function>>, meta::neg<std::is_base_of<proxy_base_tag, meta::unqualified_t<T>>>, meta::neg<std::is_same<base_t, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_protected_function>>, meta::neg<std::is_base_of<proxy_base_tag, meta::unqualified_t<T>>>, meta::neg<std::is_same<base_t, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_protected_function(T&& r) noexcept basic_protected_function(T&& r) noexcept
: base_t(std::forward<T>(r)), error_handler(get_default_handler(r.lua_state())) { : base_t(std::forward<T>(r)), error_handler(get_default_handler(r.lua_state())) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
if (!is_function<meta::unqualified_t<T>>::value) { if (!is_function<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
@ -200,7 +200,7 @@ namespace sol {
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_protected_function(lua_State* L, T&& r, handler_t eh) basic_protected_function(lua_State* L, T&& r, handler_t eh)
: base_t(L, std::forward<T>(r)), error_handler(std::move(eh)) { : base_t(L, std::forward<T>(r)), error_handler(std::move(eh)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_protected_function>(lua_state(), -1, handler); stack::check<basic_protected_function>(lua_state(), -1, handler);
@ -216,7 +216,7 @@ namespace sol {
} }
basic_protected_function(lua_State* L, int index, handler_t eh) basic_protected_function(lua_State* L, int index, handler_t eh)
: base_t(L, index), error_handler(std::move(eh)) { : base_t(L, index), error_handler(std::move(eh)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_protected_function>(L, index, handler); stack::check<basic_protected_function>(L, index, handler);
#endif // Safety #endif // Safety
@ -226,7 +226,7 @@ namespace sol {
} }
basic_protected_function(lua_State* L, absolute_index index, handler_t eh) basic_protected_function(lua_State* L, absolute_index index, handler_t eh)
: base_t(L, index), error_handler(std::move(eh)) { : base_t(L, index), error_handler(std::move(eh)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_protected_function>(L, index, handler); stack::check<basic_protected_function>(L, index, handler);
#endif // Safety #endif // Safety
@ -236,7 +236,7 @@ namespace sol {
} }
basic_protected_function(lua_State* L, raw_index index, handler_t eh) basic_protected_function(lua_State* L, raw_index index, handler_t eh)
: base_t(L, index), error_handler(std::move(eh)) { : base_t(L, index), error_handler(std::move(eh)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_protected_function>(L, index, handler); stack::check<basic_protected_function>(L, index, handler);
#endif // Safety #endif // Safety
@ -246,7 +246,7 @@ namespace sol {
} }
basic_protected_function(lua_State* L, ref_index index, handler_t eh) basic_protected_function(lua_State* L, ref_index index, handler_t eh)
: base_t(L, index), error_handler(std::move(eh)) { : base_t(L, index), error_handler(std::move(eh)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_protected_function>(lua_state(), -1, handler); stack::check<basic_protected_function>(lua_state(), -1, handler);

View File

@ -54,7 +54,7 @@ namespace sol {
template <typename T> template <typename T>
decltype(auto) tagged_get(types<T>, int index_offset) const { decltype(auto) tagged_get(types<T>, int index_offset) const {
int target = index + index_offset; int target = index + index_offset;
#ifdef SOL_SAFE_PROXIES #if defined(SOL_SAFE_PROXIES) && SOL_SAFE_PROXIES
if (!valid()) { if (!valid()) {
type t = type_of(L, target); type t = type_of(L, target);
type_panic_c_str(L, target, t, type::none, "bad get from protected_function_result (is not an error)"); type_panic_c_str(L, target, t, type::none, "bad get from protected_function_result (is not an error)");
@ -73,7 +73,7 @@ namespace sol {
error tagged_get(types<error>, int index_offset) const { error tagged_get(types<error>, int index_offset) const {
int target = index + index_offset; int target = index + index_offset;
#ifdef SOL_SAFE_PROXIES #if defined(SOL_SAFE_PROXIES) && SOL_SAFE_PROXIES
if (valid()) { if (valid()) {
type t = type_of(L, target); type t = type_of(L, target);
type_panic_c_str(L, target, t, type::none, "bad get from protected_function_result (is an error)"); type_panic_c_str(L, target, t, type::none, "bad get from protected_function_result (is an error)");

View File

@ -70,7 +70,7 @@ namespace sol {
string_view accessor = stack::get<string_view>(L, keyidx); string_view accessor = stack::get<string_view>(L, keyidx);
variable_wrapper* varwrap = nullptr; variable_wrapper* varwrap = nullptr;
{ {
#ifdef SOL_UNORDERED_MAP_COMPATIBLE_HASH #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
string_view& accessorkey = accessor; string_view& accessorkey = accessor;
auto vit = variables.find(accessorkey, string_view_hash(), std::equal_to<string_view>()); auto vit = variables.find(accessorkey, string_view_hash(), std::equal_to<string_view>());
#else #else
@ -86,7 +86,7 @@ namespace sol {
} }
bool function_failed = false; bool function_failed = false;
{ {
#ifdef SOL_UNORDERED_MAP_COMPATIBLE_HASH #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
string_view& accessorkey = accessor; string_view& accessorkey = accessor;
auto fit = functions.find(accessorkey, string_view_hash(), std::equal_to<string_view>()); auto fit = functions.find(accessorkey, string_view_hash(), std::equal_to<string_view>());
#else #else
@ -453,19 +453,19 @@ namespace sol {
switch (mf) { switch (mf) {
case meta_function::construct: case meta_function::construct:
if (prop) { if (prop) {
#ifndef SOL_NO_EXCEPTIONS #if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
#else
assert(false && "sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems"); assert(false && "sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
#else
throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
#endif #endif
} }
break; break;
case meta_function::garbage_collect: case meta_function::garbage_collect:
if (prop) { if (prop) {
#ifndef SOL_NO_EXCEPTIONS #if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
#else
assert(false && "sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems"); assert(false && "sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
#else
throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
#endif #endif
} }
return; return;

View File

@ -99,7 +99,7 @@ namespace stack {
static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
tracking.use(1); tracking.use(1);
#if SOL_LUA_VERSION >= 503 #if SOL_LUA_VERSION >= 503
#ifdef SOL_STRINGS_ARE_NUMBERS #if defined(SOL_STRINGS_ARE_NUMBERS) && SOL_STRINGS_ARE_NUMBERS
int isnum = 0; int isnum = 0;
lua_tointegerx(L, index, &isnum); lua_tointegerx(L, index, &isnum);
const bool success = isnum != 0; const bool success = isnum != 0;
@ -107,20 +107,27 @@ namespace stack {
// expected type, actual type // expected type, actual type
handler(L, index, type::number, type_of(L, index), "not a numeric type or numeric string"); handler(L, index, type::number, type_of(L, index), "not a numeric type or numeric string");
} }
#else #elif (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
// this check is precise, does not convert // this check is precise, does not convert
if (lua_isinteger(L, index) == 1) { if (lua_isinteger(L, index) == 1) {
return true; return true;
} }
const bool success = false; const bool success = false;
if (!success) {
// expected type, actual type
handler(L, index, type::number, type_of(L, index), "not a numeric (integral) type");
}
#else
type t = type_of(L, index);
const bool success = t == type::number;
#endif // If numbers are enabled, use the imprecise check
if (!success) { if (!success) {
// expected type, actual type // expected type, actual type
handler(L, index, type::number, type_of(L, index), "not a numeric type"); handler(L, index, type::number, type_of(L, index), "not a numeric type");
} }
#endif // If numbers are enabled, use the imprecise check
return success; return success;
#else #else
#ifndef SOL_STRINGS_ARE_NUMBERS #if !defined(SOL_STRINGS_ARE_NUMBERS) || !SOL_STRINGS_ARE_NUMBERS
// must pre-check, because it will convert // must pre-check, because it will convert
type t = type_of(L, index); type t = type_of(L, index);
if (t != type::number) { if (t != type::number) {
@ -131,17 +138,21 @@ namespace stack {
#endif // Do not allow strings to be numbers #endif // Do not allow strings to be numbers
int isnum = 0; int isnum = 0;
const lua_Number v = lua_tonumberx(L, index, &isnum); const lua_Number v = lua_tonumberx(L, index, &isnum);
const bool success = isnum != 0 && static_cast<lua_Number>(llround(v)) == v; const bool success = isnum != 0
#if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
&& static_cast<lua_Number>(llround(v)) == v
#endif // Safe numerics and number precision checking
;
if (!success) { if (!success) {
// expected type, actual type // expected type, actual type
#ifndef SOL_STRINGS_ARE_NUMBERS #if defined(SOL_STRINGS_ARE_NUMBERS) && SOL_STRINGS_ARE_NUMBERS
handler(L, index, type::number, t, "not a numeric type"); handler(L, index, type::number, t, "not a numeric type");
#else #else
handler(L, index, type::number, type_of(L, index), "not a numeric type or numeric string"); handler(L, index, type::number, type_of(L, index), "not a numeric type or numeric string");
#endif #endif
} }
return success; return success;
#endif #endif // Lua Version 5.3 versus others
} }
}; };
@ -150,7 +161,14 @@ namespace stack {
template <typename Handler> template <typename Handler>
static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
tracking.use(1); tracking.use(1);
#ifndef SOL_STRINGS_ARE_NUMBERS #if defined(SOL_STRINGS_ARE_NUMBERS) && SOL_STRINGS_ARE_NUMBERS
bool success = lua_isnumber(L, index) == 1;
if (!success) {
// expected type, actual type
handler(L, index, type::number, type_of(L, index), "not a numeric type or numeric string");
}
return success;
#else
type t = type_of(L, index); type t = type_of(L, index);
bool success = t == type::number; bool success = t == type::number;
if (!success) { if (!success) {
@ -158,14 +176,7 @@ namespace stack {
handler(L, index, type::number, t, "not a numeric type"); handler(L, index, type::number, t, "not a numeric type");
} }
return success; return success;
#else #endif // Strings are Numbers
bool success = lua_isnumber(L, index) == 1;
if (!success) {
// expected type, actual type
handler(L, index, type::number, type_of(L, index), "not a numeric type or numeric string");
}
return success;
#endif
} }
}; };
@ -424,7 +435,7 @@ namespace stack {
template <typename U, typename Handler> template <typename U, typename Handler>
static bool check(types<U>, lua_State* L, int index, type indextype, Handler&& handler, record& tracking) { static bool check(types<U>, lua_State* L, int index, type indextype, Handler&& handler, record& tracking) {
#ifdef SOL_ENABLE_INTEROP #if defined(SOL_ENABLE_INTEROP) && SOL_ENABLE_INTEROP
userdata_checker<extensible<T>> uc; userdata_checker<extensible<T>> uc;
(void)uc; (void)uc;
if (uc.check(L, index, indextype, handler, tracking)) { if (uc.check(L, index, indextype, handler, tracking)) {
@ -577,8 +588,8 @@ namespace stack {
} }
}; };
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#ifdef SOL_STD_VARIANT #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
template <typename... Tn, typename C> template <typename... Tn, typename C>
struct checker<std::variant<Tn...>, type::poly, C> { struct checker<std::variant<Tn...>, type::poly, C> {
typedef std::variant<Tn...> V; typedef std::variant<Tn...> V;

View File

@ -85,7 +85,7 @@ namespace stack {
int isnum = 0; int isnum = 0;
const lua_Number value = lua_tonumberx(L, index, &isnum); const lua_Number value = lua_tonumberx(L, index, &isnum);
if (isnum != 0) { if (isnum != 0) {
#if defined(SOL_SAFE_NUMERICS) && !defined(SOL_NO_CHECK_NUMBER_PRECISION) #if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
const auto integer_value = llround(value); const auto integer_value = llround(value);
if (static_cast<lua_Number>(integer_value) == value) { if (static_cast<lua_Number>(integer_value) == value) {
tracking.use(1); tracking.use(1);
@ -144,8 +144,8 @@ namespace stack {
} }
}; };
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#ifdef SOL_STD_VARIANT #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
template <typename... Tn> template <typename... Tn>
struct check_getter<std::variant<Tn...>> { struct check_getter<std::variant<Tn...>> {
typedef std::variant<Tn...> V; typedef std::variant<Tn...> V;

View File

@ -88,7 +88,7 @@ namespace sol {
inline void* align_usertype_pointer(void* ptr) { inline void* align_usertype_pointer(void* ptr) {
typedef std::integral_constant<bool, typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false false
#else #else
(std::alignment_of<void*>::value > 1) (std::alignment_of<void*>::value > 1)
@ -104,7 +104,7 @@ namespace sol {
inline void* align_usertype_unique_destructor(void* ptr) { inline void* align_usertype_unique_destructor(void* ptr) {
typedef std::integral_constant<bool, typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false false
#else #else
(std::alignment_of<unique_destructor>::value > 1) (std::alignment_of<unique_destructor>::value > 1)
@ -123,7 +123,7 @@ namespace sol {
template <typename T, bool pre_aligned = false> template <typename T, bool pre_aligned = false>
inline void* align_usertype_unique(void* ptr) { inline void* align_usertype_unique(void* ptr) {
typedef std::integral_constant<bool, typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false false
#else #else
(std::alignment_of<T>::value > 1) (std::alignment_of<T>::value > 1)
@ -144,7 +144,7 @@ namespace sol {
template <typename T> template <typename T>
inline void* align_user(void* ptr) { inline void* align_user(void* ptr) {
typedef std::integral_constant<bool, typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false false
#else #else
(std::alignment_of<T>::value > 1) (std::alignment_of<T>::value > 1)
@ -161,7 +161,7 @@ namespace sol {
template <typename T> template <typename T>
inline T** usertype_allocate_pointer(lua_State* L) { inline T** usertype_allocate_pointer(lua_State* L) {
typedef std::integral_constant<bool, typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false false
#else #else
(std::alignment_of<T*>::value > 1) (std::alignment_of<T*>::value > 1)
@ -198,7 +198,7 @@ namespace sol {
template <typename T> template <typename T>
inline T* usertype_allocate(lua_State* L) { inline T* usertype_allocate(lua_State* L) {
typedef std::integral_constant<bool, typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false false
#else #else
(std::alignment_of<T*>::value > 1 || std::alignment_of<T>::value > 1) (std::alignment_of<T*>::value > 1 || std::alignment_of<T>::value > 1)
@ -278,7 +278,7 @@ namespace sol {
template <typename T, typename Real> template <typename T, typename Real>
inline Real* usertype_unique_allocate(lua_State* L, T**& pref, unique_destructor*& dx) { inline Real* usertype_unique_allocate(lua_State* L, T**& pref, unique_destructor*& dx) {
typedef std::integral_constant<bool, typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false false
#else #else
(std::alignment_of<T*>::value > 1 || std::alignment_of<unique_destructor>::value > 1 || std::alignment_of<Real>::value > 1) (std::alignment_of<T*>::value > 1 || std::alignment_of<unique_destructor>::value > 1 || std::alignment_of<Real>::value > 1)
@ -352,7 +352,7 @@ namespace sol {
template <typename T> template <typename T>
inline T* user_allocate(lua_State* L) { inline T* user_allocate(lua_State* L) {
typedef std::integral_constant<bool, typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT #if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false false
#else #else
(std::alignment_of<T>::value > 1) (std::alignment_of<T>::value > 1)
@ -705,7 +705,7 @@ namespace sol {
namespace stack_detail { namespace stack_detail {
#ifdef SOL_SAFE_GETTER #if defined(SOL_SAFE_GETTER) && SOL_SAFE_GETTER
template <typename T> template <typename T>
inline auto tagged_get(types<T>, lua_State* L, int index, record& tracking) -> decltype(stack_detail::unchecked_get<T>(L, index, tracking)) { inline auto tagged_get(types<T>, lua_State* L, int index, record& tracking) -> decltype(stack_detail::unchecked_get<T>(L, index, tracking)) {
auto op = check_get<T>(L, index, type_panic_c_str, tracking); auto op = check_get<T>(L, index, type_panic_c_str, tracking);
@ -782,7 +782,7 @@ namespace sol {
template <typename T> template <typename T>
inline decltype(auto) get_usertype(lua_State* L, int index, record& tracking) { inline decltype(auto) get_usertype(lua_State* L, int index, record& tracking) {
#ifdef SOL_SAFE_GETTER #if defined(SOL_SAFE_GETTER) && SOL_SAFE_GETTER
return stack_detail::tagged_get(types<std::conditional_t<std::is_pointer<T>::value, detail::as_pointer_tag<std::remove_pointer_t<T>>, detail::as_value_tag<T>>>(), L, index, tracking); return stack_detail::tagged_get(types<std::conditional_t<std::is_pointer<T>::value, detail::as_pointer_tag<std::remove_pointer_t<T>>, detail::as_value_tag<T>>>(), L, index, tracking);
#else #else
return stack_detail::unchecked_get<std::conditional_t<std::is_pointer<T>::value, detail::as_pointer_tag<std::remove_pointer_t<T>>, detail::as_value_tag<T>>>(L, index, tracking); return stack_detail::unchecked_get<std::conditional_t<std::is_pointer<T>::value, detail::as_pointer_tag<std::remove_pointer_t<T>>, detail::as_value_tag<T>>>(L, index, tracking);

View File

@ -36,9 +36,9 @@
#include <utility> #include <utility>
#include <cstdlib> #include <cstdlib>
#include <cmath> #include <cmath>
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <string_view> #include <string_view>
#ifdef SOL_STD_VARIANT #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
#include <variant> #include <variant>
#endif // Apple clang screwed up #endif // Apple clang screwed up
#endif // C++17 #endif // C++17
@ -712,7 +712,7 @@ namespace stack {
struct getter<detail::as_value_tag<T>> { struct getter<detail::as_value_tag<T>> {
static T* get_no_lua_nil(lua_State* L, int index, record& tracking) { static T* get_no_lua_nil(lua_State* L, int index, record& tracking) {
void* memory = lua_touserdata(L, index); void* memory = lua_touserdata(L, index);
#ifdef SOL_ENABLE_INTEROP #if defined(SOL_ENABLE_INTEROP) && SOL_ENABLE_INTEROP
userdata_getter<extensible<T>> ug; userdata_getter<extensible<T>> ug;
(void)ug; (void)ug;
auto ugr = ug.get(L, index, memory, tracking); auto ugr = ug.get(L, index, memory, tracking);
@ -842,8 +842,8 @@ namespace stack {
} }
}; };
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#ifdef SOL_STD_VARIANT #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
template <typename... Tn> template <typename... Tn>
struct getter<std::variant<Tn...>> { struct getter<std::variant<Tn...>> {
typedef std::variant<Tn...> V; typedef std::variant<Tn...> V;

View File

@ -31,7 +31,7 @@
namespace sol { namespace sol {
namespace detail { namespace detail {
inline void stack_fail(int, int) { inline void stack_fail(int, int) {
#ifndef SOL_NO_EXCEPTIONS #if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
throw error(detail::direct_error, "imbalanced stack after operation finish"); throw error(detail::direct_error, "imbalanced stack after operation finish");
#else #else
// Lol, what do you want, an error printout? :3c // Lol, what do you want, an error printout? :3c

View File

@ -47,7 +47,7 @@ namespace stack {
template <typename T> template <typename T>
struct popper<T, std::enable_if_t<is_stack_based<meta::unqualified_t<T>>::value>> { struct popper<T, std::enable_if_t<is_stack_based<meta::unqualified_t<T>>::value>> {
static_assert(meta::neg<std::is_base_of<stack_reference, meta::unqualified_t<T>>>::value, "You cannot pop something that derives from stack_reference: it will not remain on the stack and thusly will go out of scope!"); static_assert(meta::neg<is_stack_based<meta::unqualified_t<T>>>::value, "You cannot pop something that lives solely on the stack: it will not remain on the stack when popped and thusly will go out of scope!");
}; };
} }
} // namespace sol::stack } // namespace sol::stack

View File

@ -35,9 +35,9 @@
#include <type_traits> #include <type_traits>
#include <cassert> #include <cassert>
#include <limits> #include <limits>
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <string_view> #include <string_view>
#ifdef SOL_STD_VARIANT #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
#include <variant> #include <variant>
#endif // Can use variant #endif // Can use variant
#endif // C++17 #endif // C++17
@ -214,19 +214,19 @@ namespace stack {
lua_pushinteger(L, static_cast<lua_Integer>(value)); lua_pushinteger(L, static_cast<lua_Integer>(value));
return 1; return 1;
} }
#endif #endif // Lua 5.3 and above
#if defined(SOL_SAFE_NUMERICS) && !defined(SOL_NO_CHECK_NUMBER_PRECISION) #if (defined(SOL_SAFE_NUMERICS) && SOL_SAFE_NUMERICS) && !(defined(SOL_NO_CHECK_NUMBER_PRECISION) && SOL_NO_CHECK_NUMBER_PRECISION)
if (static_cast<T>(llround(static_cast<lua_Number>(value))) != value) { if (static_cast<T>(llround(static_cast<lua_Number>(value))) != value) {
#ifdef SOL_NO_EXCEPTIONS #if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
// Is this really worth it? // Is this really worth it?
assert(false && "integer value will be misrepresented in lua"); assert(false && "integer value will be misrepresented in lua");
lua_pushnumber(L, static_cast<lua_Number>(value)); lua_pushnumber(L, static_cast<lua_Number>(value));
return 1; return 1;
#else #else
throw error(detail::direct_error, "integer value will be misrepresented in lua"); throw error(detail::direct_error, "integer value will be misrepresented in lua");
#endif #endif // No Exceptions
} }
#endif #endif // Safe Numerics and Number Precision Check
lua_pushnumber(L, static_cast<lua_Number>(value)); lua_pushnumber(L, static_cast<lua_Number>(value));
return 1; return 1;
} }
@ -288,7 +288,7 @@ namespace stack {
} }
lua_pop(L, 1 + p); lua_pop(L, 1 + p);
} }
#endif #endif // Lua Version 5.3 and others
} }
// TODO: figure out a better way to do this...? // TODO: figure out a better way to do this...?
//set_field(L, -1, cont.size()); //set_field(L, -1, cont.size());
@ -388,7 +388,7 @@ namespace stack {
} }
}; };
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
template <> template <>
struct pusher<std::remove_pointer_t<detail::lua_CFunction_noexcept>> { struct pusher<std::remove_pointer_t<detail::lua_CFunction_noexcept>> {
static int push(lua_State* L, detail::lua_CFunction_noexcept func, int n = 0) { static int push(lua_State* L, detail::lua_CFunction_noexcept func, int n = 0) {
@ -988,8 +988,8 @@ namespace stack {
} }
}; };
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#ifdef SOL_STD_VARIANT #if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
namespace stack_detail { namespace stack_detail {
struct push_function { struct push_function {

View File

@ -49,7 +49,7 @@ namespace sol {
} }
inline int default_at_panic(lua_State* L) { inline int default_at_panic(lua_State* L) {
#ifdef SOL_NO_EXCEPTIONS #if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
(void)L; (void)L;
return -1; return -1;
#else #else
@ -58,7 +58,7 @@ namespace sol {
if (message) { if (message) {
std::string err(message, messagesize); std::string err(message, messagesize);
lua_settop(L, 0); lua_settop(L, 0);
#ifdef SOL_PRINT_ERRORS #if defined(SOL_PRINT_ERRORS) && SOL_PRINT_ERRORS
std::cerr << "[sol2] An error occurred and panic has been invoked: "; std::cerr << "[sol2] An error occurred and panic has been invoked: ";
std::cerr << err; std::cerr << err;
std::cerr << std::endl; std::cerr << std::endl;
@ -66,8 +66,8 @@ namespace sol {
throw error(err); throw error(err);
} }
lua_settop(L, 0); lua_settop(L, 0);
throw error(std::string("An unexpected error occurred and forced the lua state to call atpanic")); throw error(std::string("An unexpected error occurred and panic has been invoked"));
#endif #endif // Printing Errors
} }
inline int default_traceback_error_handler(lua_State* L) { inline int default_traceback_error_handler(lua_State* L) {
@ -83,11 +83,11 @@ namespace sol {
const string_view& traceback = maybetraceback.value(); const string_view& traceback = maybetraceback.value();
msg.assign(traceback.data(), traceback.size()); msg.assign(traceback.data(), traceback.size());
} }
#ifdef SOL_PRINT_ERRORS #if defined(SOL_PRINT_ERRORS) && SOL_PRINT_ERRORS
std::cerr << "[sol2] An error occurred: "; //std::cerr << "[sol2] An error occurred and was caught in traceback: ";
std::cerr << msg; //std::cerr << msg;
std::cerr << std::endl; //std::cerr << std::endl;
#endif #endif // Printing
return stack::push(L, msg); return stack::push(L, msg);
} }
@ -115,7 +115,7 @@ namespace sol {
std::string err = "sol: "; std::string err = "sol: ";
err += to_string(result.status()); err += to_string(result.status());
err += " error"; err += " error";
#ifndef SOL_NO_EXCEPTIONS #if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
std::exception_ptr eptr = std::current_exception(); std::exception_ptr eptr = std::current_exception();
if (eptr) { if (eptr) {
err += " with a "; err += " with a ";
@ -144,12 +144,12 @@ namespace sol {
string_view serr = stack::get<string_view>(L, result.stack_index()); string_view serr = stack::get<string_view>(L, result.stack_index());
err.append(serr.data(), serr.size()); err.append(serr.data(), serr.size());
} }
#ifdef SOL_PRINT_ERRORS #if defined(SOL_PRINT_ERRORS) && SOL_PRINT_ERRORS
std::cerr << "[sol2] An error occurred and has been passed to an error handler: "; std::cerr << "[sol2] An error occurred and has been passed to an error handler: ";
std::cerr << err; std::cerr << err;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
#ifdef SOL_NO_EXCEPTIONS #if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
// replacing information of stack error into pfr // replacing information of stack error into pfr
int target = result.stack_index(); int target = result.stack_index();
if (result.pop_count() > 0) { if (result.pop_count() > 0) {
@ -169,7 +169,7 @@ namespace sol {
} }
inline protected_function_result script_default_on_error(lua_State* L, protected_function_result pfr) { inline protected_function_result script_default_on_error(lua_State* L, protected_function_result pfr) {
#ifdef SOL_DEFAULT_PASS_ON_ERROR #if defined(SOL_DEFAULT_PASS_ON_ERROR) && SOL_DEFAULT_PASS_ON_ERROR
return script_pass_on_error(L, std::move(pfr)); return script_pass_on_error(L, std::move(pfr));
#else #else
return script_throw_on_error(L, std::move(pfr)); return script_throw_on_error(L, std::move(pfr));

View File

@ -391,7 +391,7 @@ namespace sol {
return safe_script_file(filename, env, script_default_on_error, mode); return safe_script_file(filename, env, script_default_on_error, mode);
} }
#ifdef SOL_SAFE_FUNCTION #if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION
protected_function_result script(const string_view& code, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) { protected_function_result script(const string_view& code, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) {
return safe_script(code, chunkname, mode); return safe_script(code, chunkname, mode);
} }

View File

@ -27,16 +27,16 @@
#include "feature_test.hpp" #include "feature_test.hpp"
#include <cstddef> #include <cstddef>
#include <string> #include <string>
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <string_view> #include <string_view>
#endif // C++17 features #endif // C++17 features
#include <functional> #include <functional>
#ifdef SOL_USE_BOOST #if defined(SOL_USE_BOOST) && SOL_USE_BOOST
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
#endif #endif
namespace sol { namespace sol {
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
template <typename C, typename T = std::char_traits<C>> template <typename C, typename T = std::char_traits<C>>
using basic_string_view = std::basic_string_view<C, T>; using basic_string_view = std::basic_string_view<C, T>;
typedef std::string_view string_view; typedef std::string_view string_view;
@ -139,7 +139,7 @@ namespace sol {
} }
result_type operator()(const argument_type& r) const { result_type operator()(const argument_type& r) const {
#ifdef SOL_USE_BOOST #if defined(SOL_USE_BOOST) && SOL_USE_BOOST
return boost::hash_range(r.begin(), r.end()); return boost::hash_range(r.begin(), r.end());
#else #else
// Modified, from libstdc++ // Modified, from libstdc++

View File

@ -218,7 +218,7 @@ namespace sol {
template <typename T, meta::enable_any<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable_any<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_table_core(lua_State* L, T&& r) basic_table_core(lua_State* L, T&& r)
: base_t(L, std::forward<T>(r)) { : base_t(L, std::forward<T>(r)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_table_core>(lua_state(), -1, handler); stack::check<basic_table_core>(lua_state(), -1, handler);
@ -232,14 +232,14 @@ namespace sol {
} }
basic_table_core(lua_State* L, int index = -1) basic_table_core(lua_State* L, int index = -1)
: basic_table_core(detail::no_safety, L, index) { : basic_table_core(detail::no_safety, L, index) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_table_core>(L, index, handler); stack::check<basic_table_core>(L, index, handler);
#endif // Safety #endif // Safety
} }
basic_table_core(lua_State* L, ref_index index) basic_table_core(lua_State* L, ref_index index)
: basic_table_core(detail::no_safety, L, index) { : basic_table_core(detail::no_safety, L, index) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_table_core>(lua_state(), -1, handler); stack::check<basic_table_core>(lua_state(), -1, handler);
@ -248,7 +248,7 @@ namespace sol {
template <typename T, meta::enable<meta::neg<meta::any_same<meta::unqualified_t<T>, basic_table_core>>, meta::neg<std::is_same<base_type, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<meta::neg<meta::any_same<meta::unqualified_t<T>, basic_table_core>>, meta::neg<std::is_same<base_type, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_table_core(T&& r) noexcept basic_table_core(T&& r) noexcept
: basic_table_core(detail::no_safety, std::forward<T>(r)) { : basic_table_core(detail::no_safety, std::forward<T>(r)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
if (!is_table<meta::unqualified_t<T>>::value) { if (!is_table<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};

View File

@ -90,7 +90,7 @@ namespace sol {
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_thread>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_thread>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_thread(T&& r) basic_thread(T&& r)
: base_t(std::forward<T>(r)) { : base_t(std::forward<T>(r)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_thread>(lua_state(), -1, handler); stack::check<basic_thread>(lua_state(), -1, handler);
@ -105,7 +105,7 @@ namespace sol {
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_thread(lua_State* L, T&& r) basic_thread(lua_State* L, T&& r)
: base_t(L, std::forward<T>(r)) { : base_t(L, std::forward<T>(r)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_thread>(lua_state(), -1, handler); stack::check<basic_thread>(lua_state(), -1, handler);
@ -113,14 +113,14 @@ namespace sol {
} }
basic_thread(lua_State* L, int index = -1) basic_thread(lua_State* L, int index = -1)
: base_t(L, index) { : base_t(L, index) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_thread>(L, index, handler); stack::check<basic_thread>(L, index, handler);
#endif // Safety #endif // Safety
} }
basic_thread(lua_State* L, ref_index index) basic_thread(lua_State* L, ref_index index)
: base_t(L, index) { : base_t(L, index) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_thread>(lua_state(), -1, handler); stack::check<basic_thread>(lua_state(), -1, handler);
@ -134,7 +134,7 @@ namespace sol {
} }
basic_thread(lua_State* L, lua_thread_state actualthread) basic_thread(lua_State* L, lua_thread_state actualthread)
: base_t(L, -stack::push(L, actualthread)) { : base_t(L, -stack::push(L, actualthread)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_thread>(lua_state(), -1, handler); stack::check<basic_thread>(lua_state(), -1, handler);
#endif // Safety #endif // Safety

View File

@ -560,7 +560,7 @@ namespace sol {
template <typename T> template <typename T>
using is_string_like = any< using is_string_like = any<
is_specialization_of<meta::unqualified_t<T>, std::basic_string>, is_specialization_of<meta::unqualified_t<T>, std::basic_string>,
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
is_specialization_of<meta::unqualified_t<T>, std::basic_string_view>, is_specialization_of<meta::unqualified_t<T>, std::basic_string_view>,
#else #else
is_specialization_of<meta::unqualified_t<T>, basic_string_view>, is_specialization_of<meta::unqualified_t<T>, basic_string_view>,
@ -573,7 +573,7 @@ namespace sol {
meta::all<std::is_array<unqualified_t<T>>, std::is_same<meta::unqualified_t<std::remove_all_extents_t<meta::unqualified_t<T>>>, char>>, meta::all<std::is_array<unqualified_t<T>>, std::is_same<meta::unqualified_t<std::remove_all_extents_t<meta::unqualified_t<T>>>, char>>,
std::is_same<unqualified_t<T>, const char*>, std::is_same<unqualified_t<T>, const char*>,
std::is_same<unqualified_t<T>, char>, std::is_same<unqualified_t<T>, std::string>, std::is_same<unqualified_t<T>, std::initializer_list<char>> std::is_same<unqualified_t<T>, char>, std::is_same<unqualified_t<T>, std::string>, std::is_same<unqualified_t<T>, std::initializer_list<char>>
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
, std::is_same<unqualified_t<T>, std::string_view> , std::is_same<unqualified_t<T>, std::string_view>
#endif #endif
>; >;

View File

@ -37,7 +37,7 @@
#include <array> #include <array>
#include <initializer_list> #include <initializer_list>
#include <string> #include <string>
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <string_view> #include <string_view>
#ifdef SOL_STD_VARIANT #ifdef SOL_STD_VARIANT
#include <variant> #include <variant>
@ -982,7 +982,7 @@ namespace sol {
template <> template <>
struct lua_type_of<meta_function> : std::integral_constant<type, type::string> {}; struct lua_type_of<meta_function> : std::integral_constant<type, type::string> {};
#ifdef SOL_CXX17_FEATURES #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#ifdef SOL_STD_VARIANT #ifdef SOL_STD_VARIANT
template <typename... Tn> template <typename... Tn>
struct lua_type_of<std::variant<Tn...>> : std::integral_constant<type, type::poly> {}; struct lua_type_of<std::variant<Tn...>> : std::integral_constant<type, type::poly> {};

View File

@ -71,7 +71,7 @@ namespace sol {
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_function>>, meta::neg<std::is_same<base_t, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_function>>, meta::neg<std::is_same<base_t, stack_reference>>, meta::neg<std::is_same<lua_nil_t, meta::unqualified_t<T>>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_function(T&& r) noexcept basic_function(T&& r) noexcept
: base_t(std::forward<T>(r)) { : base_t(std::forward<T>(r)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
if (!is_function<meta::unqualified_t<T>>::value) { if (!is_function<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
@ -95,7 +95,7 @@ namespace sol {
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_function(lua_State* L, T&& r) basic_function(lua_State* L, T&& r)
: base_t(L, std::forward<T>(r)) { : base_t(L, std::forward<T>(r)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_function>(lua_state(), -1, handler); stack::check<basic_function>(lua_state(), -1, handler);
@ -103,14 +103,14 @@ namespace sol {
} }
basic_function(lua_State* L, int index = -1) basic_function(lua_State* L, int index = -1)
: base_t(L, index) { : base_t(L, index) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_function>(L, index, handler); stack::check<basic_function>(L, index, handler);
#endif // Safety #endif // Safety
} }
basic_function(lua_State* L, ref_index index) basic_function(lua_State* L, ref_index index)
: base_t(L, index) { : base_t(L, index) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_function>(lua_state(), -1, handler); stack::check<basic_function>(lua_state(), -1, handler);

View File

@ -39,7 +39,7 @@ namespace sol {
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_userdata>>, meta::neg<std::is_same<base_t, stack_reference>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_userdata>>, meta::neg<std::is_same<base_t, stack_reference>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_userdata(T&& r) noexcept basic_userdata(T&& r) noexcept
: base_t(std::forward<T>(r)) { : base_t(std::forward<T>(r)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
if (!is_userdata<meta::unqualified_t<T>>::value) { if (!is_userdata<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
type_assert(lua_state(), -1, type::userdata); type_assert(lua_state(), -1, type::userdata);
@ -59,7 +59,7 @@ namespace sol {
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_userdata(lua_State* L, T&& r) basic_userdata(lua_State* L, T&& r)
: base_t(L, std::forward<T>(r)) { : base_t(L, std::forward<T>(r)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_userdata>(L, -1, handler); stack::check<basic_userdata>(L, -1, handler);
@ -67,14 +67,14 @@ namespace sol {
} }
basic_userdata(lua_State* L, int index = -1) basic_userdata(lua_State* L, int index = -1)
: base_t(detail::no_safety, L, index) { : base_t(detail::no_safety, L, index) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_userdata>(L, index, handler); stack::check<basic_userdata>(L, index, handler);
#endif // Safety #endif // Safety
} }
basic_userdata(lua_State* L, ref_index index) basic_userdata(lua_State* L, ref_index index)
: base_t(detail::no_safety, L, index) { : base_t(detail::no_safety, L, index) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_userdata>(L, -1, handler); stack::check<basic_userdata>(L, -1, handler);
@ -93,7 +93,7 @@ namespace sol {
template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_lightuserdata>>, meta::neg<std::is_same<base_t, stack_reference>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<meta::neg<std::is_same<meta::unqualified_t<T>, basic_lightuserdata>>, meta::neg<std::is_same<base_t, stack_reference>>, is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_lightuserdata(T&& r) noexcept basic_lightuserdata(T&& r) noexcept
: base_t(std::forward<T>(r)) { : base_t(std::forward<T>(r)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
if (!is_lightuserdata<meta::unqualified_t<T>>::value) { if (!is_lightuserdata<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
type_assert(lua_state(), -1, type::lightuserdata); type_assert(lua_state(), -1, type::lightuserdata);
@ -113,7 +113,7 @@ namespace sol {
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler> template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_lightuserdata(lua_State* L, T&& r) basic_lightuserdata(lua_State* L, T&& r)
: basic_lightuserdata(L, std::forward<T>(r)) { : basic_lightuserdata(L, std::forward<T>(r)) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_lightuserdata>(lua_state(), -1, handler); stack::check<basic_lightuserdata>(lua_state(), -1, handler);
@ -121,14 +121,14 @@ namespace sol {
} }
basic_lightuserdata(lua_State* L, int index = -1) basic_lightuserdata(lua_State* L, int index = -1)
: base_t(L, index) { : base_t(L, index) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_lightuserdata>(L, index, handler); stack::check<basic_lightuserdata>(L, index, handler);
#endif // Safety #endif // Safety
} }
basic_lightuserdata(lua_State* L, ref_index index) basic_lightuserdata(lua_State* L, ref_index index)
: base_t(L, index) { : base_t(L, index) {
#ifdef SOL_SAFE_REFERENCES #if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this); auto pp = stack::push_pop(*this);
constructor_handler handler{}; constructor_handler handler{};
stack::check<basic_lightuserdata>(lua_state(), index, handler); stack::check<basic_lightuserdata>(lua_state(), index, handler);

View File

@ -151,7 +151,7 @@ namespace sol {
template <typename T, typename Regs> template <typename T, typename Regs>
inline void make_length_op_const(std::true_type, Regs& l, int& index) { inline void make_length_op_const(std::true_type, Regs& l, int& index) {
const char* name = to_string(meta_function::length).c_str(); const char* name = to_string(meta_function::length).c_str();
#ifdef __clang__ #if defined(__clang__)
l[index] = luaL_Reg{ name, &c_call<decltype(&T::size), &T::size> }; l[index] = luaL_Reg{ name, &c_call<decltype(&T::size), &T::size> };
#else #else
typedef decltype(std::declval<T>().size()) R; typedef decltype(std::declval<T>().size()) R;
@ -164,7 +164,7 @@ namespace sol {
template <typename T, typename Regs> template <typename T, typename Regs>
inline void make_length_op_const(std::false_type, Regs& l, int& index) { inline void make_length_op_const(std::false_type, Regs& l, int& index) {
const char* name = to_string(meta_function::length).c_str(); const char* name = to_string(meta_function::length).c_str();
#ifdef __clang__ #if defined(__clang__)
l[index] = luaL_Reg{ name, &c_call<decltype(&T::size), &T::size> }; l[index] = luaL_Reg{ name, &c_call<decltype(&T::size), &T::size> };
#else #else
typedef decltype(std::declval<T>().size()) R; typedef decltype(std::declval<T>().size()) R;

View File

@ -216,7 +216,7 @@ namespace sol {
template <typename T, bool is_index> template <typename T, bool is_index>
inline int indexing_fail(lua_State* L) { inline int indexing_fail(lua_State* L) {
if (is_index) { if (is_index) {
#if 0 //def SOL_SAFE_USERTYPE #if 0 //defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
auto maybeaccessor = stack::get<optional<string_view>>(L, is_index ? -1 : -2); auto maybeaccessor = stack::get<optional<string_view>>(L, is_index ? -1 : -2);
string_view accessor = maybeaccessor.value_or(string_detail::string_shim("(unknown)")); string_view accessor = maybeaccessor.value_or(string_detail::string_shim("(unknown)"));
return luaL_error(L, "sol: attempt to index (get) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.data()); return luaL_error(L, "sol: attempt to index (get) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.data());
@ -253,14 +253,14 @@ namespace sol {
return; return;
} }
string_view& accessor_view = maybeaccessor.value(); string_view& accessor_view = maybeaccessor.value();
#ifdef SOL_UNORDERED_MAP_COMPATIBLE_HASH #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
auto preexistingit = functions.find(accessor_view, string_view_hash(), std::equal_to<string_view>()); auto preexistingit = functions.find(accessor_view, string_view_hash(), std::equal_to<string_view>());
#else #else
std::string accessor(accessor_view.data(), accessor_view.size()); std::string accessor(accessor_view.data(), accessor_view.size());
auto preexistingit = functions.find(accessor); auto preexistingit = functions.find(accessor);
#endif #endif
if (preexistingit == functions.cend()) { if (preexistingit == functions.cend()) {
#ifdef SOL_UNORDERED_MAP_COMPATIBLE_HASH #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
std::string accessor(accessor_view.data(), accessor_view.size()); std::string accessor(accessor_view.data(), accessor_view.size());
#endif #endif
functions.emplace_hint(preexistingit, std::move(accessor), object(L, 3)); functions.emplace_hint(preexistingit, std::move(accessor), object(L, 3));
@ -282,14 +282,14 @@ namespace sol {
mapping_t& mapping = umc.mapping; mapping_t& mapping = umc.mapping;
std::vector<object>& runtime = umc.runtime; std::vector<object>& runtime = umc.runtime;
int target = static_cast<int>(runtime.size()); int target = static_cast<int>(runtime.size());
#ifdef SOL_UNORDERED_MAP_COMPATIBLE_HASH #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
auto preexistingit = mapping.find(accessor_view, string_view_hash(), std::equal_to<string_view>()); auto preexistingit = mapping.find(accessor_view, string_view_hash(), std::equal_to<string_view>());
#else #else
std::string accessor(accessor_view.data(), accessor_view.size()); std::string accessor(accessor_view.data(), accessor_view.size());
auto preexistingit = mapping.find(accessor); auto preexistingit = mapping.find(accessor);
#endif #endif
if (preexistingit == mapping.cend()) { if (preexistingit == mapping.cend()) {
#ifdef SOL_UNORDERED_MAP_COMPATIBLE_HASH #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
std::string accessor(accessor_view.data(), accessor_view.size()); std::string accessor(accessor_view.data(), accessor_view.size());
#endif #endif
runtime.emplace_back(L, 3); runtime.emplace_back(L, 3);
@ -486,7 +486,7 @@ namespace sol {
switch (mf) { switch (mf) {
case meta_function::construct: case meta_function::construct:
if (properties[i]) { if (properties[i]) {
#ifndef SOL_NO_EXCEPTIONS #if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems"); throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
#else #else
assert(false && "sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems"); assert(false && "sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
@ -495,7 +495,7 @@ namespace sol {
break; break;
case meta_function::garbage_collect: case meta_function::garbage_collect:
if (destructfunc != nullptr) { if (destructfunc != nullptr) {
#ifndef SOL_NO_EXCEPTIONS #if !(defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS)
throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems"); throw error("sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
#else #else
assert(false && "sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems"); assert(false && "sol: 2 separate constructor (new) functions were set on this type. Please specify only 1 sol::meta_function::construct/'new' type AND wrap the function in a sol::factories/initializers call, as shown by the documentation and examples, otherwise you may create problems");
@ -576,7 +576,7 @@ namespace sol {
int runtime_target = 0; int runtime_target = 0;
usertype_detail::member_search member = nullptr; usertype_detail::member_search member = nullptr;
{ {
#ifdef SOL_UNORDERED_MAP_COMPATIBLE_HASH #if defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) && SOL_UNORDERED_MAP_COMPATIBLE_HASH
string_view name = stack::get<string_view>(L, keyidx); string_view name = stack::get<string_view>(L, keyidx);
auto memberit = f.mapping.find(name, string_view_hash(), std::equal_to<string_view>()); auto memberit = f.mapping.find(name, string_view_hash(), std::equal_to<string_view>());
#else #else

View File

@ -225,7 +225,8 @@ namespace sol {
struct wrapper<R (O::*)(Args..., ...) const volatile&&> : public member_function_wrapper<R (O::*)(Args..., ...) const volatile&, R, O, Args...> { struct wrapper<R (O::*)(Args..., ...) const volatile&&> : public member_function_wrapper<R (O::*)(Args..., ...) const volatile&, R, O, Args...> {
}; };
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE //noexcept has become a part of a function's type #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
//noexcept has become a part of a function's type
template <typename R, typename O, typename... Args> template <typename R, typename O, typename... Args>
struct wrapper<R (O::*)(Args...) noexcept> : public member_function_wrapper<R (O::*)(Args...) noexcept, R, O, Args...> { struct wrapper<R (O::*)(Args...) noexcept> : public member_function_wrapper<R (O::*)(Args...) noexcept, R, O, Args...> {