diff options
author | daurnimator <quae@daurnimator.com> | 2020-07-09 22:56:47 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2020-07-09 22:56:47 +1000 |
commit | 1baeacb17e1dccc843a0f25579a22c68d5a8a1e1 (patch) | |
tree | b68489fd969b5762e9ebf34b5b9c6076879a8daa /vendor | |
parent | d826b20c71398e2e77c1cfe4e90086d8a72f3414 (diff) | |
parent | de60088d19ff006b4feceb780e97a15611fe2905 (diff) | |
download | luaossl-1baeacb17e1dccc843a0f25579a22c68d5a8a1e1.tar.gz luaossl-1baeacb17e1dccc843a0f25579a22c68d5a8a1e1.tar.bz2 luaossl-1baeacb17e1dccc843a0f25579a22c68d5a8a1e1.zip |
Merge lua-compat-5.3 v0.9
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/compat53/README.md | 5 | ||||
-rw-r--r-- | vendor/compat53/c-api/compat-5.3.c | 66 | ||||
-rw-r--r-- | vendor/compat53/c-api/compat-5.3.h | 4 | ||||
-rw-r--r-- | vendor/compat53/lbitlib.c | 233 | ||||
-rw-r--r-- | vendor/compat53/lstrlib.c | 8 | ||||
-rw-r--r-- | vendor/compat53/ltablib.c | 2 | ||||
-rw-r--r-- | vendor/compat53/lutf8lib.c | 4 | ||||
-rw-r--r-- | vendor/compat53/rockspecs/bit32-5.3.5-1.rockspec | 28 | ||||
-rw-r--r-- | vendor/compat53/rockspecs/bit32-scm-1.rockspec | 28 | ||||
-rw-r--r-- | vendor/compat53/rockspecs/compat53-0.7-1.rockspec | 32 | ||||
-rw-r--r-- | vendor/compat53/rockspecs/compat53-0.8-1.rockspec | 32 | ||||
-rw-r--r-- | vendor/compat53/rockspecs/compat53-scm-0.rockspec | 4 | ||||
-rwxr-xr-x | vendor/compat53/tests/test-bit32.lua | 9 | ||||
-rwxr-xr-x | vendor/compat53/tests/test.lua | 33 | ||||
-rw-r--r-- | vendor/compat53/tests/testmod.c | 18 |
15 files changed, 487 insertions, 19 deletions
diff --git a/vendor/compat53/README.md b/vendor/compat53/README.md index b986584..0fcd657 100644 --- a/vendor/compat53/README.md +++ b/vendor/compat53/README.md @@ -35,7 +35,7 @@ require("compat53") a meaningful return value, so the usual idiom of storing the return of `require` in a local variable makes no sense. -When run under Lua 5.3, this module does nothing. +When run under Lua 5.3+, this module does nothing. When run under Lua 5.2 or 5.1, it replaces some of your standard functions and adds new ones to bring your environment closer to that @@ -125,6 +125,7 @@ For Lua 5.1 additionally: * `lua_KContext` (see [here][14]) * `lua_KFunction` (see [here][14]) * `lua_dump` (extra `strip` parameter, ignored, see [here][15]) +* `lua_getextraspace` (limited compatibilitiy, see [here][24]) * `lua_getfield` (return value) * `lua_geti` and `lua_seti` * `lua_getglobal` (return value) @@ -186,7 +187,6 @@ For Lua 5.1 additionally: [`lua-compat-5.2`][2] for a detailed list. * the following C API functions/macros: * `lua_isyieldable` - * `lua_getextraspace` * `lua_arith` (new operators missing) * `lua_push(v)fstring` (new formats missing) * `lua_upvalueid` (5.1) @@ -236,4 +236,5 @@ This package contains code written by: [21]: https://github.com/keplerproject/lua-compat-5.3/wiki/luaL_checkversion [22]: https://github.com/keplerproject/lua-compat-5.3/wiki/luaL_Buffer [23]: https://github.com/keplerproject/lua-compat-5.3/wiki/coroutine.running + [24]: https://github.com/keplerproject/lua-compat-5.3/wiki/lua_getextraspace diff --git a/vendor/compat53/c-api/compat-5.3.c b/vendor/compat53/c-api/compat-5.3.c index bf81673..42b0a4b 100644 --- a/vendor/compat53/c-api/compat-5.3.c +++ b/vendor/compat53/c-api/compat-5.3.c @@ -28,8 +28,9 @@ #endif /* VC++ _fsopen for share-allowed file read */ #ifndef COMPAT53_HAVE_STRERROR_R -# if defined(__GLIBC__) || defined(_POSIX_VERSION) || defined(__APPLE__) || \ - (!defined (__MINGW32__) && defined(__GNUC__) && (__GNUC__ < 6)) +# if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \ + (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600) || \ + defined(__APPLE__) # define COMPAT53_HAVE_STRERROR_R 1 # else /* none of the defines matched: define to 0 */ # define COMPAT53_HAVE_STRERROR_R 0 @@ -448,7 +449,9 @@ static const char *compat53_reader (lua_State *L, void *ud, size_t *size) { 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_reader_data compat53_data = { 0, NULL, 1, 0, 0 }; + compat53_data.reader = reader; + compat53_data.ud = data; compat53_data.peeked_data = reader(L, data, &(compat53_data.peeked_data_size)); if (compat53_data.peeked_data && compat53_data.peeked_data_size && compat53_data.peeked_data[0] == LUA_SIGNATURE[0]) /* binary file? */ @@ -720,6 +723,63 @@ COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i) { } +#ifndef LUA_EXTRASPACE +#define LUA_EXTRASPACE (sizeof(void*)) +#endif + +COMPAT53_API void *lua_getextraspace (lua_State *L) { + int is_main = 0; + void *ptr = NULL; + luaL_checkstack(L, 4, "not enough stack slots available"); + lua_pushliteral(L, "__compat53_extraspace"); + lua_pushvalue(L, -1); + lua_rawget(L, LUA_REGISTRYINDEX); + if (!lua_istable(L, -1)) { + lua_pop(L, 1); + lua_createtable(L, 0, 2); + lua_createtable(L, 0, 1); + lua_pushliteral(L, "k"); + lua_setfield(L, -2, "__mode"); + lua_setmetatable(L, -2); + lua_pushvalue(L, -2); + lua_pushvalue(L, -2); + lua_rawset(L, LUA_REGISTRYINDEX); + } + lua_replace(L, -2); + is_main = lua_pushthread(L); + lua_rawget(L, -2); + ptr = lua_touserdata(L, -1); + if (!ptr) { + lua_pop(L, 1); + ptr = lua_newuserdata(L, LUA_EXTRASPACE); + if (is_main) { + memset(ptr, '\0', LUA_EXTRASPACE); + lua_pushthread(L); + lua_pushvalue(L, -2); + lua_rawset(L, -4); + lua_pushboolean(L, 1); + lua_pushvalue(L, -2); + lua_rawset(L, -4); + } else { + void* mptr = NULL; + lua_pushboolean(L, 1); + lua_rawget(L, -3); + mptr = lua_touserdata(L, -1); + if (mptr) + memcpy(ptr, mptr, LUA_EXTRASPACE); + else + memset(ptr, '\0', LUA_EXTRASPACE); + lua_pop(L, 1); + lua_pushthread(L); + lua_pushvalue(L, -2); + lua_rawset(L, -4); + } + } + lua_pop(L, 2); + return ptr; +} + + COMPAT53_API int lua_isinteger (lua_State *L, int index) { if (lua_type(L, index) == LUA_TNUMBER) { lua_Number n = lua_tonumber(L, index); diff --git a/vendor/compat53/c-api/compat-5.3.h b/vendor/compat53/c-api/compat-5.3.h index fb6cc25..b730a4b 100644 --- a/vendor/compat53/c-api/compat-5.3.h +++ b/vendor/compat53/c-api/compat-5.3.h @@ -293,6 +293,9 @@ typedef int (*lua_KFunction)(lua_State *L, int status, lua_KContext ctx); #define lua_geti COMPAT53_CONCAT(COMPAT53_PREFIX, _geti) COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i); +#define lua_getextraspace COMPAT53_CONCAT(COMPAT53_PREFIX, _getextraspace) +COMPAT53_API void *lua_getextraspace (lua_State *L); + #define lua_isinteger COMPAT53_CONCAT(COMPAT53_PREFIX, _isinteger) COMPAT53_API int lua_isinteger (lua_State *L, int index); @@ -339,7 +342,6 @@ COMPAT53_API void luaL_requiref (lua_State *L, const char *modname, /* XXX not implemented: * lua_isyieldable - * lua_getextraspace * lua_arith (new operators) * lua_pushfstring (new formats) */ diff --git a/vendor/compat53/lbitlib.c b/vendor/compat53/lbitlib.c new file mode 100644 index 0000000..4786c0d --- /dev/null +++ b/vendor/compat53/lbitlib.c @@ -0,0 +1,233 @@ +/* +** $Id: lbitlib.c,v 1.30.1.1 2017/04/19 17:20:42 roberto Exp $ +** Standard library for bitwise operations +** See Copyright Notice in lua.h +*/ + +#define lbitlib_c +#define LUA_LIB + +#include "lprefix.h" + + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + +#if defined(LUA_COMPAT_BITLIB) /* { */ + + +#define pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n)) +#define checkunsigned(L,i) ((lua_Unsigned)luaL_checkinteger(L,i)) + + +/* number of bits to consider in a number */ +#if !defined(LUA_NBITS) +#define LUA_NBITS 32 +#endif + + +/* +** a lua_Unsigned with its first LUA_NBITS bits equal to 1. (Shift must +** be made in two parts to avoid problems when LUA_NBITS is equal to the +** number of bits in a lua_Unsigned.) +*/ +#define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1)) + + +/* macro to trim extra bits */ +#define trim(x) ((x) & ALLONES) + + +/* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */ +#define mask(n) (~((ALLONES << 1) << ((n) - 1))) + + + +static lua_Unsigned andaux (lua_State *L) { + int i, n = lua_gettop(L); + lua_Unsigned r = ~(lua_Unsigned)0; + for (i = 1; i <= n; i++) + r &= checkunsigned(L, i); + return trim(r); +} + + +static int b_and (lua_State *L) { + lua_Unsigned r = andaux(L); + pushunsigned(L, r); + return 1; +} + + +static int b_test (lua_State *L) { + lua_Unsigned r = andaux(L); + lua_pushboolean(L, r != 0); + return 1; +} + + +static int b_or (lua_State *L) { + int i, n = lua_gettop(L); + lua_Unsigned r = 0; + for (i = 1; i <= n; i++) + r |= checkunsigned(L, i); + pushunsigned(L, trim(r)); + return 1; +} + + +static int b_xor (lua_State *L) { + int i, n = lua_gettop(L); + lua_Unsigned r = 0; + for (i = 1; i <= n; i++) + r ^= checkunsigned(L, i); + pushunsigned(L, trim(r)); + return 1; +} + + +static int b_not (lua_State *L) { + lua_Unsigned r = ~checkunsigned(L, 1); + pushunsigned(L, trim(r)); + return 1; +} + + +static int b_shift (lua_State *L, lua_Unsigned r, lua_Integer i) { + if (i < 0) { /* shift right? */ + i = -i; + r = trim(r); + if (i >= LUA_NBITS) r = 0; + else r >>= i; + } + else { /* shift left */ + if (i >= LUA_NBITS) r = 0; + else r <<= i; + r = trim(r); + } + pushunsigned(L, r); + return 1; +} + + +static int b_lshift (lua_State *L) { + return b_shift(L, checkunsigned(L, 1), luaL_checkinteger(L, 2)); +} + + +static int b_rshift (lua_State *L) { + return b_shift(L, checkunsigned(L, 1), -luaL_checkinteger(L, 2)); +} + + +static int b_arshift (lua_State *L) { + lua_Unsigned r = checkunsigned(L, 1); + lua_Integer i = luaL_checkinteger(L, 2); + if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1)))) + return b_shift(L, r, -i); + else { /* arithmetic shift for 'negative' number */ + if (i >= LUA_NBITS) r = ALLONES; + else + r = trim((r >> i) | ~(trim(~(lua_Unsigned)0) >> i)); /* add signal bit */ + pushunsigned(L, r); + return 1; + } +} + + +static int b_rot (lua_State *L, lua_Integer d) { + lua_Unsigned r = checkunsigned(L, 1); + int i = d & (LUA_NBITS - 1); /* i = d % NBITS */ + r = trim(r); + if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */ + r = (r << i) | (r >> (LUA_NBITS - i)); + pushunsigned(L, trim(r)); + return 1; +} + + +static int b_lrot (lua_State *L) { + return b_rot(L, luaL_checkinteger(L, 2)); +} + + +static int b_rrot (lua_State *L) { + return b_rot(L, -luaL_checkinteger(L, 2)); +} + + +/* +** get field and width arguments for field-manipulation functions, +** checking whether they are valid. +** ('luaL_error' called without 'return' to avoid later warnings about +** 'width' being used uninitialized.) +*/ +static int fieldargs (lua_State *L, int farg, int *width) { + lua_Integer f = luaL_checkinteger(L, farg); + lua_Integer w = luaL_optinteger(L, farg + 1, 1); + luaL_argcheck(L, 0 <= f, farg, "field cannot be negative"); + luaL_argcheck(L, 0 < w, farg + 1, "width must be positive"); + if (f + w > LUA_NBITS) + luaL_error(L, "trying to access non-existent bits"); + *width = (int)w; + return (int)f; +} + + +static int b_extract (lua_State *L) { + int w; + lua_Unsigned r = trim(checkunsigned(L, 1)); + int f = fieldargs(L, 2, &w); + r = (r >> f) & mask(w); + pushunsigned(L, r); + return 1; +} + + +static int b_replace (lua_State *L) { + int w; + lua_Unsigned r = trim(checkunsigned(L, 1)); + lua_Unsigned v = trim(checkunsigned(L, 2)); + int f = fieldargs(L, 3, &w); + lua_Unsigned m = mask(w); + r = (r & ~(m << f)) | ((v & m) << f); + pushunsigned(L, r); + return 1; +} + + +static const luaL_Reg bitlib[] = { + {"arshift", b_arshift}, + {"band", b_and}, + {"bnot", b_not}, + {"bor", b_or}, + {"bxor", b_xor}, + {"btest", b_test}, + {"extract", b_extract}, + {"lrotate", b_lrot}, + {"lshift", b_lshift}, + {"replace", b_replace}, + {"rrotate", b_rrot}, + {"rshift", b_rshift}, + {NULL, NULL} +}; + + + +LUAMOD_API int luaopen_bit32 (lua_State *L) { + luaL_newlib(L, bitlib); + return 1; +} + + +#else /* }{ */ + + +LUAMOD_API int luaopen_bit32 (lua_State *L) { + return luaL_error(L, "library 'bit32' has been deprecated"); +} + +#endif /* } */ diff --git a/vendor/compat53/lstrlib.c b/vendor/compat53/lstrlib.c index c7aa755..b4bed7e 100644 --- a/vendor/compat53/lstrlib.c +++ b/vendor/compat53/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.254 2016/12/22 13:08:50 roberto Exp $ +** $Id: lstrlib.c,v 1.254.1.1 2017/04/19 17:29:57 roberto Exp $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -879,7 +879,7 @@ static int lua_number2strx (lua_State *L, char *buff, int sz, buff[i] = toupper(uchar(buff[i])); } else if (fmt[SIZELENMOD] != 'a') - luaL_error(L, "modifiers for format '%%a'/'%%A' not implemented"); + return luaL_error(L, "modifiers for format '%%a'/'%%A' not implemented"); return n; } @@ -1199,8 +1199,8 @@ static int getnum (const char **fmt, int df) { static int getnumlimit (Header *h, const char **fmt, int df) { int sz = getnum(fmt, df); if (sz > MAXINTSIZE || sz <= 0) - luaL_error(h->L, "integral size (%d) out of limits [1,%d]", - sz, MAXINTSIZE); + return luaL_error(h->L, "integral size (%d) out of limits [1,%d]", + sz, MAXINTSIZE); return sz; } diff --git a/vendor/compat53/ltablib.c b/vendor/compat53/ltablib.c index 98b2f87..c534957 100644 --- a/vendor/compat53/ltablib.c +++ b/vendor/compat53/ltablib.c @@ -1,5 +1,5 @@ /* -** $Id: ltablib.c,v 1.93 2016/02/25 19:41:54 roberto Exp $ +** $Id: ltablib.c,v 1.93.1.1 2017/04/19 17:20:42 roberto Exp $ ** Library for Table Manipulation ** See Copyright Notice in lua.h */ diff --git a/vendor/compat53/lutf8lib.c b/vendor/compat53/lutf8lib.c index de9e3dc..10bd238 100644 --- a/vendor/compat53/lutf8lib.c +++ b/vendor/compat53/lutf8lib.c @@ -1,5 +1,5 @@ /* -** $Id: lutf8lib.c,v 1.16 2016/12/22 13:08:50 roberto Exp $ +** $Id: lutf8lib.c,v 1.16.1.1 2017/04/19 17:29:57 roberto Exp $ ** Standard library for UTF-8 manipulation ** See Copyright Notice in lua.h */ @@ -171,7 +171,7 @@ static int byteoffset (lua_State *L) { } else { if (iscont(s + posi)) - luaL_error(L, "initial position is a continuation byte"); + return luaL_error(L, "initial position is a continuation byte"); if (n < 0) { while (n < 0 && posi > 0) { /* move back */ do { /* find beginning of previous character */ diff --git a/vendor/compat53/rockspecs/bit32-5.3.5-1.rockspec b/vendor/compat53/rockspecs/bit32-5.3.5-1.rockspec new file mode 100644 index 0000000..e27dedb --- /dev/null +++ b/vendor/compat53/rockspecs/bit32-5.3.5-1.rockspec @@ -0,0 +1,28 @@ +package = "bit32" +version = "5.3.5-1" +source = { + url = "https://github.com/keplerproject/lua-compat-5.3/archive/v0.9.zip", + dir = "lua-compat-5.3-0.9", +} +description = { + summary = "Lua 5.2 bit manipulation library", + detailed = [[ + bit32 is the native Lua 5.2 bit manipulation library, in the version + from Lua 5.3; it is compatible with Lua 5.1, 5.2 and 5.3. + ]], + homepage = "http://www.lua.org/manual/5.2/manual.html#6.7", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.5" +} +build = { + type = "builtin", + modules = { + bit32 = { + sources = { "lbitlib.c" }, + defines = { "LUA_COMPAT_BITLIB" }, + incdirs = { "c-api" }, + } + } +} diff --git a/vendor/compat53/rockspecs/bit32-scm-1.rockspec b/vendor/compat53/rockspecs/bit32-scm-1.rockspec new file mode 100644 index 0000000..cce77de --- /dev/null +++ b/vendor/compat53/rockspecs/bit32-scm-1.rockspec @@ -0,0 +1,28 @@ +package = "bit32" +version = "scm-1" +source = { + url = "https://github.com/keplerproject/lua-compat-5.3/archive/master.zip", + branch = "lua-compat-5.3-master", +} +description = { + summary = "Lua 5.2 bit manipulation library", + detailed = [[ + bit32 is the native Lua 5.2 bit manipulation library, in the version + from Lua 5.3; it is compatible with Lua 5.1, 5.2 and 5.3. + ]], + homepage = "http://www.lua.org/manual/5.2/manual.html#6.7", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.5" +} +build = { + type = "builtin", + modules = { + bit32 = { + sources = { "lbitlib.c" }, + defines = { "LUA_COMPAT_BITLIB" }, + incdirs = { "c-api" }, + } + } +} diff --git a/vendor/compat53/rockspecs/compat53-0.7-1.rockspec b/vendor/compat53/rockspecs/compat53-0.7-1.rockspec new file mode 100644 index 0000000..844a3c6 --- /dev/null +++ b/vendor/compat53/rockspecs/compat53-0.7-1.rockspec @@ -0,0 +1,32 @@ +package = "compat53" +version = "0.7-1" +source = { + url = "https://github.com/keplerproject/lua-compat-5.3/archive/v0.7.zip", + dir = "lua-compat-5.3-0.7", +} +description = { + summary = "Compatibility module providing Lua-5.3-style APIs for Lua 5.2 and 5.1", + detailed = [[ + This is a small module that aims to make it easier to write Lua + code in a Lua-5.3-style that runs on Lua 5.3, 5.2, and 5.1. + It does *not* make Lua 5.2 (or even 5.1) entirely compatible + with Lua 5.3, but it brings the API closer to that of Lua 5.3. + ]], + homepage = "https://github.com/keplerproject/lua-compat-5.3", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.4", + --"struct" -- make Roberto's struct module optional +} +build = { + type = "builtin", + modules = { + ["compat53.init"] = "compat53/init.lua", + ["compat53.module"] = "compat53/module.lua", + ["compat53.utf8"] = "lutf8lib.c", + ["compat53.table"] = "ltablib.c", + ["compat53.string"] = "lstrlib.c", + } +} + diff --git a/vendor/compat53/rockspecs/compat53-0.8-1.rockspec b/vendor/compat53/rockspecs/compat53-0.8-1.rockspec new file mode 100644 index 0000000..0ab17a0 --- /dev/null +++ b/vendor/compat53/rockspecs/compat53-0.8-1.rockspec @@ -0,0 +1,32 @@ +package = "compat53" +version = "0.8-1" +source = { + url = "https://github.com/keplerproject/lua-compat-5.3/archive/v0.8.zip", + dir = "lua-compat-5.3-0.8", +} +description = { + summary = "Compatibility module providing Lua-5.3-style APIs for Lua 5.2 and 5.1", + detailed = [[ + This is a small module that aims to make it easier to write Lua + code in a Lua-5.3-style that runs on Lua 5.1+. + It does *not* make Lua 5.2 (or even 5.1) entirely compatible + with Lua 5.3, but it brings the API closer to that of Lua 5.3. + ]], + homepage = "https://github.com/keplerproject/lua-compat-5.3", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.5", + --"struct" -- make Roberto's struct module optional +} +build = { + type = "builtin", + modules = { + ["compat53.init"] = "compat53/init.lua", + ["compat53.module"] = "compat53/module.lua", + ["compat53.utf8"] = "lutf8lib.c", + ["compat53.table"] = "ltablib.c", + ["compat53.string"] = "lstrlib.c", + } +} + diff --git a/vendor/compat53/rockspecs/compat53-scm-0.rockspec b/vendor/compat53/rockspecs/compat53-scm-0.rockspec index 317e18c..a83dfca 100644 --- a/vendor/compat53/rockspecs/compat53-scm-0.rockspec +++ b/vendor/compat53/rockspecs/compat53-scm-0.rockspec @@ -8,7 +8,7 @@ description = { summary = "Compatibility module providing Lua-5.3-style APIs for Lua 5.2 and 5.1", detailed = [[ This is a small module that aims to make it easier to write Lua - code in a Lua-5.3-style that runs on Lua 5.3, 5.2, and 5.1. + code in a Lua-5.3-style that runs on Lua 5.1+. It does *not* make Lua 5.2 (or even 5.1) entirely compatible with Lua 5.3, but it brings the API closer to that of Lua 5.3. ]], @@ -16,7 +16,7 @@ description = { license = "MIT" } dependencies = { - "lua >= 5.1, < 5.4", + "lua >= 5.1, < 5.5", --"struct" -- make Roberto's struct module optional } build = { diff --git a/vendor/compat53/tests/test-bit32.lua b/vendor/compat53/tests/test-bit32.lua new file mode 100755 index 0000000..cc91e52 --- /dev/null +++ b/vendor/compat53/tests/test-bit32.lua @@ -0,0 +1,9 @@ +#!/usr/bin/env lua + +local bit32 = require("bit32") + + +assert(bit32.bnot(0) == 2^32-1) +assert(bit32.band(1, 3, 5) == 1) +assert(bit32.bor(1, 3, 5) == 7) + diff --git a/vendor/compat53/tests/test.lua b/vendor/compat53/tests/test.lua index c2c0abf..0640cae 100755 --- a/vendor/compat53/tests/test.lua +++ b/vendor/compat53/tests/test.lua @@ -664,14 +664,12 @@ print("isinteger", mod.isinteger(12.3)) print("isinteger", mod.isinteger(math.huge)) print("isinteger", mod.isinteger(math.sqrt(-1))) - ___'' print("rotate", mod.rotate(1, 1, 2, 3, 4, 5, 6)) print("rotate", mod.rotate(-1, 1, 2, 3, 4, 5, 6)) print("rotate", mod.rotate(4, 1, 2, 3, 4, 5, 6)) print("rotate", mod.rotate(-4, 1, 2, 3, 4, 5, 6)) - ___'' print("strtonum", mod.strtonum("+123")) print("strtonum", mod.strtonum(" 123 ")) @@ -679,7 +677,6 @@ print("strtonum", mod.strtonum("-1.23")) print("strtonum", mod.strtonum(" 123 abc")) print("strtonum", mod.strtonum("jkl")) - ___'' local a, b, c = mod.requiref() print("requiref", type(a), type(b), type(c), @@ -687,6 +684,34 @@ print("requiref", type(a), type(b), type(c), type(requiref1), type(requiref2), type(requiref3)) ___'' +local c = coroutine.wrap(function() + mod.extraspace("uvw") + print("getextraspace", mod.extraspace()) + coroutine.yield() + print("getextraspace", mod.extraspace()) + coroutine.yield() + print("getextraspace", mod.extraspace()) +end) +c() +mod.extraspace("abc") +print("getextraspace", mod.extraspace()) +c() +local d = coroutine.wrap(function() + print("getextraspace", mod.extraspace()) + mod.extraspace("xyz") + print("getextraspace", mod.extraspace()) + coroutine.yield() + print("getextraspace", mod.extraspace()) + coroutine.yield() + print("getextraspace", mod.extraspace()) +end) +d() +print("getextraspace", mod.extraspace()) +mod.extraspace("123") +c() +d() + +___'' local proxy, backend = {}, {} setmetatable(proxy, { __index = backend, __newindex = backend }) print("geti/seti", rawget(proxy, 1), rawget(backend, 1)) @@ -705,7 +730,7 @@ print("tonumber", mod.tonumber("error")) ___'' print("tointeger", mod.tointeger(12)) -print("tointeger", mod.tointeger(-12)) +print("tointeger", mod.tointeger(12)) print("tointeger", mod.tointeger(12.1)) print("tointeger", mod.tointeger(12.9)) print("tointeger", mod.tointeger(-12.1)) diff --git a/vendor/compat53/tests/testmod.c b/vendor/compat53/tests/testmod.c index cd56e76..0d73ed4 100644 --- a/vendor/compat53/tests/testmod.c +++ b/vendor/compat53/tests/testmod.c @@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include <errno.h> #include "compat-5.3.h" @@ -63,6 +64,21 @@ static int test_getseti (lua_State *L) { } +#ifndef LUA_EXTRASPACE +#define LUA_EXTRASPACE (sizeof(void*)) +#endif + +static int test_getextraspace (lua_State *L) { + size_t len = 0; + char const* s = luaL_optlstring(L, 1, NULL, &len); + char* p = (char*)lua_getextraspace(L); + lua_pushstring(L, p); + if (s) + memcpy(p, s, len > LUA_EXTRASPACE-1 ? LUA_EXTRASPACE-1 : len+1); + return 1; +} + + /* additional tests for Lua5.1 */ #define NUP 3 @@ -270,6 +286,7 @@ static int test_buffer (lua_State *L) { static int test_exec (lua_State *L) { const char *cmd = luaL_checkstring(L, 1); + errno = 0; return luaL_execresult(L, system(cmd)); } @@ -307,6 +324,7 @@ static const luaL_Reg funcs[] = { { "strtonum", test_str2num }, { "requiref", test_requiref }, { "getseti", test_getseti }, + { "extraspace", test_getextraspace }, { "newproxy", test_newproxy }, { "arith", test_arith }, { "compare", test_compare }, |