aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/compat53
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2018-05-30 17:48:40 +1000
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2018-05-30 17:48:58 +1000
commit3a2c1dc98b0ba4ca7e4600cd86f11472311954fc (patch)
tree846aad638a8b23d2a11502642657ca61acf68579 /vendor/compat53
parent77d38ec3be5030397f895fd19959a87a065fac14 (diff)
parent18b7d200cbaadf7aee592f739e2e0cb4be4ce298 (diff)
downloadluaossl-3a2c1dc98b0ba4ca7e4600cd86f11472311954fc.tar.gz
luaossl-3a2c1dc98b0ba4ca7e4600cd86f11472311954fc.tar.bz2
luaossl-3a2c1dc98b0ba4ca7e4600cd86f11472311954fc.zip
Merge commit '18b7d200cbaadf7aee592f739e2e0cb4be4ce298'
Update to compat-5.3 v0.6
Diffstat (limited to 'vendor/compat53')
-rw-r--r--vendor/compat53/.travis.yml47
-rw-r--r--vendor/compat53/README.md28
-rw-r--r--vendor/compat53/c-api/compat-5.3.c274
-rw-r--r--vendor/compat53/c-api/compat-5.3.h38
-rwxr-xr-xvendor/compat53/tests/test.lua165
-rw-r--r--vendor/compat53/tests/testmod.c39
6 files changed, 501 insertions, 90 deletions
diff --git a/vendor/compat53/.travis.yml b/vendor/compat53/.travis.yml
new file mode 100644
index 0000000..af458d8
--- /dev/null
+++ b/vendor/compat53/.travis.yml
@@ -0,0 +1,47 @@
+language: c
+compiler: gcc
+
+sudo: false
+
+env:
+ - LUA="lua=5.1"
+ - LUA="lua=5.1" EXTERNAL=true
+ - LUA="lua=5.1" COMPILER="g++"
+ - LUA="lua=5.1" EXTERNAL=true COMPILER="g++"
+ - LUA="luajit=@v2.1 --compat=none"
+ - LUA="luajit=@v2.1 --compat=none" EXTERNAL=true
+ - LUA="luajit=@v2.1 --compat=all"
+ - LUA="luajit=@v2.1 --compat=all" EXTERNAL=true
+ - LUA="lua=5.2"
+ - LUA="lua=5.2" EXTERNAL=true
+ - LUA="lua=5.2" COMPILER="g++"
+ - LUA="lua=5.2" EXTERNAL=true COMPILER="g++"
+
+branches:
+ only:
+ - master
+
+git:
+ depth: 3
+
+notifications:
+ email: false
+
+before_install:
+ - pip install --user hererocks
+ - hererocks old --$LUA
+ - test -e old/bin/lua || (cd old/bin && ln -s luajit* lua)
+ - hererocks new --lua=5.3
+
+install:
+ - export CC="${COMPILER:-gcc}" DEF="" SRC="" CFLAGS="-Wall -Wextra -Ic-api -O2 -fPIC"
+ - if [ "x${EXTERNAL:-}" = xtrue ]; then DEF="-DCOMPAT53_PREFIX=compat53" SRC="c-api/compat-5.3.c"; fi
+ - ${CC} ${CFLAGS} -Iold/include ${DEF} -shared -o old/testmod.so tests/testmod.c ${SRC}
+ - ${CC} ${CFLAGS} -Inew/include ${DEF} -shared -o new/testmod.so tests/testmod.c ${SRC}
+ - gcc ${CFLAGS} -Iold/include ${DEF} -shared -o old/compat53.so ltablib.c lutf8lib.c lstrlib.c ${SRC}
+
+script:
+ - (cd old && bin/lua ../tests/test.lua) > old.txt
+ - (cd new && bin/lua ../tests/test.lua) > new.txt
+ - diff old.txt new.txt || true
+
diff --git a/vendor/compat53/README.md b/vendor/compat53/README.md
index 08614a1..b986584 100644
--- a/vendor/compat53/README.md
+++ b/vendor/compat53/README.md
@@ -1,3 +1,5 @@
+[![Build Status](https://travis-ci.org/keplerproject/lua-compat-5.3.svg?branch=master)](https://travis-ci.org/keplerproject/lua-compat-5.3)
+
# lua-compat-5.3
Lua-5.3-style APIs for Lua 5.2 and 5.1.
@@ -133,6 +135,7 @@ For Lua 5.1 additionally:
* `lua_isinteger`
* `lua_numbertointeger`
* `lua_callk` and `lua_pcallk` (limited compatibility, see [here][14])
+* `lua_resume`
* `lua_rawget` and `lua_rawgeti` (return values)
* `lua_rawgetp` and `lua_rawsetp`
* `luaL_requiref` (now checks `package.loaded` first)
@@ -141,12 +144,16 @@ For Lua 5.1 additionally:
For Lua 5.1 additionally:
* `LUA_OK`
+* `LUA_ERRGCMM`
* `LUA_OP*` macros for `lua_arith` and `lua_compare`
+* `LUA_FILEHANDLE`
* `lua_Unsigned`
+* `luaL_Stream` (limited compatibility, see [here][19])
* `lua_absindex`
-* `lua_arith` (see [here][19])
+* `lua_arith` (see [here][20])
* `lua_compare`
* `lua_len`, `lua_rawlen`, and `luaL_len`
+* `lua_load` (mode argument)
* `lua_pushstring`, `lua_pushlstring` (return value)
* `lua_copy`
* `lua_pushglobaltable`
@@ -157,11 +164,13 @@ For Lua 5.1 additionally:
* `luaL_traceback`
* `luaL_execresult`
* `luaL_fileresult`
+* `luaL_loadbufferx`
+* `luaL_loadfilex`
* `luaL_checkversion` (with empty body, only to avoid compile errors,
- see [here][20])
+ see [here][21])
* `luaL_tolstring`
* `luaL_buffinitsize`, `luaL_prepbuffsize`, and `luaL_pushresultsize`
- (see [here][21])
+ (see [here][22])
* `lua_pushunsigned`, `lua_tounsignedx`, `lua_tounsigned`,
`luaL_checkunsigned`, `luaL_optunsigned`, if
`LUA_COMPAT_APIINTCASTS` is defined.
@@ -184,8 +193,6 @@ For Lua 5.1 additionally:
* `lua_upvaluejoin` (5.1)
* `lua_version` (5.1)
* `lua_yieldk` (5.1)
- * `luaL_loadbufferx` (5.1)
- * `luaL_loadfilex` (5.1)
## See also
@@ -202,6 +209,8 @@ This package contains code written by:
* Tomás Guisasola Gorham ([@tomasguisasola](http://github.com/tomasguisasola))
* Hisham Muhammad ([@hishamhm](http://github.com/hishamhm))
* Renato Maia ([@renatomaia](http://github.com/renatomaia))
+* [@ThePhD](http://github.com/ThePhD)
+* [@Daurnimator](http://github.com/Daurnimator)
[1]: http://www.inf.puc-rio.br/~roberto/struct/
@@ -222,8 +231,9 @@ This package contains code written by:
[16]: https://github.com/keplerproject/lua-compat-5.3/wiki/lua_getuservalue
[17]: https://github.com/keplerproject/lua-compat-5.3/wiki/lua_setuservalue
[18]: https://github.com/keplerproject/lua-compat-5.3/wiki/lua_stringtonumber
- [19]: https://github.com/keplerproject/lua-compat-5.3/wiki/lua_arith
- [20]: https://github.com/keplerproject/lua-compat-5.3/wiki/luaL_checkversion
- [21]: https://github.com/keplerproject/lua-compat-5.3/wiki/luaL_Buffer
- [22]: https://github.com/keplerproject/lua-compat-5.3/wiki/coroutine.running
+ [19]: https://github.com/keplerproject/lua-compat-5.3/wiki/luaL_Stream
+ [20]: https://github.com/keplerproject/lua-compat-5.3/wiki/lua_arith
+ [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
diff --git a/vendor/compat53/c-api/compat-5.3.c b/vendor/compat53/c-api/compat-5.3.c
index 883efb8..b82c654 100644
--- a/vendor/compat53/c-api/compat-5.3.c
+++ b/vendor/compat53/c-api/compat-5.3.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <ctype.h>
#include <errno.h>
+#include <stdio.h>
#include "compat-5.3.h"
/* don't compile it again if it already is included via compat53.h */
@@ -14,6 +15,75 @@
/* definitions for Lua 5.1 only */
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501
+#ifndef COMPAT53_FOPEN_NO_LOCK
+# if defined(_MSC_VER)
+# define COMPAT53_FOPEN_NO_LOCK 1
+# else /* otherwise */
+# define COMPAT53_FOPEN_NO_LOCK 0
+# endif /* VC++ only so far */
+#endif /* No-lock fopen_s usage if possible */
+
+#if defined(_MSC_VER) && COMPAT53_FOPEN_NO_LOCK
+# include <share.h>
+#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))
+# define COMPAT53_HAVE_STRERROR_R 1
+# else /* none of the defines matched: define to 0 */
+# define COMPAT53_HAVE_STRERROR_R 0
+# endif /* have strerror_r of some form */
+#endif /* strerror_r */
+
+#ifndef COMPAT53_HAVE_STRERROR_S
+# if defined(_MSC_VER) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
+ (defined(__STDC_LIB_EXT1__) && __STDC_LIB_EXT1__)
+# define COMPAT53_HAVE_STRERROR_S 1
+# else /* not VC++ or C11 */
+# define COMPAT53_HAVE_STRERROR_S 0
+# endif /* strerror_s from VC++ or C11 */
+#endif /* strerror_s */
+
+#ifndef COMPAT53_LUA_FILE_BUFFER_SIZE
+# define COMPAT53_LUA_FILE_BUFFER_SIZE 4096
+#endif /* Lua File Buffer Size */
+
+
+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) {
+ buff[0] = '\0';
+ /* we don't care whether the GNU version or the XSI version is used: */
+ if (strerror_r(en, buff, sz)) {
+ /* Yes, we really DO want to ignore the return value!
+ * GCC makes that extra hard, not even a (void) cast will do. */
+ }
+ if (buff[0] == '\0') {
+ /* Buffer is unchanged, so we probably have called GNU strerror_r which
+ * returned a static constant string. Chances are that strerror will
+ * return the same static constant string and therefore be thread-safe. */
+ return strerror(en);
+ }
+ }
+ return buff; /* sz is 0 *or* strerror_r wrote into the buffer */
+#elif COMPAT53_HAVE_STRERROR_S
+ /* for MSVC and other C11 implementations, use strerror_s since it's
+ * provided by default by the libraries */
+ strerror_s(buff, sz, en);
+ return buff;
+#else
+ /* fallback, but strerror is not guaranteed to be threadsafe due to modifying
+ * errno itself and some impls not locking a static buffer for it ... but most
+ * known systems have threadsafe errno: this might only change if the locale
+ * is changed out from under someone while this function is being called */
+ (void)buff;
+ (void)sz;
+ return strerror(en);
+#endif
+}
+
COMPAT53_API int lua_absindex (lua_State *L, int i) {
if (i < 0 && i > LUA_REGISTRYINDEX)
@@ -101,16 +171,16 @@ COMPAT53_API void lua_copy (lua_State *L, int from, int to) {
COMPAT53_API void lua_len (lua_State *L, int i) {
switch (lua_type(L, i)) {
case LUA_TSTRING:
- lua_pushnumber(L, (lua_Integer)lua_objlen(L, i));
+ lua_pushnumber(L, (lua_Number)lua_objlen(L, i));
break;
case LUA_TTABLE:
if (!luaL_callmeta(L, i, "__len"))
- lua_pushnumber(L, (lua_Integer)lua_objlen(L, i));
+ lua_pushnumber(L, (lua_Number)lua_objlen(L, i));
break;
case LUA_TUSERDATA:
if (luaL_callmeta(L, i, "__len"))
break;
- /* maybe fall through */
+ /* FALLTHROUGH */
default:
luaL_error(L, "attempt to get length of a %s value",
lua_typename(L, lua_type(L, i)));
@@ -336,23 +406,217 @@ COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1,
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 };
if (stat) {
lua_pushboolean(L, 1);
return 1;
}
else {
lua_pushnil(L);
+ serr = compat53_strerror(en, buf, sizeof(buf));
if (fname)
- lua_pushfstring(L, "%s: %s", fname, strerror(en));
+ lua_pushfstring(L, "%s: %s", fname, serr);
else
- lua_pushstring(L, strerror(en));
+ lua_pushstring(L, serr);
lua_pushnumber(L, (lua_Number)en);
return 3;
}
}
+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;
+ }
+ return LUA_OK;
+}
+
+
+typedef struct {
+ lua_Reader reader;
+ void *ud;
+ int has_peeked_data;
+ const char *peeked_data;
+ size_t peeked_data_size;
+} compat53_reader_data;
+
+
+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
+ 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) {
+ 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));
+ if (compat53_data.peeked_data && compat53_data.peeked_data_size &&
+ compat53_data.peeked_data[0] == LUA_SIGNATURE[0]) /* binary file? */
+ status = compat53_checkmode(L, mode, "binary", LUA_ERRSYNTAX);
+ else
+ status = compat53_checkmode(L, mode, "text", LUA_ERRSYNTAX);
+ if (status != LUA_OK)
+ return status;
+ /* we need to call the original 5.1 version of lua_load! */
+#undef lua_load
+ return lua_load(L, compat53_reader, &compat53_data, source);
+#define lua_load COMPAT53_CONCAT(COMPAT53_PREFIX, _load_53)
+}
+
+
+typedef struct {
+ int n; /* number of pre-read characters */
+ FILE *f; /* file being read */
+ char buff[COMPAT53_LUA_FILE_BUFFER_SIZE]; /* area for reading file */
+} compat53_LoadF;
+
+
+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? */
+ *size = lf->n; /* return them (chars already in buffer) */
+ lf->n = 0; /* no more pre-read characters */
+ }
+ else { /* read a block from file */
+ /* 'fread' can return > 0 *and* set the EOF flag. If next call to
+ 'compat53_getF' called 'fread', it might still wait for user input.
+ The next check avoids this problem. */
+ if (feof(lf->f)) return NULL;
+ *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */
+ }
+ return lf->buff;
+}
+
+
+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);
+ lua_remove(L, fnameindex);
+ return LUA_ERRFILE;
+}
+
+
+static int compat53_skipBOM (compat53_LoadF *lf) {
+ const char *p = "\xEF\xBB\xBF"; /* UTF-8 BOM mark */
+ int c;
+ lf->n = 0;
+ do {
+ c = getc(lf->f);
+ if (c == EOF || c != *(const unsigned char *)p++) return c;
+ lf->buff[lf->n++] = (char)c; /* to be read by the parser */
+ } while (*p != '\0');
+ lf->n = 0; /* prefix matched; discard it */
+ return getc(lf->f); /* return next character */
+}
+
+
+/*
+** reads the first character of file 'f' and skips an optional BOM mark
+** in its beginning plus its first line if it starts with '#'. Returns
+** true if it skipped the first line. In any case, '*cp' has the
+** first "valid" character of the file (after the optional BOM and
+** a first-line comment).
+*/
+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 */
+ c = getc(lf->f);
+ } while (c != EOF && c != '\n');
+ *cp = getc(lf->f); /* skip end-of-line, if present */
+ return 1; /* there was a comment */
+ }
+ else return 0; /* no comment */
+}
+
+
+COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char *mode) {
+ compat53_LoadF lf;
+ int status, readstatus;
+ int c;
+ int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
+ if (filename == NULL) {
+ lua_pushliteral(L, "=stdin");
+ lf.f = stdin;
+ }
+ else {
+ lua_pushfstring(L, "@%s", filename);
+#if defined(_MSC_VER)
+ /* This code is here to stop a deprecation error that stops builds
+ * if a certain macro is defined. While normally not caring would
+ * be best, some header-only libraries and builds can't afford to
+ * dictate this to the user. A quick check shows that fopen_s this
+ * goes back to VS 2005, and _fsopen goes back to VS 2003 .NET,
+ * possibly even before that so we don't need to do any version
+ * number checks, since this has been there since forever. */
+
+ /* TO USER: if you want the behavior of typical fopen_s/fopen,
+ * which does lock the file on VC++, define the macro used below to 0 */
+#if COMPAT53_FOPEN_NO_LOCK
+ lf.f = _fsopen(filename, "r", _SH_DENYNO); /* do not lock the file in any way */
+ if (lf.f == NULL)
+ return compat53_errfile(L, "open", fnameindex);
+#else /* use default locking version */
+ if (fopen_s(&lf.f, filename, "r") != 0)
+ return compat53_errfile(L, "open", fnameindex);
+#endif /* Locking vs. No-locking fopen variants */
+#else
+ lf.f = fopen(filename, "r"); /* default stdlib doesn't forcefully lock files here */
+ if (lf.f == NULL) return compat53_errfile(L, "open", fnameindex);
+#endif
+ }
+ if (compat53_skipcomment(&lf, &c)) /* read initial portion */
+ lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */
+ if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
+#if defined(_MSC_VER)
+ if (freopen_s(&lf.f, filename, "rb", lf.f) != 0)
+ return compat53_errfile(L, "reopen", fnameindex);
+#else
+ lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
+ if (lf.f == NULL) return compat53_errfile(L, "reopen", fnameindex);
+#endif
+ compat53_skipcomment(&lf, &c); /* re-read initial portion */
+ }
+ if (c != EOF)
+ lf.buff[lf.n++] = (char)c; /* 'c' is the first character of the stream */
+ status = lua_load(L, &compat53_getF, &lf, lua_tostring(L, -1), mode);
+ readstatus = ferror(lf.f);
+ if (filename) fclose(lf.f); /* close file (even in case of errors) */
+ if (readstatus) {
+ lua_settop(L, fnameindex); /* ignore results from 'lua_load' */
+ return compat53_errfile(L, "read", fnameindex);
+ }
+ lua_remove(L, fnameindex);
+ return status;
+}
+
+
+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);
+ }
+ else {
+ status = compat53_checkmode(L, mode, "text", LUA_ERRSYNTAX);
+ }
+ if (status != LUA_OK)
+ return status;
+ return luaL_loadbuffer(L, buff, sz, name);
+}
+
+
#if !defined(l_inspectstat) && \
(defined(unix) || defined(__unix) || defined(__unix__) || \
defined(__TOS_AIX__) || defined(_SYSTYPE_BSD) || \
diff --git a/vendor/compat53/c-api/compat-5.3.h b/vendor/compat53/c-api/compat-5.3.h
index bee77a1..755c23e 100644
--- a/vendor/compat53/c-api/compat-5.3.h
+++ b/vendor/compat53/c-api/compat-5.3.h
@@ -9,11 +9,13 @@ extern "C" {
#endif
#include <lua.h>
#include <lauxlib.h>
+#include <lualib.h>
#if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP)
}
#endif
+#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
@@ -21,7 +23,6 @@ extern "C" {
# if !defined(COMPAT53_API)
# define COMPAT53_API extern
# endif
-# undef COMPAT53_INCLUDE_SOURCE
#else /* COMPAT53_PREFIX */
/* - make all functions static and include the source.
* - compat-5.3.c doesn't need to be compiled (and linked) separately
@@ -50,8 +51,6 @@ extern "C" {
* lua_upvaluejoin
* lua_version
* lua_yieldk
- * luaL_loadbufferx
- * luaL_loadfilex
*/
#ifndef LUA_OK
@@ -88,6 +87,19 @@ extern "C" {
# define LUA_OPLE 2
#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
+ */
+#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)
+ */
+# define LUA_ERRGCMM (LUA_ERRERR + 2)
+#endif /* LUA_ERRGCMM define */
+
typedef size_t lua_Unsigned;
typedef struct luaL_Buffer_53 {
@@ -99,6 +111,14 @@ typedef struct luaL_Buffer_53 {
} 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
+ */
+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);
@@ -154,6 +174,15 @@ 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);
+#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);
+
+#define luaL_loadfilex COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadfilex)
+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);
+
#define luaL_checkstack COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkstack_53)
COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg);
@@ -186,6 +215,9 @@ COMPAT53_API int luaL_execresult (lua_State *L, int stat);
#define lua_pcallk(L, na, nr, err, ctx, cont) \
((void)(ctx), (void)(cont), lua_pcall((L), (na), (nr), (err)))
+#define lua_resume(L, from, nargs) \
+ ((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);
diff --git a/vendor/compat53/tests/test.lua b/vendor/compat53/tests/test.lua
index 582f55e..2f6c7f6 100755
--- a/vendor/compat53/tests/test.lua
+++ b/vendor/compat53/tests/test.lua
@@ -40,7 +40,7 @@ local mode = "global"
if arg[1] == "module" then
mode = "module"
end
-
+local self = arg[0]
package.path = "../?.lua;../?/init.lua"
package.cpath = "./?-"..V..".so;./?-"..V..".dll;./?.so;./?.dll"
@@ -603,11 +603,11 @@ end
___''
do
writefile("data.txt", "123 18.8 hello world\ni'm here\n")
- for a,b in io.lines("test.lua", 2, "*l") do
+ for a,b in io.lines(self, 2, "*l") do
print("io.lines()", a, b)
break
end
- for l in io.lines("test.lua") do
+ for l in io.lines(self) do
print("io.lines()", l)
break
end
@@ -624,7 +624,7 @@ do
for l in io.lines("no_such_file.txt") do print(l) end
end))
if mode ~= "module" then
- local f = assert(io.open("test.lua", "r"))
+ local f = assert(io.open(self, "r"))
for a,b in f:lines(2, "*l") do
print("file:lines()", a, b)
break
@@ -657,133 +657,158 @@ ___''
print("testing C API ...")
local mod = require("testmod")
___''
-print(mod.isinteger(1))
-print(mod.isinteger(0))
-print(mod.isinteger(1234567))
-print(mod.isinteger(12.3))
-print(mod.isinteger(math.huge))
-print(mod.isinteger(math.sqrt(-1)))
+print("isinteger", mod.isinteger(1))
+print("isinteger", mod.isinteger(0))
+print("isinteger", mod.isinteger(1234567))
+print("isinteger", mod.isinteger(12.3))
+print("isinteger", mod.isinteger(math.huge))
+print("isinteger", mod.isinteger(math.sqrt(-1)))
___''
-print(mod.rotate(1, 1, 2, 3, 4, 5, 6))
-print(mod.rotate(-1, 1, 2, 3, 4, 5, 6))
-print(mod.rotate(4, 1, 2, 3, 4, 5, 6))
-print(mod.rotate(-4, 1, 2, 3, 4, 5, 6))
+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(mod.strtonum("+123"))
-print(mod.strtonum(" 123 "))
-print(mod.strtonum("-1.23"))
-print(mod.strtonum(" 123 abc"))
-print(mod.strtonum("jkl"))
+print("strtonum", mod.strtonum("+123"))
+print("strtonum", mod.strtonum(" 123 "))
+print("strtonum", mod.strtonum("-1.23"))
+print("strtonum", mod.strtonum(" 123 abc"))
+print("strtonum", mod.strtonum("jkl"))
___''
local a, b, c = mod.requiref()
-print( type(a), type(b), type(c),
- a.boolean, b.boolean, c.boolean,
- type(requiref1), type(requiref2), type(requiref3))
+print("requiref", type(a), type(b), type(c),
+ a.boolean, b.boolean, c.boolean,
+ type(requiref1), type(requiref2), type(requiref3))
___''
local proxy, backend = {}, {}
setmetatable(proxy, { __index = backend, __newindex = backend })
-print(rawget(proxy, 1), rawget(backend, 1))
-print(mod.getseti(proxy, 1))
-print(rawget(proxy, 1), rawget(backend, 1))
-print(mod.getseti(proxy, 1))
-print(rawget(proxy, 1), rawget(backend, 1))
+print("geti/seti", rawget(proxy, 1), rawget(backend, 1))
+print("geti/seti", mod.getseti(proxy, 1))
+print("geti/seti", rawget(proxy, 1), rawget(backend, 1))
+print("geti/seti", mod.getseti(proxy, 1))
+print("geti/seti", rawget(proxy, 1), rawget(backend, 1))
-- tests for Lua 5.1
___''
-print(mod.tonumber(12))
-print(mod.tonumber("12"))
-print(mod.tonumber("0"))
-print(mod.tonumber(false))
-print(mod.tonumber("error"))
+print("tonumber", mod.tonumber(12))
+print("tonumber", mod.tonumber("12"))
+print("tonumber", mod.tonumber("0"))
+print("tonumber", mod.tonumber(false))
+print("tonumber", mod.tonumber("error"))
___''
-print(mod.tointeger(12))
-print(mod.tointeger("12"))
-print(mod.tointeger("0"))
-print( "aaa" )
-print(mod.tointeger(math.pi))
-print( "bbb" )
-print(mod.tointeger(false))
-print(mod.tointeger("error"))
+print("tointeger", mod.tointeger(12))
+print("tointeger", mod.tointeger("12"))
+print("tointeger", mod.tointeger("0"))
+print("tointeger", mod.tointeger(math.pi))
+print("tointeger", mod.tointeger(false))
+print("tointeger", mod.tointeger("error"))
___''
-print(mod.len("123"))
-print(mod.len({ 1, 2, 3}))
-print(pcall(mod.len, true))
+print("len", mod.len("123"))
+print("len", mod.len({ 1, 2, 3}))
+print("len", pcall(mod.len, true))
local ud, meta = mod.newproxy()
meta.__len = function() return 5 end
-print(mod.len(ud))
+print("len", mod.len(ud))
meta.__len = function() return true end
-print(pcall(mod.len, ud))
+print("len", pcall(mod.len, ud))
___''
-print(mod.copy(true, "string", {}, 1))
+print("copy", mod.copy(true, "string", {}, 1))
___''
-print(mod.rawxetp())
-print(mod.rawxetp("I'm back"))
+print("rawgetp/rawsetp", mod.rawxetp())
+print("rawgetp/rawsetp", mod.rawxetp("I'm back"))
___''
-print(F(mod.globals()), mod.globals() == _G)
+print("globals", F(mod.globals()), mod.globals() == _G)
___''
local t = {}
-print(F(mod.subtable(t)))
+print("getsubtable", F(mod.subtable(t)))
local x, msg = mod.subtable(t)
-print(F(x, msg, x == t.xxx))
+print("getsubtable", F(x, msg, x == t.xxx))
___''
-print(F(mod.udata()))
-print(mod.udata("nosuchtype"))
+print("udata", F(mod.udata()))
+print("udata", mod.udata("nosuchtype"))
___''
-print(F(mod.uservalue()))
+print("uservalue", F(mod.uservalue()))
___''
-print(mod.getupvalues())
+print("upvalues", mod.getupvalues())
___''
-print(mod.absindex("hi", true))
+print("absindex", mod.absindex("hi", true))
___''
-print(mod.arith(2, 1))
-print(mod.arith(3, 5))
+print("arith", mod.arith(2, 1))
+print("arith", mod.arith(3, 5))
___''
-print(mod.compare(1, 1))
-print(mod.compare(2, 1))
-print(mod.compare(1, 2))
+print("compare", mod.compare(1, 1))
+print("compare", mod.compare(2, 1))
+print("compare", mod.compare(1, 2))
___''
-print(mod.tolstring("string"))
+print("tolstring", mod.tolstring("string"))
local t = setmetatable({}, {
__tostring = function(v) return "mytable" end
})
-print(mod.tolstring(t))
+print("tolstring", mod.tolstring(t))
local t = setmetatable({}, {
__tostring = function(v) return nil end
})
-print(pcall(mod.tolstring, t))
+print("tolstring", pcall(mod.tolstring, t))
local ud, meta = mod.newproxy()
meta.__name = "XXX"
-print(mod.tolstring(ud):gsub(":.*$", ": yyy"))
+print("tolstring", mod.tolstring(ud):gsub(":.*$", ": yyy"))
+
+___''
+print("pushstring", mod.pushstring())
___''
-print(mod.pushstring())
+print("Buffer", mod.buffer())
___''
-print(mod.buffer())
+print("execresult", mod.exec("exit 0"))
+print("execresult", mod.exec("exit 1"))
+print("execresult", mod.exec("exit 25"))
___''
-print(mod.exec("exit 0"))
-print(mod.exec("exit 1"))
-print(mod.exec("exit 25"))
+do
+ local bin = string.dump(function() end)
+ local modes = { "t", "b", "bt" }
+ local codes = {
+ "", "return true", bin, "invalidsource", "\27invalidbinary"
+ }
+ for _,m in ipairs(modes) do
+ for i,c in ipairs(codes) do
+ print("loadbufferx", m, i, F(mod.loadstring(c, m)))
+ end
+ end
+
+ ___''
+ local bom = "\239\187\191"
+ local shebang = "#!/usr/bin/env lua\n"
+ codes[#codes+1] = bom .. shebang .. "return true"
+ codes[#codes+1] = bom .. shebang .. bin
+ codes[#codes+1] = bom .. shebang .. "invalidsource"
+ codes[#codes+1] = bom .. shebang .. "\027invalidbinary"
+ for _,m in ipairs(modes) do
+ for i,c in ipairs(codes) do
+ print("loadfilex", m, i, F(mod.loadfile(c, m)))
+ end
+ end
+end
___''
diff --git a/vendor/compat53/tests/testmod.c b/vendor/compat53/tests/testmod.c
index 868136b..a0d2e2a 100644
--- a/vendor/compat53/tests/testmod.c
+++ b/vendor/compat53/tests/testmod.c
@@ -1,7 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
-#include <lua.h>
-#include <lauxlib.h>
#include "compat-5.3.h"
@@ -12,7 +10,7 @@ static int test_isinteger (lua_State *L) {
static int test_rotate (lua_State *L) {
- int r = luaL_checkint(L, 1);
+ int r = (int)luaL_checkinteger(L, 1);
int n = lua_gettop(L)-1;
luaL_argcheck(L, (r < 0 ? -r : r) <= n, 1, "not enough arguments");
lua_rotate(L, 2, r);
@@ -274,6 +272,33 @@ static int test_exec (lua_State *L) {
return luaL_execresult(L, system(cmd));
}
+static int test_loadstring (lua_State *L) {
+ size_t len = 0;
+ char const* s = luaL_checklstring(L, 1, &len);
+ char const* mode = luaL_optstring(L, 2, "bt");
+ lua_pushinteger(L, luaL_loadbufferx(L, s, len, s, mode));
+ return 2;
+}
+
+static int test_loadfile (lua_State *L) {
+ char filename[L_tmpnam+1] = { 0 };
+ size_t len = 0;
+ char const* s = luaL_checklstring(L, 1, &len);
+ char const* mode = luaL_optstring(L, 2, "bt");
+ if (tmpnam(filename)) {
+ FILE* f = fopen(filename, "wb");
+ if (f) {
+ fwrite(s, 1, len, f);
+ fclose(f);
+ lua_pushinteger(L, luaL_loadfilex(L, filename, mode));
+ remove(filename);
+ return 2;
+ } else
+ remove(filename);
+ }
+ return 0;
+}
+
static const luaL_Reg funcs[] = {
{ "isinteger", test_isinteger },
@@ -297,6 +322,8 @@ static const luaL_Reg funcs[] = {
{ "pushstring", test_pushstring },
{ "buffer", test_buffer },
{ "exec", test_exec },
+ { "loadstring", test_loadstring },
+ { "loadfile", test_loadfile },
{ NULL, NULL }
};
@@ -307,6 +334,9 @@ static const luaL_Reg more_funcs[] = {
};
+#ifdef __cplusplus
+extern "C" {
+#endif
int luaopen_testmod (lua_State *L) {
int i = 1;
luaL_newlib(L, funcs);
@@ -315,4 +345,7 @@ int luaopen_testmod (lua_State *L) {
luaL_setfuncs(L, more_funcs, NUP);
return 1;
}
+#ifdef __cplusplus
+}
+#endif