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."
# command line parser
parser = argparse.ArgumentParser(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 = argparse.ArgumentParser(
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')
args = parser.parse_args()
@ -25,7 +33,7 @@ single_file = args.output[0]
if len(args.output) > 1:
forward_single_file = args.output[1]
else:
a,b = os.path.splitext(single_file)
a, b = os.path.splitext(single_file)
forward_single_file = a + '_forward' + b
script_path = os.path.normpath(os.path.dirname(os.path.realpath(__file__)))
working_dir = os.getcwd()
@ -67,33 +75,49 @@ module_path = os.path.join(script_path)
includes = set([])
standard_include = re.compile(r'#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')
define_cpp = re.compile(r'#define SOL_.*?_HPP')
endif_cpp = re.compile(r'#endif // SOL_.*?_HPP')
def get_include(line, base_path):
local_match = local_include.match(line)
if local_match:
# 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 None
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():
return os.popen('git rev-parse --short HEAD').read().strip()
def get_version():
return os.popen('git describe --tags --abbrev=0').read().strip()
def process_file(filename, out):
global includes
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:
return
@ -153,17 +177,24 @@ include_guard = 'SOL_SINGLE_INCLUDE_HPP'
forward_include_guard = 'SOL_SINGLE_INCLUDE_FORWARD_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 = ''
forward_result = ''
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')
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:
process_file(processed_file, ss)
@ -179,7 +210,12 @@ if not args.quiet:
includes = set([])
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:
process_file(forward_processed_file, forward_ss)

14
sol.hpp
View File

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

View File

@ -200,7 +200,7 @@ namespace meta {
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>
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&&;
};
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE
#if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
template <typename R, typename... 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>
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) {
@ -371,7 +371,7 @@ namespace sol {
template <typename Fx>
static int call(lua_State* L, Fx&& f) {
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);
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)");
@ -401,7 +401,7 @@ namespace sol {
template <typename V>
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;
#ifdef SOL_SAFE_USERTYPE
#if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
auto maybeo = stack::check_get<Ta*>(L, 1);
if (!maybeo || maybeo.value() == nullptr) {
if (is_variable) {
@ -461,7 +461,7 @@ namespace sol {
template <typename V>
static int call(lua_State* L, V&& f) {
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);
if (!maybeo || maybeo.value() == nullptr) {
if (is_variable) {
@ -642,7 +642,7 @@ namespace sol {
typedef meta::pop_front_type_t<typename traits_type::free_args_list> args_list;
typedef T Ta;
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);
if (!maybeo || maybeo.value() == nullptr) {
if (is_variable) {

View File

@ -32,15 +32,17 @@
#include "feature_test.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
#define COMPAT53_LUA_CPP 1
#endif // Build Lua Compat layer as C++
#endif
#endif
#include "compatibility//compat-5.3.h"
#ifndef COMPAT53_INCLUDE_SOURCE
#define COMPAT53_INCLUDE_SOURCE 1
#endif // Build Compat Layer Inline
#include "compatibility/compat-5.3.h"
#endif // SOL_NO_COMPAT

View File

@ -7,8 +7,8 @@
#include "compat-5.3.h"
/* don't compile it again if it already is included via compat53.h */
#ifndef COMPAT53_C_
#define COMPAT53_C_
#ifndef KEPLER_PROJECT_COMPAT53_C_
#define KEPLER_PROJECT_COMPAT53_C_
@ -50,7 +50,7 @@
#endif /* Lua File Buffer Size */
static char* compat53_strerror (int en, char* buff, size_t sz) {
static char* compat53_strerror(int en, char* buff, size_t sz) {
#if COMPAT53_HAVE_STRERROR_R
/* use strerror_r here, because it's available on these specific platforms */
if (sz > 0) {
@ -85,14 +85,14 @@ static char* compat53_strerror (int en, char* buff, size_t sz) {
}
COMPAT53_API int lua_absindex (lua_State *L, int i) {
COMPAT53_API int lua_absindex(lua_State *L, int i) {
if (i < 0 && i > LUA_REGISTRYINDEX)
i += lua_gettop(L) + 1;
return i;
}
static void compat53_call_lua (lua_State *L, char const code[], size_t len,
static void compat53_call_lua(lua_State *L, char const code[], size_t len,
int nargs, int nret) {
lua_rawgetp(L, LUA_REGISTRYINDEX, (void*)code);
if (lua_type(L, -1) != LUA_TFUNCTION) {
@ -102,23 +102,23 @@ static void compat53_call_lua (lua_State *L, char const code[], size_t len,
lua_pushvalue(L, -1);
lua_rawsetp(L, LUA_REGISTRYINDEX, (void*)code);
}
lua_insert(L, -nargs-1);
lua_insert(L, -nargs - 1);
lua_call(L, nargs, nret);
}
static const char compat53_arith_code[] =
"local op,a,b=...\n"
"if op==0 then return a+b\n"
"elseif op==1 then return a-b\n"
"elseif op==2 then return a*b\n"
"elseif op==3 then return a/b\n"
"elseif op==4 then return a%b\n"
"elseif op==5 then return a^b\n"
"elseif op==6 then return -a\n"
"end\n";
"local op,a,b=...\n"
"if op==0 then return a+b\n"
"elseif op==1 then return a-b\n"
"elseif op==2 then return a*b\n"
"elseif op==3 then return a/b\n"
"elseif op==4 then return a%b\n"
"elseif op==5 then return a^b\n"
"elseif op==6 then return -a\n"
"end\n";
COMPAT53_API void lua_arith (lua_State *L, int op) {
COMPAT53_API void lua_arith(lua_State *L, int op) {
if (op < LUA_OPADD || op > LUA_OPUNM)
luaL_error(L, "invalid 'op' argument for lua_arith");
luaL_checkstack(L, 5, "not enough stack slots");
@ -127,15 +127,15 @@ COMPAT53_API void lua_arith (lua_State *L, int op) {
lua_pushnumber(L, op);
lua_insert(L, -3);
compat53_call_lua(L, compat53_arith_code,
sizeof(compat53_arith_code)-1, 3, 1);
sizeof(compat53_arith_code) - 1, 3, 1);
}
static const char compat53_compare_code[] =
"local a,b=...\n"
"return a<=b\n";
"local a,b=...\n"
"return a<=b\n";
COMPAT53_API int lua_compare (lua_State *L, int idx1, int idx2, int op) {
COMPAT53_API int lua_compare(lua_State *L, int idx1, int idx2, int op) {
int result = 0;
switch (op) {
case LUA_OPEQ:
@ -149,7 +149,7 @@ COMPAT53_API int lua_compare (lua_State *L, int idx1, int idx2, int op) {
lua_pushvalue(L, idx1);
lua_pushvalue(L, idx2);
compat53_call_lua(L, compat53_compare_code,
sizeof(compat53_compare_code)-1, 2, 1);
sizeof(compat53_compare_code) - 1, 2, 1);
result = lua_toboolean(L, -1);
lua_pop(L, 1);
return result;
@ -160,7 +160,7 @@ COMPAT53_API int lua_compare (lua_State *L, int idx1, int idx2, int op) {
}
COMPAT53_API void lua_copy (lua_State *L, int from, int to) {
COMPAT53_API void lua_copy(lua_State *L, int from, int to) {
int abs_to = lua_absindex(L, to);
luaL_checkstack(L, 1, "not enough stack slots");
lua_pushvalue(L, from);
@ -168,7 +168,7 @@ COMPAT53_API void lua_copy (lua_State *L, int from, int to) {
}
COMPAT53_API void lua_len (lua_State *L, int i) {
COMPAT53_API void lua_len(lua_State *L, int i) {
switch (lua_type(L, i)) {
case LUA_TSTRING:
lua_pushnumber(L, (lua_Number)lua_objlen(L, i));
@ -188,14 +188,14 @@ COMPAT53_API void lua_len (lua_State *L, int i) {
}
COMPAT53_API int lua_rawgetp (lua_State *L, int i, const void *p) {
COMPAT53_API int lua_rawgetp(lua_State *L, int i, const void *p) {
int abs_i = lua_absindex(L, i);
lua_pushlightuserdata(L, (void*)p);
lua_rawget(L, abs_i);
return lua_type(L, -1);
}
COMPAT53_API void lua_rawsetp (lua_State *L, int i, const void *p) {
COMPAT53_API void lua_rawsetp(lua_State *L, int i, const void *p) {
int abs_i = lua_absindex(L, i);
luaL_checkstack(L, 1, "not enough stack slots");
lua_pushlightuserdata(L, (void*)p);
@ -204,16 +204,7 @@ 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);
if (isnum != NULL) {
*isnum = (n != 0 || lua_isnumber(L, i));
@ -222,13 +213,13 @@ COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum) {
}
COMPAT53_API void luaL_checkversion (lua_State *L) {
COMPAT53_API void luaL_checkversion(lua_State *L) {
(void)L;
}
COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg) {
if (!lua_checkstack(L, sp+LUA_MINSTACK)) {
COMPAT53_API void luaL_checkstack(lua_State *L, int sp, const char *msg) {
if (!lua_checkstack(L, sp + LUA_MINSTACK)) {
if (msg != NULL)
luaL_error(L, "stack overflow (%s)", msg);
else {
@ -239,7 +230,7 @@ COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg) {
}
COMPAT53_API int luaL_getsubtable (lua_State *L, int i, const char *name) {
COMPAT53_API int luaL_getsubtable(lua_State *L, int i, const char *name) {
int abs_i = lua_absindex(L, i);
luaL_checkstack(L, 3, "not enough stack slots");
lua_pushstring(L, name);
@ -255,7 +246,7 @@ COMPAT53_API int luaL_getsubtable (lua_State *L, int i, const char *name) {
}
COMPAT53_API lua_Integer luaL_len (lua_State *L, int i) {
COMPAT53_API lua_Integer luaL_len(lua_State *L, int i) {
lua_Integer res = 0;
int isnum = 0;
luaL_checkstack(L, 1, "not enough stack slots");
@ -268,8 +259,8 @@ COMPAT53_API lua_Integer luaL_len (lua_State *L, int i) {
}
COMPAT53_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
luaL_checkstack(L, nup+1, "too many upvalues");
COMPAT53_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) {
luaL_checkstack(L, nup + 1, "too many upvalues");
for (; l->name != NULL; l++) { /* fill the table with given functions */
int i;
lua_pushstring(L, l->name);
@ -282,14 +273,14 @@ COMPAT53_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
}
COMPAT53_API void luaL_setmetatable (lua_State *L, const char *tname) {
COMPAT53_API void luaL_setmetatable(lua_State *L, const char *tname) {
luaL_checkstack(L, 1, "not enough stack slots");
luaL_getmetatable(L, tname);
lua_setmetatable(L, -2);
}
COMPAT53_API void *luaL_testudata (lua_State *L, int i, const char *tname) {
COMPAT53_API void *luaL_testudata(lua_State *L, int i, const char *tname) {
void *p = lua_touserdata(L, i);
luaL_checkstack(L, 2, "not enough stack slots");
if (p == NULL || !lua_getmetatable(L, i))
@ -306,21 +297,21 @@ COMPAT53_API void *luaL_testudata (lua_State *L, int i, const char *tname) {
}
static int compat53_countlevels (lua_State *L) {
static int compat53_countlevels(lua_State *L) {
lua_Debug ar;
int li = 1, le = 1;
/* find an upper bound */
while (lua_getstack(L, le, &ar)) { li = le; le *= 2; }
/* do a binary search */
while (li < le) {
int m = (li + le)/2;
int m = (li + le) / 2;
if (lua_getstack(L, m, &ar)) li = m + 1;
else le = m;
}
return le - 1;
}
static int compat53_findfield (lua_State *L, int objidx, int level) {
static int compat53_findfield(lua_State *L, int objidx, int level) {
if (level == 0 || !lua_istable(L, -1))
return 0; /* not found */
lua_pushnil(L); /* start 'next' loop */
@ -343,7 +334,7 @@ static int compat53_findfield (lua_State *L, int objidx, int level) {
return 0; /* not found */
}
static int compat53_pushglobalfuncname (lua_State *L, lua_Debug *ar) {
static int compat53_pushglobalfuncname(lua_State *L, lua_Debug *ar) {
int top = lua_gettop(L);
lua_getinfo(L, "f", ar); /* push function */
lua_pushvalue(L, LUA_GLOBALSINDEX);
@ -358,7 +349,7 @@ static int compat53_pushglobalfuncname (lua_State *L, lua_Debug *ar) {
}
}
static void compat53_pushfuncname (lua_State *L, lua_Debug *ar) {
static void compat53_pushfuncname(lua_State *L, lua_Debug *ar) {
if (*ar->namewhat != '\0') /* is there a name? */
lua_pushfstring(L, "function " LUA_QS, ar->name);
else if (*ar->what == 'm') /* main? */
@ -378,7 +369,7 @@ static void compat53_pushfuncname (lua_State *L, lua_Debug *ar) {
#define COMPAT53_LEVELS1 12 /* size of the first part of the stack */
#define COMPAT53_LEVELS2 10 /* size of the second part of the stack */
COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1,
COMPAT53_API void luaL_traceback(lua_State *L, lua_State *L1,
const char *msg, int level) {
lua_Debug ar;
int top = lua_gettop(L);
@ -405,7 +396,7 @@ COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1,
}
COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
COMPAT53_API int luaL_fileresult(lua_State *L, int stat, const char *fname) {
const char *serr = NULL;
int en = errno; /* calls to Lua API may change this value */
char buf[512] = { 0 };
@ -426,7 +417,7 @@ COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
}
static int compat53_checkmode (lua_State *L, const char *mode, const char *modename, int err) {
static int compat53_checkmode(lua_State *L, const char *mode, const char *modename, int err) {
if (mode && strchr(mode, modename[0]) == NULL) {
lua_pushfstring(L, "attempt to load a %s chunk (mode is '%s')", modename, mode);
return err;
@ -444,18 +435,19 @@ typedef struct {
} compat53_reader_data;
static const char *compat53_reader (lua_State *L, void *ud, size_t *size) {
static const char *compat53_reader(lua_State *L, void *ud, size_t *size) {
compat53_reader_data *data = (compat53_reader_data *)ud;
if (data->has_peeked_data) {
data->has_peeked_data = 0;
*size = data->peeked_data_size;
return data->peeked_data;
} else
}
else
return data->reader(L, data->ud, size);
}
COMPAT53_API int lua_load (lua_State *L, lua_Reader reader, void *data, const char *source, const char *mode) {
COMPAT53_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char *source, const char *mode) {
int status = LUA_OK;
compat53_reader_data compat53_data = { reader, data, 1, 0, 0 };
compat53_data.peeked_data = reader(L, data, &(compat53_data.peeked_data_size));
@ -480,7 +472,7 @@ typedef struct {
} compat53_LoadF;
static const char *compat53_getF (lua_State *L, void *ud, size_t *size) {
static const char *compat53_getF(lua_State *L, void *ud, size_t *size) {
compat53_LoadF *lf = (compat53_LoadF *)ud;
(void)L; /* not used */
if (lf->n > 0) { /* are there pre-read characters to be read? */
@ -498,8 +490,8 @@ static const char *compat53_getF (lua_State *L, void *ud, size_t *size) {
}
static int compat53_errfile (lua_State *L, const char *what, int fnameindex) {
char buf[512] = {0};
static int compat53_errfile(lua_State *L, const char *what, int fnameindex) {
char buf[512] = { 0 };
const char *serr = compat53_strerror(errno, buf, sizeof(buf));
const char *filename = lua_tostring(L, fnameindex) + 1;
lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
@ -508,7 +500,7 @@ static int compat53_errfile (lua_State *L, const char *what, int fnameindex) {
}
static int compat53_skipBOM (compat53_LoadF *lf) {
static int compat53_skipBOM(compat53_LoadF *lf) {
const char *p = "\xEF\xBB\xBF"; /* UTF-8 BOM mark */
int c;
lf->n = 0;
@ -529,7 +521,7 @@ static int compat53_skipBOM (compat53_LoadF *lf) {
** first "valid" character of the file (after the optional BOM and
** a first-line comment).
*/
static int compat53_skipcomment (compat53_LoadF *lf, int *cp) {
static int compat53_skipcomment(compat53_LoadF *lf, int *cp) {
int c = *cp = compat53_skipBOM(lf);
if (c == '#') { /* first line is a comment (Unix exec. file)? */
do { /* skip first line */
@ -542,7 +534,7 @@ static int compat53_skipcomment (compat53_LoadF *lf, int *cp) {
}
COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char *mode) {
COMPAT53_API int luaL_loadfilex(lua_State *L, const char *filename, const char *mode) {
compat53_LoadF lf;
int status, readstatus;
int c;
@ -603,7 +595,7 @@ COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char
}
COMPAT53_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode) {
COMPAT53_API int luaL_loadbufferx(lua_State *L, const char *buff, size_t sz, const char *name, const char *mode) {
int status = LUA_OK;
if (sz > 0 && buff[0] == LUA_SIGNATURE[0]) {
status = compat53_checkmode(L, mode, "binary", LUA_ERRSYNTAX);
@ -624,7 +616,7 @@ COMPAT53_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t sz, co
/* some form of unix; check feature macros in unistd.h for details */
# include <unistd.h>
/* check posix version; the relevant include files and macros probably
* were available before 2001, but I'm not sure */
* were available before 2001, but I'm not sure */
# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
# include <sys/wait.h>
# define l_inspectstat(stat,what) \
@ -639,7 +631,7 @@ COMPAT53_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t sz, co
#endif
COMPAT53_API int luaL_execresult (lua_State *L, int stat) {
COMPAT53_API int luaL_execresult(lua_State *L, int stat) {
const char *what = "exit";
if (stat == -1)
return luaL_fileresult(L, 0, NULL);
@ -656,7 +648,7 @@ COMPAT53_API int luaL_execresult (lua_State *L, int stat) {
}
COMPAT53_API void luaL_buffinit (lua_State *L, luaL_Buffer_53 *B) {
COMPAT53_API void luaL_buffinit(lua_State *L, luaL_Buffer_53 *B) {
/* make it crash if used via pointer to a 5.1-style luaL_Buffer */
B->b.p = NULL;
B->b.L = NULL;
@ -669,7 +661,7 @@ COMPAT53_API void luaL_buffinit (lua_State *L, luaL_Buffer_53 *B) {
}
COMPAT53_API char *luaL_prepbuffsize (luaL_Buffer_53 *B, size_t s) {
COMPAT53_API char *luaL_prepbuffsize(luaL_Buffer_53 *B, size_t s) {
if (B->capacity - B->nelems < s) { /* needs to grow */
char* newptr = NULL;
size_t newcap = B->capacity * 2;
@ -684,17 +676,17 @@ COMPAT53_API char *luaL_prepbuffsize (luaL_Buffer_53 *B, size_t s) {
B->ptr = newptr;
B->capacity = newcap;
}
return B->ptr+B->nelems;
return B->ptr + B->nelems;
}
COMPAT53_API void luaL_addlstring (luaL_Buffer_53 *B, const char *s, size_t l) {
COMPAT53_API void luaL_addlstring(luaL_Buffer_53 *B, const char *s, size_t l) {
memcpy(luaL_prepbuffsize(B, l), s, l);
luaL_addsize(B, l);
}
COMPAT53_API void luaL_addvalue (luaL_Buffer_53 *B) {
COMPAT53_API void luaL_addvalue(luaL_Buffer_53 *B) {
size_t len = 0;
const char *s = lua_tolstring(B->L2, -1, &len);
if (!s)
@ -706,7 +698,7 @@ COMPAT53_API void luaL_addvalue (luaL_Buffer_53 *B) {
}
void luaL_pushresult (luaL_Buffer_53 *B) {
void luaL_pushresult(luaL_Buffer_53 *B) {
lua_pushlstring(B->L2, B->ptr, B->nelems);
if (B->ptr != B->b.buffer)
lua_replace(B->L2, -2); /* remove userdata buffer */
@ -721,7 +713,7 @@ void luaL_pushresult (luaL_Buffer_53 *B) {
#if defined( LUA_VERSION_NUM ) && LUA_VERSION_NUM <= 502
COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i) {
COMPAT53_API int lua_geti(lua_State *L, int index, lua_Integer i) {
index = lua_absindex(L, index);
lua_pushinteger(L, i);
lua_gettable(L, index);
@ -729,7 +721,7 @@ COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i) {
}
COMPAT53_API int lua_isinteger (lua_State *L, int index) {
COMPAT53_API int lua_isinteger(lua_State *L, int index) {
if (lua_type(L, index) == LUA_TNUMBER) {
lua_Number n = lua_tonumber(L, index);
lua_Integer i = lua_tointeger(L, index);
@ -740,7 +732,23 @@ COMPAT53_API int lua_isinteger (lua_State *L, int index) {
}
static void compat53_reverse (lua_State *L, int a, int b) {
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) {
for (; a < b; ++a, --b) {
lua_pushvalue(L, a);
lua_pushvalue(L, b);
@ -750,23 +758,23 @@ static void compat53_reverse (lua_State *L, int a, int b) {
}
COMPAT53_API void lua_rotate (lua_State *L, int idx, int n) {
COMPAT53_API void lua_rotate(lua_State *L, int idx, int n) {
int n_elems = 0;
idx = lua_absindex(L, idx);
n_elems = lua_gettop(L)-idx+1;
n_elems = lua_gettop(L) - idx + 1;
if (n < 0)
n += n_elems;
if ( n > 0 && n < n_elems) {
if (n > 0 && n < n_elems) {
luaL_checkstack(L, 2, "not enough stack slots available");
n = n_elems - n;
compat53_reverse(L, idx, idx+n-1);
compat53_reverse(L, idx+n, idx+n_elems-1);
compat53_reverse(L, idx, idx+n_elems-1);
compat53_reverse(L, idx, idx + n - 1);
compat53_reverse(L, idx + n, idx + n_elems - 1);
compat53_reverse(L, idx, idx + n_elems - 1);
}
}
COMPAT53_API void lua_seti (lua_State *L, int index, lua_Integer i) {
COMPAT53_API void lua_seti(lua_State *L, int index, lua_Integer i) {
luaL_checkstack(L, 1, "not enough stack slots available");
index = lua_absindex(L, index);
lua_pushinteger(L, i);
@ -779,7 +787,7 @@ COMPAT53_API void lua_seti (lua_State *L, int index, lua_Integer i) {
# define lua_str2number(s, p) strtod((s), (p))
#endif
COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s) {
COMPAT53_API size_t lua_stringtonumber(lua_State *L, const char *s) {
char* endptr;
lua_Number n = lua_str2number(s, &endptr);
if (endptr != s) {
@ -794,7 +802,7 @@ COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s) {
}
COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
COMPAT53_API const char *luaL_tolstring(lua_State *L, int idx, size_t *len) {
if (!luaL_callmeta(L, idx, "__tostring")) {
int t = lua_type(L, idx), tt = 0;
char const* name = NULL;
@ -820,7 +828,8 @@ COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
lua_replace(L, -2);
break;
}
} else {
}
else {
if (!lua_isstring(L, -1))
luaL_error(L, "'__tostring' must return a string");
}
@ -828,7 +837,7 @@ COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
}
COMPAT53_API void luaL_requiref (lua_State *L, const char *modname,
COMPAT53_API void luaL_requiref(lua_State *L, const char *modname,
lua_CFunction openf, int glb) {
luaL_checkstack(L, 3, "not enough stack slots available");
luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
@ -851,7 +860,7 @@ COMPAT53_API void luaL_requiref (lua_State *L, const char *modname,
#endif /* Lua 5.1 and 5.2 */
#endif /* COMPAT53_C_ */
#endif /* KEPLER_PROJECT_COMPAT53_C_ */
/*********************************************************************

View File

@ -1,5 +1,5 @@
#ifndef COMPAT53_H_
#define COMPAT53_H_
#ifndef KEPLER_PROJECT_COMPAT53_H_
#define KEPLER_PROJECT_COMPAT53_H_
#include <stddef.h>
#include <limits.h>
@ -14,29 +14,28 @@ extern "C" {
}
#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
#if defined(COMPAT53_PREFIX)
/* - 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
#ifndef COMPAT53_API
# if defined(COMPAT53_INCLUDE_SOURCE) && COMPAT53_INCLUDE_SOURCE
# if defined(__GNUC__) || defined(__clang__)
# define COMPAT53_API __attribute__((__unused__)) static
# else
# define COMPAT53_API static
# endif
# define COMPAT53_INCLUDE_SOURCE
# endif /* Clang/GCC */
# else /* COMPAT53_INCLUDE_SOURCE */
/* we are not including source, so everything is extern */
# define COMPAT53_API extern
# endif /* COMPAT53_INCLUDE_SOURCE */
#endif /* COMPAT53_PREFIX */
#define COMPAT53_CONCAT_HELPER(a, b) a##b
#define COMPAT53_CONCAT(a, b) COMPAT53_CONCAT_HELPER(a, b)
@ -46,12 +45,12 @@ extern "C" {
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501
/* XXX not implemented:
* lua_arith (new operators)
* lua_upvalueid
* lua_upvaluejoin
* lua_version
* lua_yieldk
*/
* lua_arith (new operators)
* lua_upvalueid
* lua_upvaluejoin
* lua_version
* lua_yieldk
*/
#ifndef LUA_OK
# define LUA_OK 0
@ -88,15 +87,15 @@ extern "C" {
#endif
/* LuaJIT/Lua 5.1 does not have the updated
* error codes for thread status/function returns (but some patched versions do)
* define it only if it's not found
*/
* error codes for thread status/function returns (but some patched versions do)
* define it only if it's not found
*/
#if !defined(LUA_ERRGCMM)
/* Use + 2 because in some versions of Lua (Lua 5.1)
* LUA_ERRFILE is defined as (LUA_ERRERR+1)
* so we need to avoid it (LuaJIT might have something at this
* integer value too)
*/
* LUA_ERRFILE is defined as (LUA_ERRERR+1)
* so we need to avoid it (LuaJIT might have something at this
* integer value too)
*/
# define LUA_ERRGCMM (LUA_ERRERR + 2)
#endif /* LUA_ERRGCMM define */
@ -112,24 +111,24 @@ typedef struct luaL_Buffer_53 {
#define luaL_Buffer luaL_Buffer_53
/* In PUC-Rio 5.1, userdata is a simple FILE*
* In LuaJIT, it's a struct where the first member is a FILE*
* We can't support the `closef` member
*/
* In LuaJIT, it's a struct where the first member is a FILE*
* We can't support the `closef` member
*/
typedef struct luaL_Stream {
FILE *f;
} luaL_Stream;
#define lua_absindex COMPAT53_CONCAT(COMPAT53_PREFIX, _absindex)
COMPAT53_API int lua_absindex (lua_State *L, int i);
COMPAT53_API int lua_absindex(lua_State *L, int i);
#define lua_arith COMPAT53_CONCAT(COMPAT53_PREFIX, _arith)
COMPAT53_API void lua_arith (lua_State *L, int op);
COMPAT53_API void lua_arith(lua_State *L, int op);
#define lua_compare COMPAT53_CONCAT(COMPAT53_PREFIX, _compare)
COMPAT53_API int lua_compare (lua_State *L, int idx1, int idx2, int op);
COMPAT53_API int lua_compare(lua_State *L, int idx1, int idx2, int op);
#define lua_copy COMPAT53_CONCAT(COMPAT53_PREFIX, _copy)
COMPAT53_API void lua_copy (lua_State *L, int from, int to);
COMPAT53_API void lua_copy(lua_State *L, int from, int to);
#define lua_getuservalue(L, i) \
(lua_getfenv((L), (i)), lua_type((L), -1))
@ -137,7 +136,7 @@ COMPAT53_API void lua_copy (lua_State *L, int from, int to);
(luaL_checktype((L), -1, LUA_TTABLE), lua_setfenv((L), (i)))
#define lua_len COMPAT53_CONCAT(COMPAT53_PREFIX, _len)
COMPAT53_API void lua_len (lua_State *L, int i);
COMPAT53_API void lua_len(lua_State *L, int i);
#define lua_pushstring(L, s) \
(lua_pushstring((L), (s)), lua_tostring((L), -1))
@ -158,57 +157,56 @@ COMPAT53_API void lua_len (lua_State *L, int i);
lua_pushvalue((L), LUA_GLOBALSINDEX)
#define lua_rawgetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawgetp)
COMPAT53_API int lua_rawgetp (lua_State *L, int i, const void *p);
COMPAT53_API int lua_rawgetp(lua_State *L, int i, const void *p);
#define lua_rawsetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawsetp)
COMPAT53_API void lua_rawsetp(lua_State *L, int i, const void *p);
#define lua_rawlen(L, i) lua_objlen((L), (i))
#define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx)
COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum);
#define lua_tointeger(L, i) lua_tointegerx((L), (i), NULL)
#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);
#define luaL_checkversion COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkversion)
COMPAT53_API void luaL_checkversion (lua_State *L);
COMPAT53_API void luaL_checkversion(lua_State *L);
#define lua_load COMPAT53_CONCAT(COMPAT53_PREFIX, _load_53)
COMPAT53_API int lua_load (lua_State *L, lua_Reader reader, void *data, const char* source, const char* mode);
COMPAT53_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char* source, const char* mode);
#define luaL_loadfilex COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadfilex)
COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char *mode);
COMPAT53_API int luaL_loadfilex(lua_State *L, const char *filename, const char *mode);
#define luaL_loadbufferx COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadbufferx)
COMPAT53_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode);
COMPAT53_API int luaL_loadbufferx(lua_State *L, const char *buff, size_t sz, const char *name, const char *mode);
#define luaL_checkstack COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkstack_53)
COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg);
COMPAT53_API void luaL_checkstack(lua_State *L, int sp, const char *msg);
#define luaL_getsubtable COMPAT53_CONCAT(COMPAT53_PREFIX, L_getsubtable)
COMPAT53_API int luaL_getsubtable (lua_State* L, int i, const char *name);
COMPAT53_API int luaL_getsubtable(lua_State* L, int i, const char *name);
#define luaL_len COMPAT53_CONCAT(COMPAT53_PREFIX, L_len)
COMPAT53_API lua_Integer luaL_len (lua_State *L, int i);
COMPAT53_API lua_Integer luaL_len(lua_State *L, int i);
#define luaL_setfuncs COMPAT53_CONCAT(COMPAT53_PREFIX, L_setfuncs)
COMPAT53_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);
COMPAT53_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup);
#define luaL_setmetatable COMPAT53_CONCAT(COMPAT53_PREFIX, L_setmetatable)
COMPAT53_API void luaL_setmetatable (lua_State *L, const char *tname);
COMPAT53_API void luaL_setmetatable(lua_State *L, const char *tname);
#define luaL_testudata COMPAT53_CONCAT(COMPAT53_PREFIX, L_testudata)
COMPAT53_API void *luaL_testudata (lua_State *L, int i, const char *tname);
COMPAT53_API void *luaL_testudata(lua_State *L, int i, const char *tname);
#define luaL_traceback COMPAT53_CONCAT(COMPAT53_PREFIX, L_traceback)
COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level);
COMPAT53_API void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level);
#define luaL_fileresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_fileresult)
COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname);
COMPAT53_API int luaL_fileresult(lua_State *L, int stat, const char *fname);
#define luaL_execresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_execresult)
COMPAT53_API int luaL_execresult (lua_State *L, int stat);
COMPAT53_API int luaL_execresult(lua_State *L, int stat);
#define lua_callk(L, na, nr, ctx, cont) \
((void)(ctx), (void)(cont), lua_call((L), (na), (nr)))
@ -219,19 +217,19 @@ COMPAT53_API int luaL_execresult (lua_State *L, int stat);
((void)(from), lua_resume((L), (nargs)))
#define luaL_buffinit COMPAT53_CONCAT(COMPAT53_PREFIX, _buffinit_53)
COMPAT53_API void luaL_buffinit (lua_State *L, luaL_Buffer_53 *B);
COMPAT53_API void luaL_buffinit(lua_State *L, luaL_Buffer_53 *B);
#define luaL_prepbuffsize COMPAT53_CONCAT(COMPAT53_PREFIX, _prepbufsize_53)
COMPAT53_API char *luaL_prepbuffsize (luaL_Buffer_53 *B, size_t s);
COMPAT53_API char *luaL_prepbuffsize(luaL_Buffer_53 *B, size_t s);
#define luaL_addlstring COMPAT53_CONCAT(COMPAT53_PREFIX, _addlstring_53)
COMPAT53_API void luaL_addlstring (luaL_Buffer_53 *B, const char *s, size_t l);
COMPAT53_API void luaL_addlstring(luaL_Buffer_53 *B, const char *s, size_t l);
#define luaL_addvalue COMPAT53_CONCAT(COMPAT53_PREFIX, _addvalue_53)
COMPAT53_API void luaL_addvalue (luaL_Buffer_53 *B);
COMPAT53_API void luaL_addvalue(luaL_Buffer_53 *B);
#define luaL_pushresult COMPAT53_CONCAT(COMPAT53_PREFIX, _pushresult_53)
COMPAT53_API void luaL_pushresult (luaL_Buffer_53 *B);
COMPAT53_API void luaL_pushresult(luaL_Buffer_53 *B);
#undef luaL_buffinitsize
#define luaL_buffinitsize(L, B, s) \
@ -280,7 +278,7 @@ COMPAT53_API void luaL_pushresult (luaL_Buffer_53 *B);
typedef int lua_KContext;
typedef int (*lua_KFunction)(lua_State *L, int status, lua_KContext ctx);
typedef int(*lua_KFunction)(lua_State *L, int status, lua_KContext ctx);
#define lua_dump(L, w, d, s) \
((void)(s), lua_dump((L), (w), (d)))
@ -292,10 +290,13 @@ typedef int (*lua_KFunction)(lua_State *L, int status, lua_KContext ctx);
(lua_gettable((L), (i)), lua_type((L), -1))
#define lua_geti COMPAT53_CONCAT(COMPAT53_PREFIX, _geti)
COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i);
COMPAT53_API int lua_geti(lua_State *L, int index, lua_Integer i);
#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) \
((*(p) = (lua_Integer)(n)), 1)
@ -307,16 +308,16 @@ COMPAT53_API int lua_isinteger (lua_State *L, int index);
(lua_rawgeti((L), (i), (n)), lua_type((L), -1))
#define lua_rotate COMPAT53_CONCAT(COMPAT53_PREFIX, _rotate)
COMPAT53_API void lua_rotate (lua_State *L, int idx, int n);
COMPAT53_API void lua_rotate(lua_State *L, int idx, int n);
#define lua_seti COMPAT53_CONCAT(COMPAT53_PREFIX, _seti)
COMPAT53_API void lua_seti (lua_State *L, int index, lua_Integer i);
COMPAT53_API void lua_seti(lua_State *L, int index, lua_Integer i);
#define lua_stringtonumber COMPAT53_CONCAT(COMPAT53_PREFIX, _stringtonumber)
COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s);
COMPAT53_API size_t lua_stringtonumber(lua_State *L, const char *s);
#define luaL_tolstring COMPAT53_CONCAT(COMPAT53_PREFIX, L_tolstring)
COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len);
COMPAT53_API const char *luaL_tolstring(lua_State *L, int idx, size_t *len);
#define luaL_getmetafield(L, o, e) \
(luaL_getmetafield((L), (o), (e)) ? lua_type((L), -1) : LUA_TNIL)
@ -325,8 +326,8 @@ COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len);
(luaL_newmetatable((L), (tn)) ? (lua_pushstring((L), (tn)), lua_setfield((L), -2, "__name"), 1) : 0)
#define luaL_requiref COMPAT53_CONCAT(COMPAT53_PREFIX, L_requiref_53)
COMPAT53_API void luaL_requiref (lua_State *L, const char *modname,
lua_CFunction openf, int glb );
COMPAT53_API void luaL_requiref(lua_State *L, const char *modname,
lua_CFunction openf, int glb);
#endif /* Lua 5.1 and Lua 5.2 */
@ -336,11 +337,11 @@ COMPAT53_API void luaL_requiref (lua_State *L, const char *modname,
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 502
/* XXX not implemented:
* lua_isyieldable
* lua_getextraspace
* lua_arith (new operators)
* lua_pushfstring (new formats)
*/
* lua_isyieldable
* lua_getextraspace
* lua_arith (new operators)
* lua_pushfstring (new formats)
*/
#define lua_getglobal(L, n) \
(lua_getglobal((L), (n)), lua_type((L), -1))
@ -404,17 +405,17 @@ COMPAT53_API void luaL_requiref (lua_State *L, const char *modname,
/* helper macro for defining continuation functions (for every version
* *except* Lua 5.2) */
* *except* Lua 5.2) */
#ifndef LUA_KFUNCTION
#define LUA_KFUNCTION(_name) \
static int (_name)(lua_State *L, int status, lua_KContext ctx)
#endif
#if defined(COMPAT53_INCLUDE_SOURCE)
#if defined(COMPAT53_INCLUDE_SOURCE) && COMPAT53_INCLUDE_SOURCE == 1
# include "compat-5.3.c"
#endif
#endif /* COMPAT53_H_ */
#endif /* KEPLER_PROJECT_COMPAT53_H_ */

View File

@ -26,15 +26,15 @@
#include "../feature_test.hpp"
#if defined(SOL_USING_CXX_LUA)
#if defined(SOL_USING_CXX_LUA) && SOL_USING_CXX_LUA
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#ifdef SOL_USING_CXX_LUAJIT
#if defined(SOL_USING_CXX_LUAJIT) && SOL_USING_CXX_LUAJIT
#include <luajit.h>
#endif // C++ LuaJIT ... whatever that means
#if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && !defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE)
#define SOL_EXCEPTIONS_SAFE_PROPAGATION
#if (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !(SOL_EXCEPTIONS_SAFE_PROPAGATION)) && (!defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE) || !(SOL_EXCEPTIONS_ALWAYS_UNSAFE))
#define SOL_EXCEPTIONS_SAFE_PROPAGATION 1
#endif // Exceptions can be propagated safely using C++-compiled Lua
#else
#include <lua.hpp>
@ -51,7 +51,7 @@
#define SOL_LUA_VERSION LUA_VERSION_NUM
#elif defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501
#define SOL_LUA_VERSION LUA_VERSION_NUM
#elif !defined(LUA_VERSION_NUM)
#elif !defined(LUA_VERSION_NUM) || !(LUA_VERSION_NUM)
// Definitely 5.0
#define SOL_LUA_VERSION 500
#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) {
#ifdef SOL_SAFE_USERTYPE
#if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
auto p = stack::check_get<T*>(L, 1);
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());
@ -1313,7 +1313,7 @@ namespace sol {
static auto& get_src(lua_State* L) {
auto p = stack::check_get<T*>(L, 1);
#ifdef SOL_SAFE_USERTYPE
#if defined(SOL_SAFE_USERTYPE) && SOL_SAFE_USERTYPE
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());
}
@ -1438,7 +1438,11 @@ namespace sol {
}
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;
#endif
}
static iterator begin(lua_State*, T& self) {

View File

@ -63,7 +63,7 @@ namespace sol {
auto maybenameview = stack::check_get<string_view>(L, 2);
if (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>());
#else
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>
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())) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
if (!is_function<meta::unqualified_t<T>>::value) {
auto pp = stack::push_pop(*this);
constructor_handler handler{};
@ -142,7 +142,7 @@ namespace sol {
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_coroutine(lua_State* L, T&& r, handler_t 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);
constructor_handler 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)
: base_t(L, index), error_handler(std::move(eh)) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{};
stack::check<basic_coroutine>(L, index, handler);
#endif // Safety
@ -178,7 +178,7 @@ namespace sol {
}
basic_coroutine(lua_State* L, raw_index index, handler_t 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{};
stack::check<basic_coroutine>(L, index, handler);
#endif // Safety
@ -188,7 +188,7 @@ namespace sol {
}
basic_coroutine(lua_State* L, ref_index index, handler_t 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);
constructor_handler 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)
: 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{};
stack::check<env_t>(this->lua_state(), -1, handler);
#endif // Safety
@ -71,7 +71,7 @@ namespace sol {
template <bool b>
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)) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{};
stack::check<env_t>(this->lua_state(), -1, handler);
#endif // Safety
@ -79,14 +79,14 @@ namespace sol {
}
basic_environment(lua_State* L, int index = -1)
: base_t(detail::no_safety, L, index) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{};
stack::check<basic_environment>(L, index, handler);
#endif // Safety
}
basic_environment(lua_State* L, ref_index 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);
constructor_handler 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>
basic_environment(T&& r) noexcept
: 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) {
auto pp = stack::push_pop(*this);
constructor_handler handler{};
@ -110,7 +110,7 @@ namespace sol {
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_environment(lua_State* L, T&& r) noexcept
: 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) {
auto pp = stack::push_pop(*this);
constructor_handler handler{};

View File

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

View File

@ -30,7 +30,7 @@
#endif // C++17 features macro
#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??
// on /std:c++latest under x86 conditions (VS 15.5.2),
// compiler errors are tossed for noexcept markings being on function types
@ -51,138 +51,6 @@
#endif // Clang screws up variant
#endif // C++17 only
#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 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
#include <sol/config.hpp>
#endif // SOL_FEATURE_TEST_HPP

View File

@ -81,7 +81,7 @@ namespace sol {
using main_protected_function = main_safe_function;
using stack_protected_function = stack_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 main_function = main_protected_function;
using stack_function = stack_protected_function;
@ -96,7 +96,7 @@ namespace sol {
struct unsafe_function_result;
struct 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;
#else
using function_result = unsafe_function_result;

View File

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

View File

@ -199,7 +199,7 @@ namespace sol {
stack::push(L, f);
}
#ifdef SOL_NOEXCEPT_FUNCTION_TYPE
#if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE
template <bool is_yielding>
static void select_function(std::true_type, lua_State* L, detail::lua_CFunction_noexcept f) {
// TODO: support yielding
@ -299,7 +299,7 @@ namespace sol {
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>>>
#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>>>
#endif // noexcept function types

View File

@ -120,7 +120,7 @@ namespace sol {
inline int c_call(lua_State* L) {
typedef meta::unqualified_t<F> Fu;
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
#endif
> is_raw;

View File

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

View File

@ -48,7 +48,7 @@ namespace sol {
template <typename T>
decltype(auto) tagged_get(types<T>) const {
#ifdef SOL_SAFE_PROXIES
#if defined(SOL_SAFE_PROXIES) && SOL_SAFE_PROXIES != 0
if (!valid()) {
type_panic_c_str(L, index, type_of(L, index), type::none);
}
@ -64,7 +64,7 @@ namespace sol {
}
error tagged_get(types<error>) const {
#ifdef SOL_SAFE_PROXIES
#if defined(SOL_SAFE_PROXIES) && SOL_SAFE_PROXIES != 0
if (valid()) {
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 "in_place.hpp"
#if defined(SOL_USE_BOOST)
#if defined(SOL_USE_BOOST) && SOL_USE_BOOST
#include <boost/optional.hpp>
#else
#include "optional_implementation.hpp"
@ -34,7 +34,7 @@
namespace sol {
#if defined(SOL_USE_BOOST)
#if defined(SOL_USE_BOOST) && SOL_USE_BOOST
template <typename T>
using optional = boost::optional<T>;
using nullopt_t = boost::none_t;

View File

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

View File

@ -77,7 +77,7 @@ namespace sol {
int firstreturn = 1;
int returncount = 0;
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) {
h.stackindex = 0;
if (b) {
@ -90,7 +90,7 @@ namespace sol {
}
};
(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 {
#endif // Safe Exception Propagation
#endif // No Exceptions
@ -99,7 +99,7 @@ namespace sol {
poststacksize = lua_gettop(lua_state()) - static_cast<int>(h.valid());
returncount = poststacksize - (firstreturn - 1);
#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
catch (const char* error) {
@ -117,7 +117,7 @@ namespace sol {
firstreturn = lua_gettop(lua_state());
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
// but LuaJIT will swallow all C++ errors
// 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>
basic_protected_function(T&& r) noexcept
: 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) {
auto pp = stack::push_pop(*this);
constructor_handler handler{};
@ -200,7 +200,7 @@ namespace sol {
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)
: 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);
constructor_handler 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)
: base_t(L, index), error_handler(std::move(eh)) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{};
stack::check<basic_protected_function>(L, index, handler);
#endif // Safety
@ -226,7 +226,7 @@ namespace sol {
}
basic_protected_function(lua_State* L, absolute_index index, handler_t 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{};
stack::check<basic_protected_function>(L, index, handler);
#endif // Safety
@ -236,7 +236,7 @@ namespace sol {
}
basic_protected_function(lua_State* L, raw_index index, handler_t 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{};
stack::check<basic_protected_function>(L, index, handler);
#endif // Safety
@ -246,7 +246,7 @@ namespace sol {
}
basic_protected_function(lua_State* L, ref_index index, handler_t 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);
constructor_handler handler{};
stack::check<basic_protected_function>(lua_state(), -1, handler);

View File

@ -54,7 +54,7 @@ namespace sol {
template <typename T>
decltype(auto) tagged_get(types<T>, int index_offset) const {
int target = index + index_offset;
#ifdef SOL_SAFE_PROXIES
#if defined(SOL_SAFE_PROXIES) && SOL_SAFE_PROXIES
if (!valid()) {
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)");
@ -73,7 +73,7 @@ namespace sol {
error tagged_get(types<error>, int index_offset) const {
int target = index + index_offset;
#ifdef SOL_SAFE_PROXIES
#if defined(SOL_SAFE_PROXIES) && SOL_SAFE_PROXIES
if (valid()) {
type t = type_of(L, target);
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);
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;
auto vit = variables.find(accessorkey, string_view_hash(), std::equal_to<string_view>());
#else
@ -86,7 +86,7 @@ namespace sol {
}
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;
auto fit = functions.find(accessorkey, string_view_hash(), std::equal_to<string_view>());
#else
@ -453,19 +453,19 @@ namespace sol {
switch (mf) {
case meta_function::construct:
if (prop) {
#ifndef 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
#if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
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
}
break;
case meta_function::garbage_collect:
if (prop) {
#ifndef 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
#if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS
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
}
return;

View File

@ -99,7 +99,7 @@ namespace stack {
static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
tracking.use(1);
#if SOL_LUA_VERSION >= 503
#ifdef SOL_STRINGS_ARE_NUMBERS
#if defined(SOL_STRINGS_ARE_NUMBERS) && SOL_STRINGS_ARE_NUMBERS
int isnum = 0;
lua_tointegerx(L, index, &isnum);
const bool success = isnum != 0;
@ -107,20 +107,27 @@ namespace stack {
// expected type, actual type
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
if (lua_isinteger(L, index) == 1) {
return true;
}
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) {
// expected type, actual 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;
#else
#ifndef SOL_STRINGS_ARE_NUMBERS
#if !defined(SOL_STRINGS_ARE_NUMBERS) || !SOL_STRINGS_ARE_NUMBERS
// must pre-check, because it will convert
type t = type_of(L, index);
if (t != type::number) {
@ -131,17 +138,21 @@ namespace stack {
#endif // Do not allow strings to be numbers
int isnum = 0;
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) {
// 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");
#else
handler(L, index, type::number, type_of(L, index), "not a numeric type or numeric string");
#endif
}
return success;
#endif
#endif // Lua Version 5.3 versus others
}
};
@ -150,7 +161,14 @@ namespace stack {
template <typename Handler>
static bool check(lua_State* L, int index, Handler&& handler, record& tracking) {
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);
bool success = t == type::number;
if (!success) {
@ -158,14 +176,7 @@ namespace stack {
handler(L, index, type::number, t, "not a numeric type");
}
return success;
#else
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
#endif // Strings are Numbers
}
};
@ -424,7 +435,7 @@ namespace stack {
template <typename U, typename Handler>
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;
(void)uc;
if (uc.check(L, index, indextype, handler, tracking)) {
@ -577,8 +588,8 @@ namespace stack {
}
};
#ifdef SOL_CXX17_FEATURES
#ifdef SOL_STD_VARIANT
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT
template <typename... Tn, typename C>
struct checker<std::variant<Tn...>, type::poly, C> {
typedef std::variant<Tn...> V;

View File

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

View File

@ -88,7 +88,7 @@ namespace sol {
inline void* align_usertype_pointer(void* ptr) {
typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT
#if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false
#else
(std::alignment_of<void*>::value > 1)
@ -104,7 +104,7 @@ namespace sol {
inline void* align_usertype_unique_destructor(void* ptr) {
typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT
#if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false
#else
(std::alignment_of<unique_destructor>::value > 1)
@ -123,7 +123,7 @@ namespace sol {
template <typename T, bool pre_aligned = false>
inline void* align_usertype_unique(void* ptr) {
typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT
#if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false
#else
(std::alignment_of<T>::value > 1)
@ -144,7 +144,7 @@ namespace sol {
template <typename T>
inline void* align_user(void* ptr) {
typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT
#if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false
#else
(std::alignment_of<T>::value > 1)
@ -161,7 +161,7 @@ namespace sol {
template <typename T>
inline T** usertype_allocate_pointer(lua_State* L) {
typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT
#if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false
#else
(std::alignment_of<T*>::value > 1)
@ -198,7 +198,7 @@ namespace sol {
template <typename T>
inline T* usertype_allocate(lua_State* L) {
typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT
#if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false
#else
(std::alignment_of<T*>::value > 1 || std::alignment_of<T>::value > 1)
@ -278,7 +278,7 @@ namespace sol {
template <typename T, typename Real>
inline Real* usertype_unique_allocate(lua_State* L, T**& pref, unique_destructor*& dx) {
typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT
#if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false
#else
(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>
inline T* user_allocate(lua_State* L) {
typedef std::integral_constant<bool,
#ifdef SOL_NO_MEMORY_ALIGNMENT
#if defined(SOL_NO_MEMORY_ALIGNMENT) && SOL_NO_MEMORY_ALIGNMENT
false
#else
(std::alignment_of<T>::value > 1)
@ -705,7 +705,7 @@ namespace sol {
namespace stack_detail {
#ifdef SOL_SAFE_GETTER
#if defined(SOL_SAFE_GETTER) && SOL_SAFE_GETTER
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)) {
auto op = check_get<T>(L, index, type_panic_c_str, tracking);
@ -782,7 +782,7 @@ namespace sol {
template <typename T>
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);
#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);

View File

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

View File

@ -31,7 +31,7 @@
namespace sol {
namespace detail {
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");
#else
// Lol, what do you want, an error printout? :3c

View File

@ -47,7 +47,7 @@ namespace stack {
template <typename T>
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

View File

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

View File

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

View File

@ -27,16 +27,16 @@
#include "feature_test.hpp"
#include <cstddef>
#include <string>
#ifdef SOL_CXX17_FEATURES
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <string_view>
#endif // C++17 features
#include <functional>
#ifdef SOL_USE_BOOST
#if defined(SOL_USE_BOOST) && SOL_USE_BOOST
#include <boost/functional/hash.hpp>
#endif
namespace sol {
#ifdef SOL_CXX17_FEATURES
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
template <typename C, typename T = std::char_traits<C>>
using basic_string_view = std::basic_string_view<C, T>;
typedef std::string_view string_view;
@ -139,7 +139,7 @@ namespace sol {
}
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());
#else
// 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>
basic_table_core(lua_State* L, 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);
constructor_handler 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(detail::no_safety, L, index) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{};
stack::check<basic_table_core>(L, index, handler);
#endif // Safety
}
basic_table_core(lua_State* L, ref_index 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);
constructor_handler 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>
basic_table_core(T&& r) noexcept
: 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) {
auto pp = stack::push_pop(*this);
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>
basic_thread(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);
constructor_handler 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>
basic_thread(lua_State* L, 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);
constructor_handler handler{};
stack::check<basic_thread>(lua_state(), -1, handler);
@ -113,14 +113,14 @@ namespace sol {
}
basic_thread(lua_State* L, int index = -1)
: base_t(L, index) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{};
stack::check<basic_thread>(L, index, handler);
#endif // Safety
}
basic_thread(lua_State* L, ref_index index)
: base_t(L, index) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this);
constructor_handler handler{};
stack::check<basic_thread>(lua_state(), -1, handler);
@ -134,7 +134,7 @@ namespace sol {
}
basic_thread(lua_State* L, lua_thread_state actualthread)
: base_t(L, -stack::push(L, actualthread)) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{};
stack::check<basic_thread>(lua_state(), -1, handler);
#endif // Safety

View File

@ -560,7 +560,7 @@ namespace sol {
template <typename T>
using is_string_like = any<
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>,
#else
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>>,
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>>
#ifdef SOL_CXX17_FEATURES
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
, std::is_same<unqualified_t<T>, std::string_view>
#endif
>;

View File

@ -37,7 +37,7 @@
#include <array>
#include <initializer_list>
#include <string>
#ifdef SOL_CXX17_FEATURES
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
#include <string_view>
#ifdef SOL_STD_VARIANT
#include <variant>
@ -982,7 +982,7 @@ namespace sol {
template <>
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
template <typename... Tn>
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>
basic_function(T&& r) noexcept
: 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) {
auto pp = stack::push_pop(*this);
constructor_handler handler{};
@ -95,7 +95,7 @@ namespace sol {
template <typename T, meta::enable<is_lua_reference<meta::unqualified_t<T>>> = meta::enabler>
basic_function(lua_State* L, 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);
constructor_handler handler{};
stack::check<basic_function>(lua_state(), -1, handler);
@ -103,14 +103,14 @@ namespace sol {
}
basic_function(lua_State* L, int index = -1)
: base_t(L, index) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{};
stack::check<basic_function>(L, index, handler);
#endif // Safety
}
basic_function(lua_State* L, ref_index index)
: base_t(L, index) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this);
constructor_handler 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>
basic_userdata(T&& r) noexcept
: 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) {
auto pp = stack::push_pop(*this);
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>
basic_userdata(lua_State* L, 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);
constructor_handler handler{};
stack::check<basic_userdata>(L, -1, handler);
@ -67,14 +67,14 @@ namespace sol {
}
basic_userdata(lua_State* L, int index = -1)
: base_t(detail::no_safety, L, index) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{};
stack::check<basic_userdata>(L, index, handler);
#endif // Safety
}
basic_userdata(lua_State* L, ref_index 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);
constructor_handler 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>
basic_lightuserdata(T&& r) noexcept
: 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) {
auto pp = stack::push_pop(*this);
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>
basic_lightuserdata(lua_State* L, 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);
constructor_handler handler{};
stack::check<basic_lightuserdata>(lua_state(), -1, handler);
@ -121,14 +121,14 @@ namespace sol {
}
basic_lightuserdata(lua_State* L, int index = -1)
: base_t(L, index) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
constructor_handler handler{};
stack::check<basic_lightuserdata>(L, index, handler);
#endif // Safety
}
basic_lightuserdata(lua_State* L, ref_index index)
: base_t(L, index) {
#ifdef SOL_SAFE_REFERENCES
#if defined(SOL_SAFE_REFERENCES) && SOL_SAFE_REFERENCES
auto pp = stack::push_pop(*this);
constructor_handler handler{};
stack::check<basic_lightuserdata>(lua_state(), index, handler);

View File

@ -151,7 +151,7 @@ namespace sol {
template <typename T, typename Regs>
inline void make_length_op_const(std::true_type, Regs& l, int& index) {
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> };
#else
typedef decltype(std::declval<T>().size()) R;
@ -164,7 +164,7 @@ namespace sol {
template <typename T, typename Regs>
inline void make_length_op_const(std::false_type, Regs& l, int& index) {
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> };
#else
typedef decltype(std::declval<T>().size()) R;

View File

@ -216,7 +216,7 @@ namespace sol {
template <typename T, bool is_index>
inline int indexing_fail(lua_State* L) {
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);
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());
@ -253,14 +253,14 @@ namespace sol {
return;
}
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>());
#else
std::string accessor(accessor_view.data(), accessor_view.size());
auto preexistingit = functions.find(accessor);
#endif
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());
#endif
functions.emplace_hint(preexistingit, std::move(accessor), object(L, 3));
@ -282,14 +282,14 @@ namespace sol {
mapping_t& mapping = umc.mapping;
std::vector<object>& runtime = umc.runtime;
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>());
#else
std::string accessor(accessor_view.data(), accessor_view.size());
auto preexistingit = mapping.find(accessor);
#endif
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());
#endif
runtime.emplace_back(L, 3);
@ -486,7 +486,7 @@ namespace sol {
switch (mf) {
case meta_function::construct:
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");
#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");
@ -495,7 +495,7 @@ namespace sol {
break;
case meta_function::garbage_collect:
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");
#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");
@ -576,7 +576,7 @@ namespace sol {
int runtime_target = 0;
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);
auto memberit = f.mapping.find(name, string_view_hash(), std::equal_to<string_view>());
#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...> {
};
#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>
struct wrapper<R (O::*)(Args...) noexcept> : public member_function_wrapper<R (O::*)(Args...) noexcept, R, O, Args...> {