mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Updated copyright headers and added compatibility with lua 5.1.5 and luajit!
This means sol can now run on the fastest dynamic language implementation ever! Wooo!~
This commit is contained in:
parent
cd46aac23c
commit
184f16d7fa
3
.gitignore
vendored
3
.gitignore
vendored
@ -34,3 +34,6 @@ luajit-2.0.3/
|
||||
.dropbox*
|
||||
desktop.ini
|
||||
lua-5.3.0/
|
||||
.vs/
|
||||
lua-5.1.5/
|
||||
luajit-2.0.4/
|
||||
|
2
sol.hpp
2
sol.hpp
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
41
sol/compatibility.hpp
Normal file
41
sol/compatibility.hpp
Normal file
@ -0,0 +1,41 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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_COMPATIBILITY_HPP
|
||||
#define SOL_COMPATIBILITY_HPP
|
||||
|
||||
// The various pieces of the compatibility layer
|
||||
// comes from https://github.com/keplerproject/lua-compat-5.2
|
||||
// but has been modified in many places for use with Sol and luajit,
|
||||
// though the core abstractions remain the same
|
||||
#include "compatibility/version.hpp"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "compatibility/5.1.0.h"
|
||||
#include "compatibility/5.0.0.h"
|
||||
#include "compatibility/5.x.x.h"
|
||||
#include "compatibility/5.x.x.inl"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SOL_COMPATIBILITY_HPP
|
44
sol/compatibility/5.0.0.h
Normal file
44
sol/compatibility/5.0.0.h
Normal file
@ -0,0 +1,44 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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_5_0_0_H
|
||||
#define SOL_5_0_0_H
|
||||
|
||||
#include "version.hpp"
|
||||
|
||||
#if SOL_LUA_VERSION < 501
|
||||
/* Lua 5.0 */
|
||||
|
||||
#define LUA_QL(x) "'" x "'"
|
||||
#define LUA_QS LUA_QL("%s")
|
||||
|
||||
#define luaL_Reg luaL_reg
|
||||
|
||||
#define luaL_opt(L, f, n, d) \
|
||||
(lua_isnoneornil(L, n) ? (d) : f(L, n))
|
||||
|
||||
#define luaL_addchar(B,c) \
|
||||
((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \
|
||||
(*(B)->p++ = (char)(c)))
|
||||
|
||||
#endif // Lua 5.0
|
||||
|
||||
#endif // SOL_5_0_0_H
|
130
sol/compatibility/5.1.0.h
Normal file
130
sol/compatibility/5.1.0.h
Normal file
@ -0,0 +1,130 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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_5_1_0_H
|
||||
#define SOL_5_1_0_H
|
||||
|
||||
#include "version.hpp"
|
||||
|
||||
#if SOL_LUA_VERSION == 501
|
||||
/* Lua 5.1 */
|
||||
|
||||
#include <lua.hpp>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* LuaJIT doesn't define these unofficial macros ... */
|
||||
#if !defined(LUAI_INT32)
|
||||
#include <limits.h>
|
||||
#if INT_MAX-20 < 32760
|
||||
#define LUAI_INT32 long
|
||||
#define LUAI_UINT32 unsigned long
|
||||
#elif INT_MAX > 2147483640L
|
||||
#define LUAI_INT32 int
|
||||
#define LUAI_UINT32 unsigned int
|
||||
#else
|
||||
#error "could not detect suitable lua_Unsigned datatype"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define LUA_OPADD 0
|
||||
#define LUA_OPSUB 1
|
||||
#define LUA_OPMUL 2
|
||||
#define LUA_OPDIV 3
|
||||
#define LUA_OPMOD 4
|
||||
#define LUA_OPPOW 5
|
||||
#define LUA_OPUNM 6
|
||||
#define LUA_OPEQ 0
|
||||
#define LUA_OPLT 1
|
||||
#define LUA_OPLE 2
|
||||
|
||||
typedef LUAI_UINT32 lua_Unsigned;
|
||||
|
||||
typedef struct luaL_Buffer_52 {
|
||||
luaL_Buffer b; /* make incorrect code crash! */
|
||||
char *ptr;
|
||||
size_t nelems;
|
||||
size_t capacity;
|
||||
lua_State *L2;
|
||||
} luaL_Buffer_52;
|
||||
#define luaL_Buffer luaL_Buffer_52
|
||||
|
||||
|
||||
#define lua_tounsigned(L, i) lua_tounsignedx(L, i, NULL)
|
||||
|
||||
#define lua_rawlen(L, i) lua_objlen(L, i)
|
||||
|
||||
void lua_arith(lua_State *L, int op);
|
||||
int lua_compare(lua_State *L, int idx1, int idx2, int op);
|
||||
void lua_pushunsigned(lua_State *L, lua_Unsigned n);
|
||||
lua_Unsigned luaL_checkunsigned(lua_State *L, int i);
|
||||
lua_Unsigned lua_tounsignedx(lua_State *L, int i, int *isnum);
|
||||
lua_Unsigned luaL_optunsigned(lua_State *L, int i, lua_Unsigned def);
|
||||
lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum);
|
||||
void lua_len(lua_State *L, int i);
|
||||
int luaL_len(lua_State *L, int i);
|
||||
const char *luaL_tolstring(lua_State *L, int idx, size_t *len);
|
||||
void luaL_requiref(lua_State *L, char const* modname, lua_CFunction openf, int glb);
|
||||
|
||||
#define luaL_buffinit luaL_buffinit_52
|
||||
void luaL_buffinit(lua_State *L, luaL_Buffer_52 *B);
|
||||
|
||||
#define luaL_prepbuffsize luaL_prepbuffsize_52
|
||||
char *luaL_prepbuffsize(luaL_Buffer_52 *B, size_t s);
|
||||
|
||||
#define luaL_addlstring luaL_addlstring_52
|
||||
void luaL_addlstring(luaL_Buffer_52 *B, const char *s, size_t l);
|
||||
|
||||
#define luaL_addvalue luaL_addvalue_52
|
||||
void luaL_addvalue(luaL_Buffer_52 *B);
|
||||
|
||||
#define luaL_pushresult luaL_pushresult_52
|
||||
void luaL_pushresult(luaL_Buffer_52 *B);
|
||||
|
||||
#undef luaL_buffinitsize
|
||||
#define luaL_buffinitsize(L, B, s) \
|
||||
(luaL_buffinit(L, B), luaL_prepbuffsize(B, s))
|
||||
|
||||
#undef luaL_prepbuffer
|
||||
#define luaL_prepbuffer(B) \
|
||||
luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
|
||||
|
||||
#undef luaL_addchar
|
||||
#define luaL_addchar(B, c) \
|
||||
((void)((B)->nelems < (B)->capacity || luaL_prepbuffsize(B, 1)), \
|
||||
((B)->ptr[(B)->nelems++] = (c)))
|
||||
|
||||
#undef luaL_addsize
|
||||
#define luaL_addsize(B, s) \
|
||||
((B)->nelems += (s))
|
||||
|
||||
#undef luaL_addstring
|
||||
#define luaL_addstring(B, s) \
|
||||
luaL_addlstring(B, s, strlen(s))
|
||||
|
||||
#undef luaL_pushresultsize
|
||||
#define luaL_pushresultsize(B, s) \
|
||||
(luaL_addsize(B, s), luaL_pushresult(B))
|
||||
|
||||
#endif /* Lua 5.1 */
|
||||
|
||||
#endif // SOL_5_1_0_H
|
57
sol/compatibility/5.x.x.h
Normal file
57
sol/compatibility/5.x.x.h
Normal file
@ -0,0 +1,57 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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_5_X_X_H
|
||||
#define SOL_5_X_X_H
|
||||
|
||||
#include "version.hpp"
|
||||
|
||||
#if SOL_LUA_VERSION < 520
|
||||
|
||||
#define LUA_RIDX_GLOBALS LUA_GLOBALSINDEX
|
||||
|
||||
#define LUA_OK 0
|
||||
|
||||
#define lua_pushglobaltable(L) \
|
||||
lua_pushvalue(L, LUA_GLOBALSINDEX)
|
||||
|
||||
#define luaL_newlib(L, l) \
|
||||
(lua_newtable((L)),luaL_setfuncs((L), (l), 0))
|
||||
|
||||
void luaL_checkversion(lua_State *L);
|
||||
|
||||
int lua_absindex(lua_State *L, int i);
|
||||
void lua_copy(lua_State *L, int from, int to);
|
||||
void lua_rawgetp(lua_State *L, int i, const void *p);
|
||||
void lua_rawsetp(lua_State *L, int i, const void *p);
|
||||
void *luaL_testudata(lua_State *L, int i, const char *tname);
|
||||
lua_Number lua_tonumberx(lua_State *L, int i, int *isnum);
|
||||
void lua_getuservalue(lua_State *L, int i);
|
||||
void lua_setuservalue(lua_State *L, int i);
|
||||
void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup);
|
||||
void luaL_setmetatable(lua_State *L, const char *tname);
|
||||
int luaL_getsubtable(lua_State *L, int i, const char *name);
|
||||
void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level);
|
||||
int luaL_fileresult(lua_State *L, int stat, const char *fname);
|
||||
|
||||
#endif // Lua 5.1 and below
|
||||
|
||||
#endif // SOL_5_X_X_H
|
678
sol/compatibility/5.x.x.inl
Normal file
678
sol/compatibility/5.x.x.inl
Normal file
@ -0,0 +1,678 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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_5_X_X_INL
|
||||
#define SOL_5_X_X_INL
|
||||
|
||||
#include "version.hpp"
|
||||
#include "5.1.0.h"
|
||||
#include "5.0.0.h"
|
||||
#include "5.x.x.h"
|
||||
|
||||
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM == 501
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PACKAGE_KEY "_sol.package"
|
||||
|
||||
inline int lua_absindex(lua_State *L, int i) {
|
||||
if (i < 0 && i > LUA_REGISTRYINDEX)
|
||||
i += lua_gettop(L) + 1;
|
||||
return i;
|
||||
}
|
||||
|
||||
inline 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);
|
||||
lua_replace(L, abs_to);
|
||||
}
|
||||
|
||||
inline void 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);
|
||||
}
|
||||
|
||||
inline 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);
|
||||
lua_insert(L, -2);
|
||||
lua_rawset(L, abs_i);
|
||||
}
|
||||
|
||||
inline 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))
|
||||
return NULL;
|
||||
else {
|
||||
int res = 0;
|
||||
luaL_getmetatable(L, tname);
|
||||
res = lua_rawequal(L, -1, -2);
|
||||
lua_pop(L, 2);
|
||||
if (!res)
|
||||
p = NULL;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
inline 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));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
inline static void push_package_table(lua_State *L) {
|
||||
lua_pushliteral(L, PACKAGE_KEY);
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
if (!lua_istable(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
/* try to get package table from globals */
|
||||
lua_pushliteral(L, "package");
|
||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
if (lua_istable(L, -1)) {
|
||||
lua_pushliteral(L, PACKAGE_KEY);
|
||||
lua_pushvalue(L, -2);
|
||||
lua_rawset(L, LUA_REGISTRYINDEX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void lua_getuservalue(lua_State *L, int i) {
|
||||
luaL_checktype(L, i, LUA_TUSERDATA);
|
||||
luaL_checkstack(L, 2, "not enough stack slots");
|
||||
lua_getfenv(L, i);
|
||||
lua_pushvalue(L, LUA_GLOBALSINDEX);
|
||||
if (lua_rawequal(L, -1, -2)) {
|
||||
lua_pop(L, 1);
|
||||
lua_pushnil(L);
|
||||
lua_replace(L, -2);
|
||||
}
|
||||
else {
|
||||
lua_pop(L, 1);
|
||||
push_package_table(L);
|
||||
if (lua_rawequal(L, -1, -2)) {
|
||||
lua_pop(L, 1);
|
||||
lua_pushnil(L);
|
||||
lua_replace(L, -2);
|
||||
}
|
||||
else
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
inline void lua_setuservalue(lua_State *L, int i) {
|
||||
luaL_checktype(L, i, LUA_TUSERDATA);
|
||||
if (lua_isnil(L, -1)) {
|
||||
luaL_checkstack(L, 1, "not enough stack slots");
|
||||
lua_pushvalue(L, LUA_GLOBALSINDEX);
|
||||
lua_replace(L, -2);
|
||||
}
|
||||
lua_setfenv(L, i);
|
||||
}
|
||||
|
||||
/*
|
||||
** Adapted from Lua 5.2.0
|
||||
*/
|
||||
inline 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);
|
||||
for (i = 0; i < nup; i++) /* copy upvalues to the top */
|
||||
lua_pushvalue(L, -(nup + 1));
|
||||
lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
|
||||
lua_settable(L, -(nup + 3)); /* table must be below the upvalues, the name and the closure */
|
||||
}
|
||||
lua_pop(L, nup); /* remove upvalues */
|
||||
}
|
||||
|
||||
inline 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);
|
||||
}
|
||||
|
||||
inline 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);
|
||||
lua_gettable(L, abs_i);
|
||||
if (lua_istable(L, -1))
|
||||
return 1;
|
||||
lua_pop(L, 1);
|
||||
lua_newtable(L);
|
||||
lua_pushstring(L, name);
|
||||
lua_pushvalue(L, -2);
|
||||
lua_settable(L, abs_i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef SOL_LUAJIT
|
||||
inline static int 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;
|
||||
if (lua_getstack(L, m, &ar)) li = m + 1;
|
||||
else le = m;
|
||||
}
|
||||
return le - 1;
|
||||
}
|
||||
|
||||
inline static int 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 */
|
||||
while (lua_next(L, -2)) { /* for each pair in table */
|
||||
if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */
|
||||
if (lua_rawequal(L, objidx, -1)) { /* found object? */
|
||||
lua_pop(L, 1); /* remove value (but keep name) */
|
||||
return 1;
|
||||
}
|
||||
else if (findfield(L, objidx, level - 1)) { /* try recursively */
|
||||
lua_remove(L, -2); /* remove table (but keep name) */
|
||||
lua_pushliteral(L, ".");
|
||||
lua_insert(L, -2); /* place '.' between the two names */
|
||||
lua_concat(L, 3);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
lua_pop(L, 1); /* remove value */
|
||||
}
|
||||
return 0; /* not found */
|
||||
}
|
||||
|
||||
inline static int pushglobalfuncname(lua_State *L, lua_Debug *ar) {
|
||||
int top = lua_gettop(L);
|
||||
lua_getinfo(L, "f", ar); /* push function */
|
||||
lua_pushvalue(L, LUA_GLOBALSINDEX);
|
||||
if (findfield(L, top + 1, 2)) {
|
||||
lua_copy(L, -1, top + 1); /* move name to proper place */
|
||||
lua_pop(L, 2); /* remove pushed values */
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
lua_settop(L, top); /* remove function and global table */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline static void 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? */
|
||||
lua_pushliteral(L, "main chunk");
|
||||
else if (*ar->what == 'C') {
|
||||
if (pushglobalfuncname(L, ar)) {
|
||||
lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1));
|
||||
lua_remove(L, -2); /* remove name */
|
||||
}
|
||||
else
|
||||
lua_pushliteral(L, "?");
|
||||
}
|
||||
else
|
||||
lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined);
|
||||
}
|
||||
|
||||
#define LEVELS1 12 /* size of the first part of the stack */
|
||||
#define LEVELS2 10 /* size of the second part of the stack */
|
||||
|
||||
inline void luaL_traceback(lua_State *L, lua_State *L1,
|
||||
const char *msg, int level) {
|
||||
lua_Debug ar;
|
||||
int top = lua_gettop(L);
|
||||
int numlevels = countlevels(L1);
|
||||
int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0;
|
||||
if (msg) lua_pushfstring(L, "%s\n", msg);
|
||||
lua_pushliteral(L, "stack traceback:");
|
||||
while (lua_getstack(L1, level++, &ar)) {
|
||||
if (level == mark) { /* too many levels? */
|
||||
lua_pushliteral(L, "\n\t..."); /* add a '...' */
|
||||
level = numlevels - LEVELS2; /* and skip to last ones */
|
||||
}
|
||||
else {
|
||||
lua_getinfo(L1, "Slnt", &ar);
|
||||
lua_pushfstring(L, "\n\t%s:", ar.short_src);
|
||||
if (ar.currentline > 0)
|
||||
lua_pushfstring(L, "%d:", ar.currentline);
|
||||
lua_pushliteral(L, " in ");
|
||||
pushfuncname(L, &ar);
|
||||
lua_concat(L, lua_gettop(L) - top);
|
||||
}
|
||||
}
|
||||
lua_concat(L, lua_gettop(L) - top);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
inline void luaL_checkversion(lua_State *L) {
|
||||
(void)L;
|
||||
}
|
||||
|
||||
#ifndef SOL_LUAJIT
|
||||
inline int luaL_fileresult(lua_State *L, int stat, const char *fname) {
|
||||
int en = errno; /* calls to Lua API may change this value */
|
||||
if (stat) {
|
||||
lua_pushboolean(L, 1);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
lua_pushnil(L);
|
||||
if (fname)
|
||||
lua_pushfstring(L, "%s: %s", fname, strerror(en));
|
||||
else
|
||||
lua_pushstring(L, strerror(en));
|
||||
lua_pushnumber(L, (lua_Number)en);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
#endif // luajit
|
||||
#endif // Lua 5.0 or Lua 5.1
|
||||
|
||||
|
||||
#if SOL_LUA_VERSION == 501
|
||||
#include <limits.h>
|
||||
|
||||
typedef LUAI_INT32 LUA_INT32;
|
||||
|
||||
/********************************************************************/
|
||||
/* extract of 5.2's luaconf.h */
|
||||
/* detects proper defines for faster unsigned<->number conversion */
|
||||
/* see copyright notice at the end of this file */
|
||||
/********************************************************************/
|
||||
|
||||
#if !defined(LUA_ANSI) && defined(_WIN32) && !defined(_WIN32_WCE)
|
||||
#define LUA_WIN /* enable goodies for regular Windows platforms */
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
|
||||
|
||||
/* Microsoft compiler on a Pentium (32 bit) ? */
|
||||
#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */
|
||||
|
||||
#define LUA_MSASMTRICK
|
||||
#define LUA_IEEEENDIAN 0
|
||||
#define LUA_NANTRICK
|
||||
|
||||
/* pentium 32 bits? */
|
||||
#elif defined(__i386__) || defined(__i386) || defined(__X86__) /* }{ */
|
||||
|
||||
#define LUA_IEEE754TRICK
|
||||
#define LUA_IEEELL
|
||||
#define LUA_IEEEENDIAN 0
|
||||
#define LUA_NANTRICK
|
||||
|
||||
/* pentium 64 bits? */
|
||||
#elif defined(__x86_64) /* }{ */
|
||||
|
||||
#define LUA_IEEE754TRICK
|
||||
#define LUA_IEEEENDIAN 0
|
||||
|
||||
#elif defined(__POWERPC__) || defined(__ppc__) /* }{ */
|
||||
|
||||
#define LUA_IEEE754TRICK
|
||||
#define LUA_IEEEENDIAN 1
|
||||
|
||||
#else /* }{ */
|
||||
|
||||
/* assume IEEE754 and a 32-bit integer type */
|
||||
#define LUA_IEEE754TRICK
|
||||
|
||||
#endif /* } */
|
||||
|
||||
#endif /* } */
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
/* extract of 5.2's llimits.h */
|
||||
/* gives us lua_number2unsigned and lua_unsigned2number */
|
||||
/* see copyright notice just below this one here */
|
||||
/********************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
* This file contains parts of Lua 5.2's source code:
|
||||
*
|
||||
* Copyright (C) 1994-2013 Lua.org, PUC-Rio.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*********************************************************************/
|
||||
|
||||
#if defined(MS_ASMTRICK) || defined(LUA_MSASMTRICK) /* { */
|
||||
/* trick with Microsoft assembler for X86 */
|
||||
|
||||
#define lua_number2unsigned(i,n) \
|
||||
{__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
|
||||
|
||||
|
||||
#elif defined(LUA_IEEE754TRICK) /* }{ */
|
||||
/* the next trick should work on any machine using IEEE754 with
|
||||
a 32-bit int type */
|
||||
|
||||
union compat52_luai_Cast { double l_d; LUA_INT32 l_p[2]; };
|
||||
|
||||
#if !defined(LUA_IEEEENDIAN) /* { */
|
||||
#define LUAI_EXTRAIEEE \
|
||||
static const union compat52_luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
|
||||
#define LUA_IEEEENDIANLOC (ieeeendian.l_p[1] == 33)
|
||||
#else
|
||||
#define LUA_IEEEENDIANLOC LUA_IEEEENDIAN
|
||||
#define LUAI_EXTRAIEEE /* empty */
|
||||
#endif /* } */
|
||||
|
||||
#define lua_number2int32(i,n,t) \
|
||||
{ LUAI_EXTRAIEEE \
|
||||
volatile union compat52_luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
|
||||
(i) = (t)u.l_p[LUA_IEEEENDIANLOC]; }
|
||||
|
||||
#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
|
||||
|
||||
#endif /* } */
|
||||
|
||||
|
||||
/* the following definitions always work, but may be slow */
|
||||
|
||||
#if !defined(lua_number2unsigned) /* { */
|
||||
/* the following definition assures proper modulo behavior */
|
||||
#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_NUMBER_FLOAT)
|
||||
#include <math.h>
|
||||
#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
|
||||
#define lua_number2unsigned(i,n) \
|
||||
((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
|
||||
#else
|
||||
#define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n))
|
||||
#endif
|
||||
#endif /* } */
|
||||
|
||||
|
||||
#if !defined(lua_unsigned2number)
|
||||
/* on several machines, coercion from unsigned to double is slow,
|
||||
so it may be worth to avoid */
|
||||
#define lua_unsigned2number(u) \
|
||||
(((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u))
|
||||
#endif
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
inline static void compat52_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) {
|
||||
lua_pop(L, 1);
|
||||
if (luaL_loadbuffer(L, code, len, "=none"))
|
||||
lua_error(L);
|
||||
lua_pushvalue(L, -1);
|
||||
lua_rawsetp(L, LUA_REGISTRYINDEX, (void*)code);
|
||||
}
|
||||
lua_insert(L, -nargs - 1);
|
||||
lua_call(L, nargs, nret);
|
||||
}
|
||||
|
||||
static const char compat52_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"
|
||||
};
|
||||
|
||||
inline 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");
|
||||
if (op == LUA_OPUNM)
|
||||
lua_pushvalue(L, -1);
|
||||
lua_pushnumber(L, op);
|
||||
lua_insert(L, -3);
|
||||
compat52_call_lua(L, compat52_arith_code,
|
||||
sizeof(compat52_arith_code) - 1, 3, 1);
|
||||
}
|
||||
|
||||
static const char compat52_compare_code[] = {
|
||||
"local a,b=...\n"
|
||||
"return a<=b\n"
|
||||
};
|
||||
|
||||
inline int lua_compare(lua_State *L, int idx1, int idx2, int op) {
|
||||
int result = 0;
|
||||
switch (op) {
|
||||
case LUA_OPEQ:
|
||||
return lua_equal(L, idx1, idx2);
|
||||
case LUA_OPLT:
|
||||
return lua_lessthan(L, idx1, idx2);
|
||||
case LUA_OPLE:
|
||||
luaL_checkstack(L, 5, "not enough stack slots");
|
||||
idx1 = lua_absindex(L, idx1);
|
||||
idx2 = lua_absindex(L, idx2);
|
||||
lua_pushvalue(L, idx1);
|
||||
lua_pushvalue(L, idx2);
|
||||
compat52_call_lua(L, compat52_compare_code,
|
||||
sizeof(compat52_compare_code) - 1, 2, 1);
|
||||
result = lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
return result;
|
||||
default:
|
||||
luaL_error(L, "invalid 'op' argument for lua_compare");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void lua_pushunsigned(lua_State *L, lua_Unsigned n) {
|
||||
lua_pushnumber(L, lua_unsigned2number(n));
|
||||
}
|
||||
|
||||
inline lua_Unsigned luaL_checkunsigned(lua_State *L, int i) {
|
||||
lua_Unsigned result;
|
||||
lua_Number n = lua_tonumber(L, i);
|
||||
if (n == 0 && !lua_isnumber(L, i))
|
||||
luaL_checktype(L, i, LUA_TNUMBER);
|
||||
lua_number2unsigned(result, n);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline lua_Unsigned lua_tounsignedx(lua_State *L, int i, int *isnum) {
|
||||
lua_Unsigned result;
|
||||
lua_Number n = lua_tonumberx(L, i, isnum);
|
||||
lua_number2unsigned(result, n);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline lua_Unsigned luaL_optunsigned(lua_State *L, int i, lua_Unsigned def) {
|
||||
return luaL_opt(L, luaL_checkunsigned, i, def);
|
||||
}
|
||||
|
||||
inline 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;
|
||||
}
|
||||
|
||||
inline void lua_len(lua_State *L, int i) {
|
||||
switch (lua_type(L, i)) {
|
||||
case LUA_TSTRING: /* fall through */
|
||||
case LUA_TTABLE:
|
||||
if (!luaL_callmeta(L, i, "__len"))
|
||||
lua_pushnumber(L, (int)lua_objlen(L, i));
|
||||
break;
|
||||
case LUA_TUSERDATA:
|
||||
if (luaL_callmeta(L, i, "__len"))
|
||||
break;
|
||||
/* maybe fall through */
|
||||
default:
|
||||
luaL_error(L, "attempt to get length of a %s value",
|
||||
lua_typename(L, lua_type(L, i)));
|
||||
}
|
||||
}
|
||||
|
||||
inline int luaL_len(lua_State *L, int i) {
|
||||
int res = 0, isnum = 0;
|
||||
luaL_checkstack(L, 1, "not enough stack slots");
|
||||
lua_len(L, i);
|
||||
res = (int)lua_tointegerx(L, -1, &isnum);
|
||||
lua_pop(L, 1);
|
||||
if (!isnum)
|
||||
luaL_error(L, "object length is not a number");
|
||||
return res;
|
||||
}
|
||||
|
||||
inline const char *luaL_tolstring(lua_State *L, int idx, size_t *len) {
|
||||
if (!luaL_callmeta(L, idx, "__tostring")) {
|
||||
int t = lua_type(L, idx);
|
||||
switch (t) {
|
||||
case LUA_TNIL:
|
||||
lua_pushliteral(L, "nil");
|
||||
break;
|
||||
case LUA_TSTRING:
|
||||
case LUA_TNUMBER:
|
||||
lua_pushvalue(L, idx);
|
||||
break;
|
||||
case LUA_TBOOLEAN:
|
||||
if (lua_toboolean(L, idx))
|
||||
lua_pushliteral(L, "true");
|
||||
else
|
||||
lua_pushliteral(L, "false");
|
||||
break;
|
||||
default:
|
||||
lua_pushfstring(L, "%s: %p", lua_typename(L, t),
|
||||
lua_topointer(L, idx));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return lua_tolstring(L, -1, len);
|
||||
}
|
||||
|
||||
inline void luaL_requiref(lua_State *L, char const* modname,
|
||||
lua_CFunction openf, int glb) {
|
||||
luaL_checkstack(L, 3, "not enough stack slots");
|
||||
lua_pushcfunction(L, openf);
|
||||
lua_pushstring(L, modname);
|
||||
lua_call(L, 1, 1);
|
||||
lua_getglobal(L, "package");
|
||||
if (lua_istable(L, -1) == 0) {
|
||||
lua_pop(L, 1);
|
||||
lua_createtable(L, 0, 16);
|
||||
lua_setglobal(L, "package");
|
||||
lua_getglobal(L, "package");
|
||||
}
|
||||
lua_getfield(L, -1, "loaded");
|
||||
if (lua_istable(L, -1) == 0) {
|
||||
lua_pop(L, 1);
|
||||
lua_createtable(L, 0, 1);
|
||||
lua_setfield(L, -2, "loaded");
|
||||
lua_getfield(L, -1, "loaded");
|
||||
}
|
||||
lua_replace(L, -2);
|
||||
lua_pushvalue(L, -2);
|
||||
lua_setfield(L, -2, modname);
|
||||
lua_pop(L, 1);
|
||||
if (glb) {
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setglobal(L, modname);
|
||||
}
|
||||
}
|
||||
|
||||
inline void luaL_buffinit(lua_State *L, luaL_Buffer_52 *B) {
|
||||
/* make it crash if used via pointer to a 5.1-style luaL_Buffer */
|
||||
B->b.p = NULL;
|
||||
B->b.L = NULL;
|
||||
B->b.lvl = 0;
|
||||
/* reuse the buffer from the 5.1-style luaL_Buffer though! */
|
||||
B->ptr = B->b.buffer;
|
||||
B->capacity = LUAL_BUFFERSIZE;
|
||||
B->nelems = 0;
|
||||
B->L2 = L;
|
||||
}
|
||||
|
||||
inline char *luaL_prepbuffsize(luaL_Buffer_52 *B, size_t s) {
|
||||
if (B->capacity - B->nelems < s) { /* needs to grow */
|
||||
char* newptr = NULL;
|
||||
size_t newcap = B->capacity * 2;
|
||||
if (newcap - B->nelems < s)
|
||||
newcap = B->nelems + s;
|
||||
if (newcap < B->capacity) /* overflow */
|
||||
luaL_error(B->L2, "buffer too large");
|
||||
newptr = (char*)lua_newuserdata(B->L2, newcap);
|
||||
memcpy(newptr, B->ptr, B->nelems);
|
||||
if (B->ptr != B->b.buffer)
|
||||
lua_replace(B->L2, -2); /* remove old buffer */
|
||||
B->ptr = newptr;
|
||||
B->capacity = newcap;
|
||||
}
|
||||
return B->ptr + B->nelems;
|
||||
}
|
||||
|
||||
inline void luaL_addlstring(luaL_Buffer_52 *B, const char *s, size_t l) {
|
||||
memcpy(luaL_prepbuffsize(B, l), s, l);
|
||||
luaL_addsize(B, l);
|
||||
}
|
||||
|
||||
inline void luaL_addvalue(luaL_Buffer_52 *B) {
|
||||
size_t len = 0;
|
||||
const char *s = lua_tolstring(B->L2, -1, &len);
|
||||
if (!s)
|
||||
luaL_error(B->L2, "cannot convert value to string");
|
||||
if (B->ptr != B->b.buffer)
|
||||
lua_insert(B->L2, -2); /* userdata buffer must be at stack top */
|
||||
luaL_addlstring(B, s, len);
|
||||
lua_remove(B->L2, B->ptr != B->b.buffer ? -2 : -1);
|
||||
}
|
||||
|
||||
inline void luaL_pushresult(luaL_Buffer_52 *B) {
|
||||
lua_pushlstring(B->L2, B->ptr, B->nelems);
|
||||
if (B->ptr != B->b.buffer)
|
||||
lua_replace(B->L2, -2); /* remove userdata buffer */
|
||||
}
|
||||
|
||||
#endif /* SOL_LUA_VERSION == 501 */
|
||||
|
||||
#endif // SOL_5_X_X_INL
|
43
sol/compatibility/version.hpp
Normal file
43
sol/compatibility/version.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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_VERSION_HPP
|
||||
#define SOL_VERSION_HPP
|
||||
|
||||
#include <lua.hpp>
|
||||
|
||||
#ifdef LUAJIT_VERSION
|
||||
#define SOL_LUAJIT
|
||||
#endif // luajit
|
||||
|
||||
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502
|
||||
#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)
|
||||
// Definitely 5.0
|
||||
#define SOL_LUA_VERSION 500
|
||||
#else
|
||||
// ??? Not sure, assume 502?
|
||||
#define SOL_LUA_VERSION 502
|
||||
#endif // Lua Version 502, 501 || luajit, 500
|
||||
|
||||
#endif // SOL_VERSION_HPP
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
@ -46,8 +46,9 @@ public:
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, ref);
|
||||
}
|
||||
|
||||
void push() const noexcept {
|
||||
int push() const noexcept {
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
|
||||
return 1;
|
||||
}
|
||||
|
||||
reference(reference&& o) noexcept {
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
@ -58,7 +58,13 @@ public:
|
||||
state():
|
||||
L(luaL_newstate(), lua_close),
|
||||
reg(L.get(), LUA_REGISTRYINDEX),
|
||||
#if SOL_LUA_VERSION < 520
|
||||
// Global table is just a special index
|
||||
global(L.get(), LUA_GLOBALSINDEX) {
|
||||
#else
|
||||
// Global tables are stored in the environment/registry table
|
||||
global(reg.get<table>(LUA_RIDX_GLOBALS)) {
|
||||
#endif // Lua 5.2
|
||||
lua_atpanic(L.get(), detail::atpanic);
|
||||
}
|
||||
|
||||
@ -78,7 +84,10 @@ public:
|
||||
|
||||
for(auto&& library : libraries) {
|
||||
switch(library) {
|
||||
case lib::base:
|
||||
#if SOL_LUA_VERSION <= 501 && defined(SOL_LUAJIT)
|
||||
case lib::coroutine:
|
||||
#endif // luajit opens coroutine base stuff
|
||||
case lib::base:
|
||||
luaL_requiref(L.get(), "base", luaopen_base, 1);
|
||||
lua_pop(L.get(), 1);
|
||||
break;
|
||||
@ -86,10 +95,12 @@ public:
|
||||
luaL_requiref(L.get(), "package", luaopen_package, 1);
|
||||
lua_pop(L.get(), 1);
|
||||
break;
|
||||
#if SOL_LUA_VERSION > 501
|
||||
case lib::coroutine:
|
||||
luaL_requiref(L.get(), "coroutine", luaopen_coroutine, 1);
|
||||
lua_pop(L.get(), 1);
|
||||
break;
|
||||
#endif // Lua 5.2+ only
|
||||
case lib::string:
|
||||
luaL_requiref(L.get(), "string", luaopen_string, 1);
|
||||
lua_pop(L.get(), 1);
|
||||
@ -102,10 +113,12 @@ public:
|
||||
luaL_requiref(L.get(), "math", luaopen_math, 1);
|
||||
lua_pop(L.get(), 1);
|
||||
break;
|
||||
#if SOL_LUA_VERSION > 510
|
||||
case lib::bit32:
|
||||
luaL_requiref(L.get(), "bit32", luaopen_bit32, 1);
|
||||
lua_pop(L.get(), 1);
|
||||
break;
|
||||
#endif // Lua 5.2+ only
|
||||
case lib::io:
|
||||
luaL_requiref(L.get(), "io", luaopen_io, 1);
|
||||
lua_pop(L.get(), 1);
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
@ -120,9 +120,9 @@ struct return_type<T> {
|
||||
template<>
|
||||
struct return_type<> : types<>{
|
||||
typedef void type;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename T, bool isclass = std::is_class<Unqualified<T>>::value>
|
||||
struct is_function_impl : std::is_function<typename std::remove_pointer<T>::type> {};
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
@ -22,9 +22,9 @@
|
||||
#ifndef SOL_TYPES_HPP
|
||||
#define SOL_TYPES_HPP
|
||||
|
||||
#include <lua.hpp>
|
||||
#include <string>
|
||||
#include "compatibility.hpp"
|
||||
#include "traits.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace sol {
|
||||
struct nil_t {};
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2013 Danny Y., Rapptz
|
||||
// Copyright (c) 2013-2015 Danny Y., Rapptz
|
||||
|
||||
// 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
|
||||
|
@ -445,7 +445,7 @@ TEST_CASE("functions/overloaded", "Check if overloaded function resolution templ
|
||||
lua.open_libraries(sol::lib::base);
|
||||
|
||||
lua.set_function("non_overloaded", non_overloaded);
|
||||
REQUIRE_NOTHROW(lua.script("x = non_overloaded(1)\nprint(x)"));
|
||||
REQUIRE_NOTHROW(lua.script("x = non_overloaded(1, 2, 3)\nprint(x)"));
|
||||
|
||||
/*
|
||||
// Cannot reasonably support: clang++ refuses to try enough
|
||||
@ -466,7 +466,7 @@ TEST_CASE("functions/overloaded", "Check if overloaded function resolution templ
|
||||
REQUIRE_NOTHROW(lua.script("print(overloaded(1, 2))"));
|
||||
|
||||
lua.set_function<int(int, int, int)>("overloaded", overloaded);
|
||||
REQUIRE_NOTHROW(lua.script("print(overloaded(1, 2))"));
|
||||
REQUIRE_NOTHROW(lua.script("print(overloaded(1, 2, 3))"));
|
||||
}
|
||||
|
||||
TEST_CASE("functions/return_order_and_multi_get", "Check if return order is in the same reading order specified in Lua") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user