From 6ba979f3adcfeff3ecaf641e553a8e5cb9c33103 Mon Sep 17 00:00:00 2001 From: John Regan Date: Wed, 12 Aug 2026 10:24:20 -0400 Subject: [PATCH] Merge lua-compat-5.3 v0.15.1 --- vendor/compat53/.github/dependabot.yml | 15 + .../workflows/bit32-multi-arch-tests.yml | 53 ++ .../.github/workflows/compat53-tests.yml | 100 +++ vendor/compat53/.travis.yml | 2 +- vendor/compat53/LICENSE | 3 +- vendor/compat53/README.md | 51 +- vendor/compat53/c-api/compat-5.3.c | 13 +- vendor/compat53/c-api/compat-5.3.h | 35 +- vendor/compat53/compat53/file_mt.lua | 71 ++ vendor/compat53/compat53/init.lua | 62 +- vendor/compat53/compat53/module.lua | 86 +- vendor/compat53/lbitlib.c | 14 +- vendor/compat53/liolib.c | 776 ++++++++++++++++++ vendor/compat53/lprefix.h | 107 +++ .../compat53/rockspecs/bit32-5.3.5-1.rockspec | 2 +- .../rockspecs/bit32-5.3.5.1-1.rockspec | 28 + .../compat53/rockspecs/bit32-scm-1.rockspec | 6 +- .../rockspecs/compat53-0.1-1.rockspec | 4 +- ...cm-0.rockspec => compat53-0.11-1.rockspec} | 9 +- .../rockspecs/compat53-0.12-1.rockspec | 33 + .../rockspecs/compat53-0.13-1.rockspec | 32 + .../rockspecs/compat53-0.14-1.rockspec | 33 + .../rockspecs/compat53-0.14.1-1.rockspec | 33 + .../rockspecs/compat53-0.14.2-1.rockspec | 32 + .../rockspecs/compat53-0.14.3-1.rockspec | 32 + .../rockspecs/compat53-0.14.4-1.rockspec | 32 + .../rockspecs/compat53-0.15.0-1.rockspec | 32 + .../rockspecs/compat53-0.15.1-1.rockspec | 32 + .../rockspecs/compat53-0.2-1.rockspec | 4 +- .../rockspecs/compat53-0.3-1.rockspec | 4 +- .../rockspecs/compat53-0.4-1.rockspec | 4 +- .../rockspecs/compat53-0.5-1.rockspec | 4 +- .../rockspecs/compat53-0.7-1.rockspec | 4 +- .../rockspecs/compat53-0.8-1.rockspec | 4 +- .../rockspecs/compat53-scm-1.rockspec | 34 + vendor/compat53/tests/test-bit32.lua | 1 + vendor/compat53/tests/test.lua | 38 +- 37 files changed, 1698 insertions(+), 127 deletions(-) create mode 100644 vendor/compat53/.github/dependabot.yml create mode 100644 vendor/compat53/.github/workflows/bit32-multi-arch-tests.yml create mode 100644 vendor/compat53/.github/workflows/compat53-tests.yml create mode 100644 vendor/compat53/compat53/file_mt.lua create mode 100644 vendor/compat53/liolib.c create mode 100644 vendor/compat53/rockspecs/bit32-5.3.5.1-1.rockspec rename vendor/compat53/rockspecs/{compat53-scm-0.rockspec => compat53-0.11-1.rockspec} (78%) create mode 100644 vendor/compat53/rockspecs/compat53-0.12-1.rockspec create mode 100644 vendor/compat53/rockspecs/compat53-0.13-1.rockspec create mode 100644 vendor/compat53/rockspecs/compat53-0.14-1.rockspec create mode 100644 vendor/compat53/rockspecs/compat53-0.14.1-1.rockspec create mode 100644 vendor/compat53/rockspecs/compat53-0.14.2-1.rockspec create mode 100644 vendor/compat53/rockspecs/compat53-0.14.3-1.rockspec create mode 100644 vendor/compat53/rockspecs/compat53-0.14.4-1.rockspec create mode 100644 vendor/compat53/rockspecs/compat53-0.15.0-1.rockspec create mode 100644 vendor/compat53/rockspecs/compat53-0.15.1-1.rockspec create mode 100644 vendor/compat53/rockspecs/compat53-scm-1.rockspec diff --git a/vendor/compat53/.github/dependabot.yml b/vendor/compat53/.github/dependabot.yml new file mode 100644 index 0000000..bfccd65 --- /dev/null +++ b/vendor/compat53/.github/dependabot.yml @@ -0,0 +1,15 @@ +# Keep GitHub Actions up to date with GitHub's Dependabot... +# https://docs.github.com/en/code-security/how-tos/secure-your-supply-chain/secure-your-dependencies/auto-update-actions +# https://docs.github.com/en/code-security/reference/supply-chain-security/dependabot-options-reference#package-ecosystem +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + groups: + github-actions: + patterns: + - "*" # Group all Actions updates into a single larger pull request + schedule: + interval: weekly + cooldown: # https://nesbitt.io/2026/03/04/package-managers-need-to-cool-down.html + default-days: 7 diff --git a/vendor/compat53/.github/workflows/bit32-multi-arch-tests.yml b/vendor/compat53/.github/workflows/bit32-multi-arch-tests.yml new file mode 100644 index 0000000..7c9d76f --- /dev/null +++ b/vendor/compat53/.github/workflows/bit32-multi-arch-tests.yml @@ -0,0 +1,53 @@ +name: bit32-multi-arch-tests +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] +jobs: + bit32-test: + runs-on: ubuntu-latest + name: bit32 tests on ${{ matrix.luaVersion }} ${{ matrix.arch }} + strategy: + fail-fast: false + matrix: + luaVersion: ["5.1.5", "5.4.1"] + luaRocksVersion: ["3.3.1"] + arch: ["armv7", "aarch64"] + steps: + - uses: actions/checkout@v7 + - uses: actions/cache@v6 + id: lua-cache + with: + path: .install/${{ matrix.arch }}/lua-${{ matrix.luaVersion }} + key: lua-on-linux-${{ matrix.arch }}-${{ matrix.luaVersion }} + - uses: uraimo/run-on-arch-action@v3 + with: + arch: ${{ matrix.arch }} + distro: ubuntu_rolling + githubToken: ${{ github.token }} + setup: | + mkdir -p ".install/${{ matrix.arch }}" + install: | + apt-get update -q -y + apt-get install -q -y curl unzip build-essential libreadline-dev libncurses-dev clang + rm -rf /var/lib/apt/lists/* + run: | + v() { + echo -n -e "\033[36m" >&2 + echo -n "# $*" >&2 + echo -e "\033[0m" >&2 + "$@" + } + export CC=clang + if [ "${{ steps.lua-cache.outputs.cache-hit }}" != true ]; then + (set -o pipefail; cd ".install/${{ matrix.arch }}" && v curl --fail --silent --location "http://www.lua.org/ftp/lua-${{ matrix.luaVersion }}.tar.gz" | tar xzpf -) + (cd ".install/${{ matrix.arch }}/lua-${{ matrix.luaVersion }}" && v make linux) + fi + (cd ".install/${{ matrix.arch }}/lua-${{ matrix.luaVersion }}" && v make install) + (set -o pipefail; cd .install && v curl --fail --silent --location "http://luarocks.org/releases/luarocks-${{ matrix.luaRocksVersion }}.tar.gz" | tar xzpf -) + (cd ".install/luarocks-${{ matrix.luaRocksVersion }}" && v ./configure && v make bootstrap) + eval "$(luarocks path)" + v luarocks make rockspecs/bit32-scm-1.rockspec + v lua tests/test-bit32.lua + diff --git a/vendor/compat53/.github/workflows/compat53-tests.yml b/vendor/compat53/.github/workflows/compat53-tests.yml new file mode 100644 index 0000000..2c66aea --- /dev/null +++ b/vendor/compat53/.github/workflows/compat53-tests.yml @@ -0,0 +1,100 @@ +name: compat53-tests +on: + push: + branches: ["master"] + pull_request: + branches: ["master"] +jobs: + compat53-test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - luaVersion: "lua=5.1" + compiler: gcc + external: false + - luaVersion: "lua=5.1" + compiler: gcc + external: true + - luaVersion: "lua=5.1" + compiler: g++ + external: true + - luaVersion: "lua=5.1" + compiler: clang + external: false + - luaVersion: "luajit=@v2.1 --compat=none" + compiler: gcc + external: false + - luaVersion: "luajit=@v2.1 --compat=none" + compiler: gcc + external: true + - luaVersion: "luajit=@v2.1 --compat=all" + compiler: gcc + external: false + - luaVersion: "luajit=@v2.1 --compat=all" + compiler: gcc + external: true + - luaVersion: "lua=5.2" + compiler: gcc + external: false + - luaVersion: "lua=5.2" + compiler: gcc + external: true + - luaVersion: "lua=5.2" + compiler: g++ + external: true + steps: + - uses: actions/checkout@v7 + - name: install Lua + run: | + sudo apt install libreadline-dev + pip3 install --user hererocks + ~/.local/bin/hererocks old --${{ matrix.luaVersion }} + test -e old/bin/lua || (cd old/bin && ln -s luajit* lua) + ~/.local/bin/hererocks new --lua=5.3 + - name: compile C modules + run: | + export CC=${{ matrix.compiler }} CFLAGS="-Wall -Wextra -Ic-api -O2 -fPIC" + export DEF="" SRC="" + if [ "${{ matrix.external }}" = true ]; 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} + ${CC} ${CFLAGS} -Iold/include ${DEF} -shared -o old/compat53.so ltablib.c lutf8lib.c lstrlib.c liolib.c ${SRC} + - name: run test scripts + run: | + (cd old && bin/lua ../tests/test.lua) > old.txt + (cd new && bin/lua ../tests/test.lua) > new.txt + - name: compare script output + run: diff old.txt new.txt || true + + compat53-install: + strategy: + fail-fast: false # https://github.com/actions/runner-images#available-images + matrix: # https://www.lua.org/versions.html + os: [ubuntu-latest] + lua-version: [5.1, 5.2, 5.3, 5.4, 5.5] + include: + - os: macos-latest + lua-version: 5.1 + - os: macos-latest + lua-version: 5.5 + runs-on: ${{ matrix.os }} + steps: + - run: echo "${{ runner.os }} on ${{ runner.arch }}" + - uses: actions/checkout@v7 + - uses: luarocks/gh-actions-lua@master + with: + luaVersion: ${{ matrix.lua-version }} + - uses: luarocks/gh-actions-luarocks@master + with: + luaRocksVersion: "3.13.0" + - run: lua -v && luarocks --version + - run: luarocks lint rockspecs/compat53-scm-1.rockspec + # Install the local version of compat53. + - run: luarocks --local make rockspecs/compat53-scm-1.rockspec + - run: luarocks list && luarocks show compat53 + - run: luarocks --local remove compat53 + # Install the public version of compat53. + - run: luarocks install --check-lua-versions compat53 + - run: luarocks list && luarocks show compat53 diff --git a/vendor/compat53/.travis.yml b/vendor/compat53/.travis.yml index af458d8..44ae3a0 100644 --- a/vendor/compat53/.travis.yml +++ b/vendor/compat53/.travis.yml @@ -38,7 +38,7 @@ install: - 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} + - gcc ${CFLAGS} -Iold/include ${DEF} -shared -o old/compat53.so ltablib.c lutf8lib.c lstrlib.c liolib.c ${SRC} script: - (cd old && bin/lua ../tests/test.lua) > old.txt diff --git a/vendor/compat53/LICENSE b/vendor/compat53/LICENSE index 511db15..193ed12 100644 --- a/vendor/compat53/LICENSE +++ b/vendor/compat53/LICENSE @@ -1,6 +1,7 @@ The MIT License (MIT) -Copyright (c) 2015 Kepler Project. +Copyright (C) 1994-2020 Lua.org, PUC-Rio. +Copyright (C) 2013-2023 The Lua-Compat-5.3 authors. 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 diff --git a/vendor/compat53/README.md b/vendor/compat53/README.md index 0fcd657..3ee6acf 100644 --- a/vendor/compat53/README.md +++ b/vendor/compat53/README.md @@ -1,4 +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) +[![Compat53 Status](https://github.com/lunarmodules/lua-compat-5.3/workflows/compat53-tests/badge.svg)](https://github.com/lunarmodules/lua-compat-5.3/actions?workflow=compat53-tests) +[![Bit32 Status](https://github.com/lunarmodules/lua-compat-5.3/workflows/bit32-multi-arch-tests/badge.svg)](https://github.com/lunarmodules/lua-compat-5.3/actions?workflow=bit32-multi-arch-tests) # lua-compat-5.3 @@ -116,6 +117,8 @@ For Lua 5.1 additionally: * `io.write` and `file:write` return file handle * `io.lines` and `file:lines` accept format arguments (like `io.read`) (see [here][10] and [here][11]) +* `file:close` returns three results when a process is opened + with `io.popen` * `debug.setmetatable` returns object * `debug.getuservalue` (see [here][12]) * `debug.setuservalue` (see [here][13]) @@ -214,27 +217,27 @@ This package contains code written by: [1]: http://www.inf.puc-rio.br/~roberto/struct/ - [2]: http://github.com/keplerproject/lua-compat-5.2/ - [3]: http://keplerproject.org/compat/ - [4]: https://github.com/keplerproject/lua-compat-5.3/wiki/string_packing - [5]: https://github.com/keplerproject/lua-compat-5.3/wiki/math.type - [6]: https://github.com/keplerproject/lua-compat-5.3/wiki/pattern_matching - [7]: https://github.com/keplerproject/lua-compat-5.3/wiki/pairs - [8]: https://github.com/keplerproject/lua-compat-5.3/wiki/package.searchpath - [9]: https://github.com/keplerproject/lua-compat-5.3/wiki/os.execute - [10]: https://github.com/keplerproject/lua-compat-5.3/wiki/io.lines - [11]: https://github.com/keplerproject/lua-compat-5.3/wiki/file.lines - [12]: https://github.com/keplerproject/lua-compat-5.3/wiki/debug.getuservalue - [13]: https://github.com/keplerproject/lua-compat-5.3/wiki/debug.setuservalue - [14]: https://github.com/keplerproject/lua-compat-5.3/wiki/yieldable_c_functions - [15]: https://github.com/keplerproject/lua-compat-5.3/wiki/lua_dump - [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/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 - [24]: https://github.com/keplerproject/lua-compat-5.3/wiki/lua_getextraspace + [2]: http://github.com/lunarmodules/lua-compat-5.2/ + [3]: http://lunarmodules.org/compat/ + [4]: https://github.com/lunarmodules/lua-compat-5.3/wiki/string_packing + [5]: https://github.com/lunarmodules/lua-compat-5.3/wiki/math.type + [6]: https://github.com/lunarmodules/lua-compat-5.3/wiki/pattern_matching + [7]: https://github.com/lunarmodules/lua-compat-5.3/wiki/pairs + [8]: https://github.com/lunarmodules/lua-compat-5.3/wiki/package.searchpath + [9]: https://github.com/lunarmodules/lua-compat-5.3/wiki/os.execute + [10]: https://github.com/lunarmodules/lua-compat-5.3/wiki/io.lines + [11]: https://github.com/lunarmodules/lua-compat-5.3/wiki/file.lines + [12]: https://github.com/lunarmodules/lua-compat-5.3/wiki/debug.getuservalue + [13]: https://github.com/lunarmodules/lua-compat-5.3/wiki/debug.setuservalue + [14]: https://github.com/lunarmodules/lua-compat-5.3/wiki/yieldable_c_functions + [15]: https://github.com/lunarmodules/lua-compat-5.3/wiki/lua_dump + [16]: https://github.com/lunarmodules/lua-compat-5.3/wiki/lua_getuservalue + [17]: https://github.com/lunarmodules/lua-compat-5.3/wiki/lua_setuservalue + [18]: https://github.com/lunarmodules/lua-compat-5.3/wiki/lua_stringtonumber + [19]: https://github.com/lunarmodules/lua-compat-5.3/wiki/luaL_Stream + [20]: https://github.com/lunarmodules/lua-compat-5.3/wiki/lua_arith + [21]: https://github.com/lunarmodules/lua-compat-5.3/wiki/luaL_checkversion + [22]: https://github.com/lunarmodules/lua-compat-5.3/wiki/luaL_Buffer + [23]: https://github.com/lunarmodules/lua-compat-5.3/wiki/coroutine.running + [24]: https://github.com/lunarmodules/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 42b0a4b..1901a82 100644 --- a/vendor/compat53/c-api/compat-5.3.c +++ b/vendor/compat53/c-api/compat-5.3.c @@ -28,9 +28,10 @@ #endif /* VC++ _fsopen for share-allowed file read */ #ifndef COMPAT53_HAVE_STRERROR_R -# if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \ +# if (!defined(_WIN32)) && \ + ((defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \ (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600) || \ - defined(__APPLE__) + defined(__APPLE__)) # define COMPAT53_HAVE_STRERROR_R 1 # else /* none of the defines matched: define to 0 */ # define COMPAT53_HAVE_STRERROR_R 0 @@ -715,6 +716,14 @@ void luaL_pushresult (luaL_Buffer_53 *B) { #if defined( LUA_VERSION_NUM ) && LUA_VERSION_NUM <= 502 +COMPAT53_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { +#undef lua_pushlstring + lua_pushlstring(L, len > 0 ? s : "", len); +#define lua_pushlstring COMPAT53_CONCAT(COMPAT53_PREFIX, _pushlstring_53) + return lua_tostring(L, -1); +} + + COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i) { index = lua_absindex(L, index); lua_pushinteger(L, i); diff --git a/vendor/compat53/c-api/compat-5.3.h b/vendor/compat53/c-api/compat-5.3.h index b730a4b..de6c402 100644 --- a/vendor/compat53/c-api/compat-5.3.h +++ b/vendor/compat53/c-api/compat-5.3.h @@ -142,9 +142,6 @@ COMPAT53_API void lua_len (lua_State *L, int i); #define lua_pushstring(L, s) \ (lua_pushstring((L), (s)), lua_tostring((L), -1)) -#define lua_pushlstring(L, s, len) \ - ((((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))), lua_tostring((L), -1)) - #ifndef luaL_newlibtable # define luaL_newlibtable(L, l) \ (lua_createtable((L), 0, sizeof((l))/sizeof(*(l))-1)) @@ -290,6 +287,9 @@ typedef int (*lua_KFunction)(lua_State *L, int status, lua_KContext ctx); #define lua_gettable(L, i) \ (lua_gettable((L), (i)), lua_type((L), -1)) +#define lua_pushlstring COMPAT53_CONCAT(COMPAT53_PREFIX, _pushlstring_53) +COMPAT53_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len); + #define lua_geti COMPAT53_CONCAT(COMPAT53_PREFIX, _geti) COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i); @@ -352,9 +352,6 @@ COMPAT53_API void luaL_requiref (lua_State *L, const char *modname, #define lua_getuservalue(L, i) \ (lua_getuservalue((L), (i)), lua_type((L), -1)) -#define lua_pushlstring(L, s, len) \ - (((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))) - #define lua_rawgetp(L, i, p) \ (lua_rawgetp((L), (i), (p)), lua_type((L), -1)) @@ -398,12 +395,32 @@ COMPAT53_API void luaL_requiref (lua_State *L, const char *modname, +/* declarations for Lua 5.5 */ +#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 505 + +/* +** Internal assertions for in-house debugging +*/ +#if defined LUAI_ASSERT +# undef NDEBUG +# include +# define lua_assert(c) assert(c) +#endif + +#if !defined(lua_assert) +# define lua_assert(c) ((void)0) +#endif + +#endif /* Lua 5.5 only */ + + + /* other Lua versions */ -#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 || LUA_VERSION_NUM > 504 +#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 || LUA_VERSION_NUM > 505 -# error "unsupported Lua version (i.e. not Lua 5.1, 5.2, 5.3, or 5.4)" +# error "unsupported Lua version (i.e. not Lua 5.1, 5.2, 5.3, 5.4, or 5.5)" -#endif /* other Lua versions except 5.1, 5.2, 5.3, and 5.4 */ +#endif /* other Lua versions except 5.1, 5.2, 5.3, 5.4, and 5.5 */ diff --git a/vendor/compat53/compat53/file_mt.lua b/vendor/compat53/compat53/file_mt.lua new file mode 100644 index 0000000..6433619 --- /dev/null +++ b/vendor/compat53/compat53/file_mt.lua @@ -0,0 +1,71 @@ +local lua_version = _VERSION:sub(-3) + +local M = {} + +local unpack = lua_version == "5.1" and unpack or table.unpack + +local function addasterisk(fmt) + if type(fmt) == "string" and fmt:sub(1, 1) ~= "*" then + return "*"..fmt + else + return fmt + end +end + +function M.update_file_meta(file_meta, is_luajit52) + + -- make '*' optional for file:read and file:lines + + local file_lines = file_meta.__index.lines + file_meta.__index.lines = function(self, ...) + local n = select('#', ...) + for i = 1, n do + local a = select(i, ...) + local b = addasterisk(a) + -- as an optimization we only allocate a table for the + -- modified format arguments when we have a '*' somewhere + if a ~= b then + local args = { ... } + args[i] = b + for j = i+1, n do + args[j] = addasterisk(args[j]) + end + return file_lines(self, unpack(args, 1, n)) + end + end + return file_lines(self, ...) + end + + local file_read = file_meta.__index.read + file_meta.__index.read = function(self, ...) + local n = select('#', ...) + for i = 1, n do + local a = select(i, ...) + local b = addasterisk(a) + -- as an optimization we only allocate a table for the + -- modified format arguments when we have a '*' somewhere + if a ~= b then + local args = { ... } + args[i] = b + for j = i+1, n do + args[j] = addasterisk(args[j]) + end + return file_read(self, unpack(args, 1, n)) + end + end + return file_read(self, ...) + end + + if not is_luajit52 then + local file_write = file_meta.__index.write + file_meta.__index.write = function(self, ...) + local ret, err = file_write(self, ...) + if ret then + return self + end + return ret, err + end + end +end + +return M diff --git a/vendor/compat53/compat53/init.lua b/vendor/compat53/compat53/init.lua index a7f0c80..b507571 100644 --- a/vendor/compat53/compat53/init.lua +++ b/vendor/compat53/compat53/init.lua @@ -17,57 +17,15 @@ if lua_version < "5.3" then local file_meta = gmt(io.stdout) - -- make '*' optional for file:read and file:lines - if type(file_meta) == "table" and type(file_meta.__index) == "table" then - - local function addasterisk(fmt) - if type(fmt) == "string" and fmt:sub(1, 1) ~= "*" then - return "*"..fmt - else - return fmt - end - end - - local file_lines = file_meta.__index.lines - file_meta.__index.lines = function(self, ...) - local n = select('#', ...) - for i = 1, n do - local a = select(i, ...) - local b = addasterisk(a) - -- as an optimization we only allocate a table for the - -- modified format arguments when we have a '*' somewhere - if a ~= b then - local args = { ... } - args[i] = b - for j = i+1, n do - args[j] = addasterisk(args[j]) - end - return file_lines(self, unpack(args, 1, n)) - end - end - return file_lines(self, ...) - end + -- detect LuaJIT (including LUAJIT_ENABLE_LUA52COMPAT compilation flag) + local is_luajit = (string.dump(function() end) or ""):sub(1, 3) == "\027LJ" + local is_luajit52 = is_luajit and + #setmetatable({}, { __len = function() return 1 end }) == 1 - local file_read = file_meta.__index.read - file_meta.__index.read = function(self, ...) - local n = select('#', ...) - for i = 1, n do - local a = select(i, ...) - local b = addasterisk(a) - -- as an optimization we only allocate a table for the - -- modified format arguments when we have a '*' somewhere - if a ~= b then - local args = { ... } - args[i] = b - for j = i+1, n do - args[j] = addasterisk(args[j]) - end - return file_read(self, unpack(args, 1, n)) - end - end - return file_read(self, ...) - end + if type(file_meta) == "table" and type(file_meta.__index) == "table" then + local file_mt = require("compat53.file_mt") + file_mt.update_file_meta(file_meta, is_luajit52) end -- got a valid metatable for file objects @@ -85,12 +43,6 @@ if lua_version < "5.3" then local io_type = io.type - -- detect LuaJIT (including LUAJIT_ENABLE_LUA52COMPAT compilation flag) - local is_luajit = (string.dump(function() end) or ""):sub(1, 3) == "\027LJ" - local is_luajit52 = is_luajit and - #setmetatable({}, { __len = function() return 1 end }) == 1 - - -- make package.searchers available as an alias for package.loaders local p_index = { searchers = package.loaders } setmetatable(package, { diff --git a/vendor/compat53/compat53/module.lua b/vendor/compat53/compat53/module.lua index 30be6b5..b583875 100644 --- a/vendor/compat53/compat53/module.lua +++ b/vendor/compat53/compat53/module.lua @@ -13,7 +13,11 @@ if lua_version < "5.3" then debug, io, math, package, string, table local io_lines = io.lines local io_read = io.read + local io_open = io.open + local io_popen = io.popen + local io_tmpfile = io.tmpfile local unpack = lua_version == "5.1" and unpack or table.unpack + local debug_setmetatable = type(debug) == "table" and debug.setmetatable -- create module table M = {} @@ -67,6 +71,15 @@ if lua_version < "5.3" then end + -- load io functions + local io_ok, iolib = pcall(require, "compat53.io") + if io_ok then + for k,v in pairs(iolib) do + M.io[k] = v + end + end + + -- load string packing functions local str_ok, strlib = pcall(require, "compat53.string") if str_ok then @@ -106,6 +119,7 @@ if lua_version < "5.3" then M.math.mininteger = minint function M.math.tointeger(n) + n = tonumber(n) if type(n) == "number" and n <= maxint and n >= minint and n % 1 == 0 then return n end @@ -156,9 +170,9 @@ if lua_version < "5.3" then if cond then return cond, ... elseif select('#', ...) > 0 then - error((...), 0) + error((...), 2) else - error("assertion failed!", 0) + error("assertion failed!", 2) end end @@ -441,7 +455,6 @@ if lua_version < "5.3" then if type(debug) == "table" then local debug_setfenv = debug.setfenv local debug_getfenv = debug.getfenv - local debug_setmetatable = debug.setmetatable M.debug = setmetatable({}, { __index = debug }) @@ -813,6 +826,73 @@ if lua_version < "5.3" then end end -- not luajit + local is_full_compat = package.loaded["compat53"] or package.loaded["compat53.init"] + + -- When using the full `compat53.init` module, we override the global state, so + -- we can patch the FILE metatable. When using `compat53.module` on its own, however, + -- we have to choose between being compatible with the Lua 5.3 API of the file metamethods, + -- or with the pointer identity of the original LuaJIT metatable in the C API (see issue #70). + -- We default to be Lua 5.3 API compatible, but we offer the user a choice to override this + -- by setting a special global `LUA_COMPAT53_NO_FILE_META_OVERRIDE` to `true`, prior to + -- requiring `compat53.module`. + local use_modular_compat_file_meta = is_luajit + and not is_full_compat + and not _G.LUA_COMPAT53_NO_FILE_META_OVERRIDE + + if use_modular_compat_file_meta then + local compat_file_meta = {} + local compat_file_meta_loaded = 0 + + local function load_compat_file_meta(file_meta) + -- fill compat_file_meta with original entries + for k, v in pairs(file_meta) do + compat_file_meta[k] = v + end + compat_file_meta.__index = {} + for k, v in pairs(file_meta.__index) do + compat_file_meta.__index[k] = v + end + + compat_file_meta_loaded = 1 + + -- update it with compatibility functions + local file_mt_ok, file_mt = pcall(require, "compat53.file_mt") + if file_mt_ok then + file_mt.update_file_meta(compat_file_meta, is_luajit52) + + compat_file_meta_loaded = 2 + end + end + + local function return_fd(fd, err, code) + if not fd then + return fd, err, code + end + if fd and debug_setmetatable then + if compat_file_meta_loaded == 0 then + local file_meta = gmt(fd) + load_compat_file_meta(file_meta) + end + if compat_file_meta_loaded == 2 then + debug_setmetatable(fd, compat_file_meta) + end + end + return fd + end + + function M.io.open(...) + return return_fd(io_open(...)) + end + + function M.io.popen(...) + return return_fd(io_popen(...)) + end + + function M.io.tmpfile(...) + return return_fd(io_tmpfile(...)) + end + end + end -- lua 5.1 -- further write should be forwarded to _G diff --git a/vendor/compat53/lbitlib.c b/vendor/compat53/lbitlib.c index 4786c0d..db2652a 100644 --- a/vendor/compat53/lbitlib.c +++ b/vendor/compat53/lbitlib.c @@ -19,8 +19,18 @@ #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)) +#define pushunsigned(L,n) (sizeof(lua_Integer) > 4 ? lua_pushinteger(L, (lua_Integer)(n)) : lua_pushnumber(L, (lua_Number)(n))) +static lua_Unsigned checkunsigned(lua_State *L, int i) { + if (sizeof(lua_Integer) > 4) + return (lua_Unsigned)luaL_checkinteger(L, i); + else { + lua_Number d = luaL_checknumber(L, i); + if (d < 0) + d = (d + 1) + (~(lua_Unsigned)0); + luaL_argcheck(L, d >= 0 && d <= (~(lua_Unsigned)0), i, "value out of range"); + return (lua_Unsigned)d; + } +} /* number of bits to consider in a number */ diff --git a/vendor/compat53/liolib.c b/vendor/compat53/liolib.c new file mode 100644 index 0000000..8a9e75c --- /dev/null +++ b/vendor/compat53/liolib.c @@ -0,0 +1,776 @@ +/* +** $Id: liolib.c,v 2.151.1.1 2017/04/19 17:29:57 roberto Exp $ +** Standard I/O (and system) library +** See Copyright Notice in lua.h +*/ + +#define liolib_c +#define LUA_LIB + +#include "lprefix.h" + + +#include +#include +#include +#include +#include +#include + +#include "lua.h" + +#include "lauxlib.h" +#include "lualib.h" + + + + +/* +** Change this macro to accept other modes for 'fopen' besides +** the standard ones. +*/ +#if !defined(l_checkmode) + +/* accepted extensions to 'mode' in 'fopen' */ +#if !defined(L_MODEEXT) +#define L_MODEEXT "b" +#endif + +/* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */ +static int l_checkmode (const char *mode) { + return (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && + (*mode != '+' || (++mode, 1)) && /* skip if char is '+' */ + (strspn(mode, L_MODEEXT) == strlen(mode))); /* check extensions */ +} + +#endif + +/* +** {====================================================== +** l_popen spawns a new process connected to the current +** one through the file streams. +** ======================================================= +*/ + +#if !defined(l_popen) /* { */ + +#if defined(LUA_USE_POSIX) /* { */ + +#define l_popen(L,c,m) (fflush(NULL), popen(c,m)) +#define l_pclose(L,file) (pclose(file)) + +#elif defined(LUA_USE_WINDOWS) /* }{ */ + +#define l_popen(L,c,m) (_popen(c,m)) +#define l_pclose(L,file) (_pclose(file)) + +#else /* }{ */ + +/* ISO C definitions */ +#define l_popen(L,c,m) \ + ((void)((void)c, m), \ + luaL_error(L, "'popen' not supported"), \ + (FILE*)0) +#define l_pclose(L,file) ((void)L, (void)file, -1) + +#endif /* } */ + +#endif /* } */ + +/* }====================================================== */ + + +#if !defined(l_getc) /* { */ + +#if defined(LUA_USE_POSIX) +#define l_getc(f) getc_unlocked(f) +#define l_lockfile(f) flockfile(f) +#define l_unlockfile(f) funlockfile(f) +#else +#define l_getc(f) getc(f) +#define l_lockfile(f) ((void)0) +#define l_unlockfile(f) ((void)0) +#endif + +#endif /* } */ + + +/* +** {====================================================== +** l_fseek: configuration for longer offsets +** ======================================================= +*/ + +#if !defined(l_fseek) /* { */ + +#if defined(LUA_USE_POSIX) /* { */ + +#include + +#define l_fseek(f,o,w) fseeko(f,o,w) +#define l_ftell(f) ftello(f) +#define l_seeknum off_t + +#elif defined(LUA_USE_WINDOWS) && !defined(_CRTIMP_TYPEINFO) \ + && defined(_MSC_VER) && (_MSC_VER >= 1400) /* }{ */ + +/* Windows (but not DDK) and Visual C++ 2005 or higher */ +#define l_fseek(f,o,w) _fseeki64(f,o,w) +#define l_ftell(f) _ftelli64(f) +#define l_seeknum __int64 + +#else /* }{ */ + +/* ISO C definitions */ +#define l_fseek(f,o,w) fseek(f,o,w) +#define l_ftell(f) ftell(f) +#define l_seeknum long + +#endif /* } */ + +#endif /* } */ + +/* }====================================================== */ + + +#define IO_PREFIX "_IO_" +#define IOPREF_LEN (sizeof(IO_PREFIX)/sizeof(char) - 1) +#define IO_INPUT (IO_PREFIX "input") +#define IO_OUTPUT (IO_PREFIX "output") + + +typedef luaL_Stream LStream; + + +#define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE)) + +#define isclosed(p) ((p)->closef == NULL) + + +static int io_type (lua_State *L) { + LStream *p; + luaL_checkany(L, 1); + p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE); + if (p == NULL) + lua_pushnil(L); /* not a file */ + else if (isclosed(p)) + lua_pushliteral(L, "closed file"); + else + lua_pushliteral(L, "file"); + return 1; +} + + +static int f_tostring (lua_State *L) { + LStream *p = tolstream(L); + if (isclosed(p)) + lua_pushliteral(L, "file (closed)"); + else + lua_pushfstring(L, "file (%p)", p->f); + return 1; +} + + +static FILE *tofile (lua_State *L) { + LStream *p = tolstream(L); + if (isclosed(p)) + luaL_error(L, "attempt to use a closed file"); + lua_assert(p->f); + return p->f; +} + + +/* +** When creating file handles, always creates a 'closed' file handle +** before opening the actual file; so, if there is a memory error, the +** handle is in a consistent state. +*/ +static LStream *newprefile (lua_State *L) { + LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream)); + p->closef = NULL; /* mark file handle as 'closed' */ + luaL_setmetatable(L, LUA_FILEHANDLE); + return p; +} + + +/* +** Calls the 'close' function from a file handle. The 'volatile' avoids +** a bug in some versions of the Clang compiler (e.g., clang 3.0 for +** 32 bits). +*/ +static int aux_close (lua_State *L) { + LStream *p = tolstream(L); + volatile lua_CFunction cf = p->closef; + p->closef = NULL; /* mark stream as closed */ + return (*cf)(L); /* close it */ +} + + +static int f_close (lua_State *L) { + tofile(L); /* make sure argument is an open stream */ + return aux_close(L); +} + + +static int io_close (lua_State *L) { + if (lua_isnone(L, 1)) /* no argument? */ + lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */ + return f_close(L); +} + + +static int f_gc (lua_State *L) { + LStream *p = tolstream(L); + if (!isclosed(p) && p->f != NULL) + aux_close(L); /* ignore closed and incompletely open files */ + return 0; +} + + +/* +** function to close regular files +*/ +static int io_fclose (lua_State *L) { + LStream *p = tolstream(L); + int res = fclose(p->f); + return luaL_fileresult(L, (res == 0), NULL); +} + + +static LStream *newfile (lua_State *L) { + LStream *p = newprefile(L); + p->f = NULL; + p->closef = &io_fclose; + return p; +} + + +static void opencheck (lua_State *L, const char *fname, const char *mode) { + LStream *p = newfile(L); + p->f = fopen(fname, mode); + if (p->f == NULL) + luaL_error(L, "cannot open file '%s' (%s)", fname, strerror(errno)); +} + + +static int io_open (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + LStream *p = newfile(L); + const char *md = mode; /* to traverse/check mode */ + luaL_argcheck(L, l_checkmode(md), 2, "invalid mode"); + p->f = fopen(filename, mode); + return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; +} + + +/* +** function to close 'popen' files +*/ +static int io_pclose (lua_State *L) { + LStream *p = tolstream(L); + return luaL_execresult(L, l_pclose(L, p->f)); +} + + +static int io_popen (lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + const char *mode = luaL_optstring(L, 2, "r"); + LStream *p = newprefile(L); + p->f = l_popen(L, filename, mode); + p->closef = &io_pclose; + return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; +} + + +static int io_tmpfile (lua_State *L) { + LStream *p = newfile(L); + p->f = tmpfile(); + return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1; +} + + +static FILE *getiofile (lua_State *L, const char *findex) { + LStream *p; + lua_getfield(L, LUA_REGISTRYINDEX, findex); + p = (LStream *)lua_touserdata(L, -1); + if (isclosed(p)) + luaL_error(L, "standard %s file is closed", findex + IOPREF_LEN); + return p->f; +} + + +static int g_iofile (lua_State *L, const char *f, const char *mode) { + if (!lua_isnoneornil(L, 1)) { + const char *filename = lua_tostring(L, 1); + if (filename) + opencheck(L, filename, mode); + else { + tofile(L); /* check that it's a valid file handle */ + lua_pushvalue(L, 1); + } + lua_setfield(L, LUA_REGISTRYINDEX, f); + } + /* return current value */ + lua_getfield(L, LUA_REGISTRYINDEX, f); + return 1; +} + + +static int io_input (lua_State *L) { + return g_iofile(L, IO_INPUT, "r"); +} + + +static int io_output (lua_State *L) { + return g_iofile(L, IO_OUTPUT, "w"); +} + + +static int io_readline (lua_State *L); + + +/* +** maximum number of arguments to 'f:lines'/'io.lines' (it + 3 must fit +** in the limit for upvalues of a closure) +*/ +#define MAXARGLINE 250 + +static void aux_lines (lua_State *L, int toclose) { + int n = lua_gettop(L) - 1; /* number of arguments to read */ + luaL_argcheck(L, n <= MAXARGLINE, MAXARGLINE + 2, "too many arguments"); + lua_pushinteger(L, n); /* number of arguments to read */ + lua_pushboolean(L, toclose); /* close/not close file when finished */ + lua_rotate(L, 2, 2); /* move 'n' and 'toclose' to their positions */ + lua_pushcclosure(L, io_readline, 3 + n); +} + + +static int f_lines (lua_State *L) { + tofile(L); /* check that it's a valid file handle */ + aux_lines(L, 0); + return 1; +} + + +static int io_lines (lua_State *L) { + int toclose; + if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */ + if (lua_isnil(L, 1)) { /* no file name? */ + lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT); /* get default input */ + lua_replace(L, 1); /* put it at index 1 */ + tofile(L); /* check that it's a valid file handle */ + toclose = 0; /* do not close it after iteration */ + } + else { /* open a new file */ + const char *filename = luaL_checkstring(L, 1); + opencheck(L, filename, "r"); + lua_replace(L, 1); /* put file at index 1 */ + toclose = 1; /* close it after iteration */ + } + aux_lines(L, toclose); + return 1; +} + + +/* +** {====================================================== +** READ +** ======================================================= +*/ + + +/* maximum length of a numeral */ +#if !defined (L_MAXLENNUM) +#define L_MAXLENNUM 200 +#endif + + +/* auxiliary structure used by 'read_number' */ +typedef struct { + FILE *f; /* file being read */ + int c; /* current character (look ahead) */ + int n; /* number of elements in buffer 'buff' */ + char buff[L_MAXLENNUM + 1]; /* +1 for ending '\0' */ +} RN; + + +/* +** Add current char to buffer (if not out of space) and read next one +*/ +static int nextc (RN *rn) { + if (rn->n >= L_MAXLENNUM) { /* buffer overflow? */ + rn->buff[0] = '\0'; /* invalidate result */ + return 0; /* fail */ + } + else { + rn->buff[rn->n++] = rn->c; /* save current char */ + rn->c = l_getc(rn->f); /* read next one */ + return 1; + } +} + + +/* +** Accept current char if it is in 'set' (of size 2) +*/ +static int test2 (RN *rn, const char *set) { + if (rn->c == set[0] || rn->c == set[1]) + return nextc(rn); + else return 0; +} + + +/* +** Read a sequence of (hex)digits +*/ +static int readdigits (RN *rn, int hex) { + int count = 0; + while ((hex ? isxdigit(rn->c) : isdigit(rn->c)) && nextc(rn)) + count++; + return count; +} + + +/* +** Read a number: first reads a valid prefix of a numeral into a buffer. +** Then it calls 'lua_stringtonumber' to check whether the format is +** correct and to convert it to a Lua number +*/ +static int read_number (lua_State *L, FILE *f) { + RN rn; + int count = 0; + int hex = 0; + char decp[2]; + rn.f = f; rn.n = 0; + decp[0] = lua_getlocaledecpoint(); /* get decimal point from locale */ + decp[1] = '.'; /* always accept a dot */ + l_lockfile(rn.f); + do { rn.c = l_getc(rn.f); } while (isspace(rn.c)); /* skip spaces */ + test2(&rn, "-+"); /* optional signal */ + if (test2(&rn, "00")) { + if (test2(&rn, "xX")) hex = 1; /* numeral is hexadecimal */ + else count = 1; /* count initial '0' as a valid digit */ + } + count += readdigits(&rn, hex); /* integral part */ + if (test2(&rn, decp)) /* decimal point? */ + count += readdigits(&rn, hex); /* fractional part */ + if (count > 0 && test2(&rn, (hex ? "pP" : "eE"))) { /* exponent mark? */ + test2(&rn, "-+"); /* exponent signal */ + readdigits(&rn, 0); /* exponent digits */ + } + ungetc(rn.c, rn.f); /* unread look-ahead char */ + l_unlockfile(rn.f); + rn.buff[rn.n] = '\0'; /* finish string */ + if (lua_stringtonumber(L, rn.buff)) /* is this a valid number? */ + return 1; /* ok */ + else { /* invalid format */ + lua_pushnil(L); /* "result" to be removed */ + return 0; /* read fails */ + } +} + + +static int test_eof (lua_State *L, FILE *f) { + int c = getc(f); + ungetc(c, f); /* no-op when c == EOF */ + lua_pushliteral(L, ""); + return (c != EOF); +} + + +static int read_line (lua_State *L, FILE *f, int chop) { + luaL_Buffer b; + int c = '\0'; + luaL_buffinit(L, &b); + while (c != EOF && c != '\n') { /* repeat until end of line */ + char *buff = luaL_prepbuffer(&b); /* preallocate buffer */ + int i = 0; + l_lockfile(f); /* no memory errors can happen inside the lock */ + while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n') + buff[i++] = c; + l_unlockfile(f); + luaL_addsize(&b, i); + } + if (!chop && c == '\n') /* want a newline and have one? */ + luaL_addchar(&b, c); /* add ending newline to result */ + luaL_pushresult(&b); /* close buffer */ + /* return ok if read something (either a newline or something else) */ + return (c == '\n' || lua_rawlen(L, -1) > 0); +} + + +static void read_all (lua_State *L, FILE *f) { + size_t nr; + luaL_Buffer b; + luaL_buffinit(L, &b); + do { /* read file in chunks of LUAL_BUFFERSIZE bytes */ + char *p = luaL_prepbuffer(&b); + nr = fread(p, sizeof(char), LUAL_BUFFERSIZE, f); + luaL_addsize(&b, nr); + } while (nr == LUAL_BUFFERSIZE); + luaL_pushresult(&b); /* close buffer */ +} + + +static int read_chars (lua_State *L, FILE *f, size_t n) { + size_t nr; /* number of chars actually read */ + char *p; + luaL_Buffer b; + luaL_buffinit(L, &b); + p = luaL_prepbuffsize(&b, n); /* prepare buffer to read whole block */ + nr = fread(p, sizeof(char), n, f); /* try to read 'n' chars */ + luaL_addsize(&b, nr); + luaL_pushresult(&b); /* close buffer */ + return (nr > 0); /* true iff read something */ +} + + +static int g_read (lua_State *L, FILE *f, int first) { + int nargs = lua_gettop(L) - 1; + int success; + int n; + clearerr(f); + if (nargs == 0) { /* no arguments? */ + success = read_line(L, f, 1); + n = first+1; /* to return 1 result */ + } + else { /* ensure stack space for all results and for auxlib's buffer */ + luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments"); + success = 1; + for (n = first; nargs-- && success; n++) { + if (lua_type(L, n) == LUA_TNUMBER) { + size_t l = (size_t)luaL_checkinteger(L, n); + success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); + } + else { + const char *p = luaL_checkstring(L, n); + if (*p == '*') p++; /* skip optional '*' (for compatibility) */ + switch (*p) { + case 'n': /* number */ + success = read_number(L, f); + break; + case 'l': /* line */ + success = read_line(L, f, 1); + break; + case 'L': /* line with end-of-line */ + success = read_line(L, f, 0); + break; + case 'a': /* file */ + read_all(L, f); /* read entire file */ + success = 1; /* always success */ + break; + default: + return luaL_argerror(L, n, "invalid format"); + } + } + } + } + if (ferror(f)) + return luaL_fileresult(L, 0, NULL); + if (!success) { + lua_pop(L, 1); /* remove last result */ + lua_pushnil(L); /* push nil instead */ + } + return n - first; +} + + +static int io_read (lua_State *L) { + return g_read(L, getiofile(L, IO_INPUT), 1); +} + + +static int f_read (lua_State *L) { + return g_read(L, tofile(L), 2); +} + + +static int io_readline (lua_State *L) { + LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1)); + int i; + int n = (int)lua_tointeger(L, lua_upvalueindex(2)); + if (isclosed(p)) /* file is already closed? */ + return luaL_error(L, "file is already closed"); + lua_settop(L , 1); + luaL_checkstack(L, n, "too many arguments"); + for (i = 1; i <= n; i++) /* push arguments to 'g_read' */ + lua_pushvalue(L, lua_upvalueindex(3 + i)); + n = g_read(L, p->f, 2); /* 'n' is number of results */ + lua_assert(n > 0); /* should return at least a nil */ + if (lua_toboolean(L, -n)) /* read at least one value? */ + return n; /* return them */ + else { /* first result is nil: EOF or error */ + if (n > 1) { /* is there error information? */ + /* 2nd result is error message */ + return luaL_error(L, "%s", lua_tostring(L, -n + 1)); + } + if (lua_toboolean(L, lua_upvalueindex(3))) { /* generator created file? */ + lua_settop(L, 0); + lua_pushvalue(L, lua_upvalueindex(1)); + aux_close(L); /* close it */ + } + return 0; + } +} + +/* }====================================================== */ + + +static int g_write (lua_State *L, FILE *f, int arg) { + int nargs = lua_gettop(L) - arg; + int status = 1; + for (; nargs--; arg++) { + if (lua_type(L, arg) == LUA_TNUMBER) { + /* optimization: could be done exactly as for strings */ + int len = lua_isinteger(L, arg) + ? fprintf(f, LUA_INTEGER_FMT, + (LUAI_UACINT)lua_tointeger(L, arg)) + : fprintf(f, LUA_NUMBER_FMT, + (LUAI_UACNUMBER)lua_tonumber(L, arg)); + status = status && (len > 0); + } + else { + size_t l; + const char *s = luaL_checklstring(L, arg, &l); + status = status && (fwrite(s, sizeof(char), l, f) == l); + } + } + if (status) return 1; /* file handle already on stack top */ + else return luaL_fileresult(L, status, NULL); +} + + +static int io_write (lua_State *L) { + return g_write(L, getiofile(L, IO_OUTPUT), 1); +} + + +static int f_write (lua_State *L) { + FILE *f = tofile(L); + lua_pushvalue(L, 1); /* push file at the stack top (to be returned) */ + return g_write(L, f, 2); +} + + +static int f_seek (lua_State *L) { + static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; + static const char *const modenames[] = {"set", "cur", "end", NULL}; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, "cur", modenames); + lua_Integer p3 = luaL_optinteger(L, 3, 0); + l_seeknum offset = (l_seeknum)p3; + luaL_argcheck(L, (lua_Integer)offset == p3, 3, + "not an integer in proper range"); + op = l_fseek(f, offset, mode[op]); + if (op) + return luaL_fileresult(L, 0, NULL); /* error */ + else { + lua_pushinteger(L, (lua_Integer)l_ftell(f)); + return 1; + } +} + + +static int f_setvbuf (lua_State *L) { + static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; + static const char *const modenames[] = {"no", "full", "line", NULL}; + FILE *f = tofile(L); + int op = luaL_checkoption(L, 2, NULL, modenames); + lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE); + int res = setvbuf(f, NULL, mode[op], (size_t)sz); + return luaL_fileresult(L, res == 0, NULL); +} + + + +static int io_flush (lua_State *L) { + return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL); +} + + +static int f_flush (lua_State *L) { + return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL); +} + + +/* +** functions for 'io' library +*/ +static const luaL_Reg iolib[] = { + {"close", io_close}, + {"flush", io_flush}, + {"input", io_input}, + {"lines", io_lines}, + {"open", io_open}, + {"output", io_output}, + {"popen", io_popen}, + {"read", io_read}, + {"tmpfile", io_tmpfile}, + {"type", io_type}, + {"write", io_write}, + {NULL, NULL} +}; + + +/* +** methods for file handles +*/ +static const luaL_Reg flib[] = { + {"close", f_close}, + {"flush", f_flush}, + {"lines", f_lines}, + {"read", f_read}, + {"seek", f_seek}, + {"setvbuf", f_setvbuf}, + {"write", f_write}, + {"__gc", f_gc}, + {"__tostring", f_tostring}, + {NULL, NULL} +}; + + +static void createmeta (lua_State *L) { + luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ + lua_pushvalue(L, -1); /* push metatable */ + lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ + luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */ + lua_pop(L, 1); /* pop new metatable */ +} + + +/* +** function to (not) close the standard files stdin, stdout, and stderr +*/ +static int io_noclose (lua_State *L) { + LStream *p = tolstream(L); + p->closef = &io_noclose; /* keep file opened */ + lua_pushnil(L); + lua_pushliteral(L, "cannot close standard file"); + return 2; +} + + +static void createstdfile (lua_State *L, FILE *f, const char *k, + const char *fname) { + LStream *p = newprefile(L); + p->f = f; + p->closef = &io_noclose; + if (k != NULL) { + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, k); /* add file to registry */ + } + lua_setfield(L, -2, fname); /* add file to module */ +} + + +LUAMOD_API int luaopen_io (lua_State *L) { + luaL_newlib(L, iolib); /* new module */ + createmeta(L); + /* create (and set) default files */ + createstdfile(L, stdin, IO_INPUT, "stdin"); + createstdfile(L, stdout, IO_OUTPUT, "stdout"); + createstdfile(L, stderr, NULL, "stderr"); + return 1; +} + diff --git a/vendor/compat53/lprefix.h b/vendor/compat53/lprefix.h index 0eb149f..0f83906 100644 --- a/vendor/compat53/lprefix.h +++ b/vendor/compat53/lprefix.h @@ -173,3 +173,110 @@ LUAMOD_API int luaopen_compat53_string (lua_State *L) { #endif + +#ifdef liolib_c +/* move the io library open function out of the way (we only take + * the popen and type functions)! + */ +# define luaopen_io luaopen_io_XXX + +#include +#include + +# if !defined(lua_getlocaledecpoint) +# define lua_getlocaledecpoint() (localeconv()->decimal_point[0]) +# endif + +# ifndef LUA_INTEGER_FMT +# define LUA_INTEGER_FMT "%ld" +# endif +# ifndef LUAI_UACINT +# define LUAI_UACINT lua_Integer +# endif + +/* choose which popen implementation to pick */ +# if (defined(_WIN32) && !defined(__CYGWIN__)) +# define LUA_USE_WINDOWS 1 +# endif +# if (!defined(LUA_USE_WINDOWS) && !defined(LUA_USE_POSIX)) && \ + ((defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \ + (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600) || \ + defined(__APPLE__)) +# define LUA_USE_POSIX 1 +# endif + +typedef struct COMPAT53_luaL_Stream { + FILE *f; /* stream (NULL for incompletely created streams) */ + lua_CFunction closef; /* to close stream (NULL for closed streams) */ +} COMPAT53_luaL_Stream; + +#define luaL_Stream COMPAT53_luaL_Stream + +#define COMPAT53_LUA_PFILEHANDLE "PFILE*" + +static int io_ptype (lua_State *L) { + luaL_Stream *p; + luaL_checkany(L, 1); + p = (luaL_Stream *)luaL_testudata(L, 1, COMPAT53_LUA_PFILEHANDLE); + if (p) { + /* Lua 5.3 implementation, for popen files */ + if (p->closef == NULL) + lua_pushliteral(L, "closed file"); + else + lua_pushliteral(L, "file"); + return 1; + } else { + /* Lua 5.1 implementation, for plain files */ + void *ud = lua_touserdata(L, 1); + lua_getfield(L, LUA_REGISTRYINDEX, LUA_FILEHANDLE); + if (ud == NULL || !lua_getmetatable(L, 1) || !lua_rawequal(L, -2, -1)) + lua_pushnil(L); /* not a file */ + else if (*((FILE **)ud) == NULL) + lua_pushliteral(L, "closed file"); + else + lua_pushliteral(L, "file"); + return 1; + } +} + +static int io_popen (lua_State *L); +static void createmeta (lua_State *L); + +# undef LUA_FILEHANDLE +# define LUA_FILEHANDLE COMPAT53_LUA_PFILEHANDLE + +LUAMOD_API int luaopen_compat53_io (lua_State *L) { + luaL_Reg const funcs[] = { + +/* for PUC-Rio Lua 5.1 only */ +# if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 && !defined(LUA_JITLIBNAME) + + { "popen", io_popen }, + { "type", io_ptype }, + +# endif /* for PUC-Rio Lua 5.1 only */ + + { NULL, NULL } + }; + luaL_newlib(L, funcs); + createmeta(L); + return 1; +} + + +/* fake CLANG feature detection on other compilers */ +# ifndef __has_attribute +# define __has_attribute(x) 0 +# endif +/* make luaopen_io(_XXX) static, so it (and all other referenced + * io functions) won't be included in the resulting dll + * (hopefully). + */ +# undef LUAMOD_API +# if defined(__GNUC__) || __has_attribute(__unused__) +# define LUAMOD_API __attribute__((__unused__)) static +# else +# define LUAMOD_API static +# endif + +#endif /* iolib.c */ diff --git a/vendor/compat53/rockspecs/bit32-5.3.5-1.rockspec b/vendor/compat53/rockspecs/bit32-5.3.5-1.rockspec index e27dedb..353e19c 100644 --- a/vendor/compat53/rockspecs/bit32-5.3.5-1.rockspec +++ b/vendor/compat53/rockspecs/bit32-5.3.5-1.rockspec @@ -1,7 +1,7 @@ package = "bit32" version = "5.3.5-1" source = { - url = "https://github.com/keplerproject/lua-compat-5.3/archive/v0.9.zip", + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.9.zip", dir = "lua-compat-5.3-0.9", } description = { diff --git a/vendor/compat53/rockspecs/bit32-5.3.5.1-1.rockspec b/vendor/compat53/rockspecs/bit32-5.3.5.1-1.rockspec new file mode 100644 index 0000000..371f1ae --- /dev/null +++ b/vendor/compat53/rockspecs/bit32-5.3.5.1-1.rockspec @@ -0,0 +1,28 @@ +package = "bit32" +version = "5.3.5.1-1" +source = { + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.10.zip", + dir = "lua-compat-5.3-0.10", +} +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, 5.3 and 5.4. + ]], + 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 index cce77de..16e81b5 100644 --- a/vendor/compat53/rockspecs/bit32-scm-1.rockspec +++ b/vendor/compat53/rockspecs/bit32-scm-1.rockspec @@ -1,8 +1,8 @@ package = "bit32" version = "scm-1" source = { - url = "https://github.com/keplerproject/lua-compat-5.3/archive/master.zip", - branch = "lua-compat-5.3-master", + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/master.zip", + dir = "lua-compat-5.3-master", } description = { summary = "Lua 5.2 bit manipulation library", @@ -14,7 +14,7 @@ description = { license = "MIT" } dependencies = { - "lua >= 5.1, < 5.5" + "lua >= 5.1, < 5.6" } build = { type = "builtin", diff --git a/vendor/compat53/rockspecs/compat53-0.1-1.rockspec b/vendor/compat53/rockspecs/compat53-0.1-1.rockspec index 0ff56b0..b9012fe 100644 --- a/vendor/compat53/rockspecs/compat53-0.1-1.rockspec +++ b/vendor/compat53/rockspecs/compat53-0.1-1.rockspec @@ -1,7 +1,7 @@ package = "compat53" version = "0.1-1" source = { - url = "https://github.com/keplerproject/lua-compat-5.3/archive/v0.1.zip", + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.1.zip", dir = "lua-compat-5.3-0.1", } description = { @@ -12,7 +12,7 @@ description = { 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", + homepage = "https://github.com/lunarmodules/lua-compat-5.3", license = "MIT" } dependencies = { diff --git a/vendor/compat53/rockspecs/compat53-scm-0.rockspec b/vendor/compat53/rockspecs/compat53-0.11-1.rockspec similarity index 78% rename from vendor/compat53/rockspecs/compat53-scm-0.rockspec rename to vendor/compat53/rockspecs/compat53-0.11-1.rockspec index a83dfca..9608f0a 100644 --- a/vendor/compat53/rockspecs/compat53-scm-0.rockspec +++ b/vendor/compat53/rockspecs/compat53-0.11-1.rockspec @@ -1,8 +1,8 @@ package = "compat53" -version = "scm-0" +version = "0.11-1" source = { - url = "https://github.com/keplerproject/lua-compat-5.3/archive/master.zip", - dir = "lua-compat-5.3-master", + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.11.zip", + dir = "lua-compat-5.3-0.11", } description = { summary = "Compatibility module providing Lua-5.3-style APIs for Lua 5.2 and 5.1", @@ -12,7 +12,7 @@ description = { 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", + homepage = "https://github.com/lunarmodules/lua-compat-5.3", license = "MIT" } dependencies = { @@ -27,6 +27,7 @@ build = { ["compat53.utf8"] = "lutf8lib.c", ["compat53.table"] = "ltablib.c", ["compat53.string"] = "lstrlib.c", + ["compat53.io"] = "liolib.c", } } diff --git a/vendor/compat53/rockspecs/compat53-0.12-1.rockspec b/vendor/compat53/rockspecs/compat53-0.12-1.rockspec new file mode 100644 index 0000000..1b120ca --- /dev/null +++ b/vendor/compat53/rockspecs/compat53-0.12-1.rockspec @@ -0,0 +1,33 @@ +package = "compat53" +version = "0.12-1" +source = { + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.12.zip", + dir = "lua-compat-5.3-0.12", +} +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/lunarmodules/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", + ["compat53.io"] = "liolib.c", + } +} + diff --git a/vendor/compat53/rockspecs/compat53-0.13-1.rockspec b/vendor/compat53/rockspecs/compat53-0.13-1.rockspec new file mode 100644 index 0000000..f08dc66 --- /dev/null +++ b/vendor/compat53/rockspecs/compat53-0.13-1.rockspec @@ -0,0 +1,32 @@ +package = "compat53" +version = "0.13-1" +source = { + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.13.zip", + dir = "lua-compat-5.3-0.13" +} +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/lunarmodules/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.io"] = "liolib.c", + ["compat53.module"] = "compat53/module.lua", + ["compat53.string"] = "lstrlib.c", + ["compat53.table"] = "ltablib.c", + ["compat53.utf8"] = "lutf8lib.c" + } +} diff --git a/vendor/compat53/rockspecs/compat53-0.14-1.rockspec b/vendor/compat53/rockspecs/compat53-0.14-1.rockspec new file mode 100644 index 0000000..54ad4a9 --- /dev/null +++ b/vendor/compat53/rockspecs/compat53-0.14-1.rockspec @@ -0,0 +1,33 @@ +package = "compat53" +version = "0.14-1" +source = { + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.14.zip", + dir = "lua-compat-5.3-0.14" +} +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/lunarmodules/lua-compat-5.3", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.5" + --"struct" -- make Roberto's struct module optional +} +build = { + type = "builtin", + modules = { + ["compat53.file_mt"] = "compat53/file_mt.lua", + ["compat53.init"] = "compat53/init.lua", + ["compat53.io"] = "liolib.c", + ["compat53.module"] = "compat53/module.lua", + ["compat53.string"] = "lstrlib.c", + ["compat53.table"] = "ltablib.c", + ["compat53.utf8"] = "lutf8lib.c" + } +} diff --git a/vendor/compat53/rockspecs/compat53-0.14.1-1.rockspec b/vendor/compat53/rockspecs/compat53-0.14.1-1.rockspec new file mode 100644 index 0000000..ea35bb2 --- /dev/null +++ b/vendor/compat53/rockspecs/compat53-0.14.1-1.rockspec @@ -0,0 +1,33 @@ +package = "compat53" +version = "0.14.1-1" +source = { + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.14.1.zip", + dir = "lua-compat-5.3-0.14.1" +} +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/lunarmodules/lua-compat-5.3", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.5" + --"struct" -- make Roberto's struct module optional +} +build = { + type = "builtin", + modules = { + ["compat53.file_mt"] = "compat53/file_mt.lua", + ["compat53.init"] = "compat53/init.lua", + ["compat53.io"] = "liolib.c", + ["compat53.module"] = "compat53/module.lua", + ["compat53.string"] = "lstrlib.c", + ["compat53.table"] = "ltablib.c", + ["compat53.utf8"] = "lutf8lib.c" + } +} diff --git a/vendor/compat53/rockspecs/compat53-0.14.2-1.rockspec b/vendor/compat53/rockspecs/compat53-0.14.2-1.rockspec new file mode 100644 index 0000000..99236fe --- /dev/null +++ b/vendor/compat53/rockspecs/compat53-0.14.2-1.rockspec @@ -0,0 +1,32 @@ +package = "compat53" +version = "0.14.2-1" +source = { + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.14.2.zip", + dir = "lua-compat-5.3-0.14.2" +} +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/lunarmodules/lua-compat-5.3", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.5" +} +build = { + type = "builtin", + modules = { + ["compat53.file_mt"] = "compat53/file_mt.lua", + ["compat53.init"] = "compat53/init.lua", + ["compat53.io"] = "liolib.c", + ["compat53.module"] = "compat53/module.lua", + ["compat53.string"] = "lstrlib.c", + ["compat53.table"] = "ltablib.c", + ["compat53.utf8"] = "lutf8lib.c" + } +} diff --git a/vendor/compat53/rockspecs/compat53-0.14.3-1.rockspec b/vendor/compat53/rockspecs/compat53-0.14.3-1.rockspec new file mode 100644 index 0000000..d6327d7 --- /dev/null +++ b/vendor/compat53/rockspecs/compat53-0.14.3-1.rockspec @@ -0,0 +1,32 @@ +package = "compat53" +version = "0.14.3-1" +source = { + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.14.3.zip", + dir = "lua-compat-5.3-0.14.3" +} +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/lunarmodules/lua-compat-5.3", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.5" +} +build = { + type = "builtin", + modules = { + ["compat53.file_mt"] = "compat53/file_mt.lua", + ["compat53.init"] = "compat53/init.lua", + ["compat53.io"] = "liolib.c", + ["compat53.module"] = "compat53/module.lua", + ["compat53.string"] = "lstrlib.c", + ["compat53.table"] = "ltablib.c", + ["compat53.utf8"] = "lutf8lib.c" + } +} diff --git a/vendor/compat53/rockspecs/compat53-0.14.4-1.rockspec b/vendor/compat53/rockspecs/compat53-0.14.4-1.rockspec new file mode 100644 index 0000000..804220f --- /dev/null +++ b/vendor/compat53/rockspecs/compat53-0.14.4-1.rockspec @@ -0,0 +1,32 @@ +package = "compat53" +version = "0.14.4-1" +source = { + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.14.4.zip", + dir = "lua-compat-5.3-0.14.4" +} +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/lunarmodules/lua-compat-5.3", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.5" +} +build = { + type = "builtin", + modules = { + ["compat53.file_mt"] = "compat53/file_mt.lua", + ["compat53.init"] = "compat53/init.lua", + ["compat53.io"] = "liolib.c", + ["compat53.module"] = "compat53/module.lua", + ["compat53.string"] = "lstrlib.c", + ["compat53.table"] = "ltablib.c", + ["compat53.utf8"] = "lutf8lib.c" + } +} diff --git a/vendor/compat53/rockspecs/compat53-0.15.0-1.rockspec b/vendor/compat53/rockspecs/compat53-0.15.0-1.rockspec new file mode 100644 index 0000000..6215cd6 --- /dev/null +++ b/vendor/compat53/rockspecs/compat53-0.15.0-1.rockspec @@ -0,0 +1,32 @@ +package = "compat53" +version = "0.15.0-1" +source = { + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.15.0.zip", + dir = "lua-compat-5.3-0.15.0" +} +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/lunarmodules/lua-compat-5.3", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.6" +} +build = { + type = "builtin", + modules = { + ["compat53.file_mt"] = "compat53/file_mt.lua", + ["compat53.init"] = "compat53/init.lua", + ["compat53.io"] = "liolib.c", + ["compat53.module"] = "compat53/module.lua", + ["compat53.string"] = "lstrlib.c", + ["compat53.table"] = "ltablib.c", + ["compat53.utf8"] = "lutf8lib.c" + } +} diff --git a/vendor/compat53/rockspecs/compat53-0.15.1-1.rockspec b/vendor/compat53/rockspecs/compat53-0.15.1-1.rockspec new file mode 100644 index 0000000..0a7d7cc --- /dev/null +++ b/vendor/compat53/rockspecs/compat53-0.15.1-1.rockspec @@ -0,0 +1,32 @@ +package = "compat53" +version = "0.15.1-1" +source = { + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.15.1.zip", + dir = "lua-compat-5.3-0.15.1" +} +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/lunarmodules/lua-compat-5.3", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.6" +} +build = { + type = "builtin", + modules = { + ["compat53.file_mt"] = "compat53/file_mt.lua", + ["compat53.init"] = "compat53/init.lua", + ["compat53.io"] = "liolib.c", + ["compat53.module"] = "compat53/module.lua", + ["compat53.string"] = "lstrlib.c", + ["compat53.table"] = "ltablib.c", + ["compat53.utf8"] = "lutf8lib.c" + } +} diff --git a/vendor/compat53/rockspecs/compat53-0.2-1.rockspec b/vendor/compat53/rockspecs/compat53-0.2-1.rockspec index 1b3c80e..47ddaf2 100644 --- a/vendor/compat53/rockspecs/compat53-0.2-1.rockspec +++ b/vendor/compat53/rockspecs/compat53-0.2-1.rockspec @@ -1,7 +1,7 @@ package = "compat53" version = "0.2-1" source = { - url = "https://github.com/keplerproject/lua-compat-5.3/archive/v0.2.zip", + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.2.zip", dir = "lua-compat-5.3-0.2", } description = { @@ -12,7 +12,7 @@ description = { 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", + homepage = "https://github.com/lunarmodules/lua-compat-5.3", license = "MIT" } dependencies = { diff --git a/vendor/compat53/rockspecs/compat53-0.3-1.rockspec b/vendor/compat53/rockspecs/compat53-0.3-1.rockspec index 43f53d2..d99099f 100644 --- a/vendor/compat53/rockspecs/compat53-0.3-1.rockspec +++ b/vendor/compat53/rockspecs/compat53-0.3-1.rockspec @@ -1,7 +1,7 @@ package = "compat53" version = "0.3-1" source = { - url = "https://github.com/keplerproject/lua-compat-5.3/archive/v0.3.zip", + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.3.zip", dir = "lua-compat-5.3-0.3", } description = { @@ -12,7 +12,7 @@ description = { 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", + homepage = "https://github.com/lunarmodules/lua-compat-5.3", license = "MIT" } dependencies = { diff --git a/vendor/compat53/rockspecs/compat53-0.4-1.rockspec b/vendor/compat53/rockspecs/compat53-0.4-1.rockspec index 9331e19..bc33826 100644 --- a/vendor/compat53/rockspecs/compat53-0.4-1.rockspec +++ b/vendor/compat53/rockspecs/compat53-0.4-1.rockspec @@ -1,7 +1,7 @@ package = "compat53" version = "0.4-1" source = { - url = "https://github.com/keplerproject/lua-compat-5.3/archive/v0.4.zip", + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.4.zip", dir = "lua-compat-5.3-0.4", } description = { @@ -12,7 +12,7 @@ description = { 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", + homepage = "https://github.com/lunarmodules/lua-compat-5.3", license = "MIT" } dependencies = { diff --git a/vendor/compat53/rockspecs/compat53-0.5-1.rockspec b/vendor/compat53/rockspecs/compat53-0.5-1.rockspec index 3cceccd..8d18b51 100644 --- a/vendor/compat53/rockspecs/compat53-0.5-1.rockspec +++ b/vendor/compat53/rockspecs/compat53-0.5-1.rockspec @@ -1,7 +1,7 @@ package = "compat53" version = "0.5-1" source = { - url = "https://github.com/keplerproject/lua-compat-5.3/archive/v0.5.zip", + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.5.zip", dir = "lua-compat-5.3-0.5", } description = { @@ -12,7 +12,7 @@ description = { 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", + homepage = "https://github.com/lunarmodules/lua-compat-5.3", license = "MIT" } dependencies = { diff --git a/vendor/compat53/rockspecs/compat53-0.7-1.rockspec b/vendor/compat53/rockspecs/compat53-0.7-1.rockspec index 844a3c6..fc5a0c8 100644 --- a/vendor/compat53/rockspecs/compat53-0.7-1.rockspec +++ b/vendor/compat53/rockspecs/compat53-0.7-1.rockspec @@ -1,7 +1,7 @@ package = "compat53" version = "0.7-1" source = { - url = "https://github.com/keplerproject/lua-compat-5.3/archive/v0.7.zip", + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.7.zip", dir = "lua-compat-5.3-0.7", } description = { @@ -12,7 +12,7 @@ description = { 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", + homepage = "https://github.com/lunarmodules/lua-compat-5.3", license = "MIT" } dependencies = { diff --git a/vendor/compat53/rockspecs/compat53-0.8-1.rockspec b/vendor/compat53/rockspecs/compat53-0.8-1.rockspec index 0ab17a0..2fe47b9 100644 --- a/vendor/compat53/rockspecs/compat53-0.8-1.rockspec +++ b/vendor/compat53/rockspecs/compat53-0.8-1.rockspec @@ -1,7 +1,7 @@ package = "compat53" version = "0.8-1" source = { - url = "https://github.com/keplerproject/lua-compat-5.3/archive/v0.8.zip", + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.8.zip", dir = "lua-compat-5.3-0.8", } description = { @@ -12,7 +12,7 @@ description = { 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", + homepage = "https://github.com/lunarmodules/lua-compat-5.3", license = "MIT" } dependencies = { diff --git a/vendor/compat53/rockspecs/compat53-scm-1.rockspec b/vendor/compat53/rockspecs/compat53-scm-1.rockspec new file mode 100644 index 0000000..b72eff6 --- /dev/null +++ b/vendor/compat53/rockspecs/compat53-scm-1.rockspec @@ -0,0 +1,34 @@ +package = "compat53" +version = "scm-1" +source = { + url = "https://github.com/lunarmodules/lua-compat-5.3/archive/master.zip", + dir = "lua-compat-5.3-master", +} +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/lunarmodules/lua-compat-5.3", + license = "MIT" +} +dependencies = { + "lua >= 5.1, < 5.6", + --"struct" -- make Roberto's struct module optional +} +build = { + type = "builtin", + modules = { + ["compat53.init"] = "compat53/init.lua", + ["compat53.module"] = "compat53/module.lua", + ["compat53.file_mt"] = "compat53/file_mt.lua", + ["compat53.utf8"] = "lutf8lib.c", + ["compat53.table"] = "ltablib.c", + ["compat53.string"] = "lstrlib.c", + ["compat53.io"] = "liolib.c", + } +} + diff --git a/vendor/compat53/tests/test-bit32.lua b/vendor/compat53/tests/test-bit32.lua index cc91e52..a408b7d 100755 --- a/vendor/compat53/tests/test-bit32.lua +++ b/vendor/compat53/tests/test-bit32.lua @@ -4,6 +4,7 @@ local bit32 = require("bit32") assert(bit32.bnot(0) == 2^32-1) +assert(bit32.bnot(-1) == 0) 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 0640cae..503e3f4 100755 --- a/vendor/compat53/tests/test.lua +++ b/vendor/compat53/tests/test.lua @@ -36,6 +36,8 @@ end local V = _VERSION:gsub("^.*(%d+)%.(%d+)$", "%1%2") if jit then V = "jit" end +local is_puclua51 = (_VERSION == "Lua 5.1" and not jit) + local mode = "global" if arg[1] == "module" then mode = "module" @@ -228,6 +230,7 @@ print("math.mininteger", math.mininteger-1 < math.mininteger) ___'' print("math.tointeger", math.tointeger(0)) print("math.tointeger", math.tointeger(math.pi)) +print("math.tointeger", math.tointeger("123")) print("math.tointeger", math.tointeger("hello")) print("math.tointeger", math.tointeger(math.maxinteger+2.0)) print("math.tointeger", math.tointeger(math.mininteger*2.0)) @@ -575,7 +578,7 @@ ___'' do print("io.write()", io.type(io.write("hello world\n"))) local f = assert(io.tmpfile()) - print("file:write()", io.type(f:write("hello world\n"))) + print("io.tmpfile => file:write()", io.type(f:write("hello world\n"))) f:close() end @@ -588,13 +591,18 @@ do io.input("data.txt") print("io.read()", io.read("n", "number", "l", "a")) io.input(io.stdin) - if mode ~= "module" then - local f = assert(io.open("data.txt", "r")) - print("file:read()", f:read("*n", "*number", "*l", "*a")) - f:close() - f = assert(io.open("data.txt", "r")) - print("file:read()", f:read("n", "number", "l", "a")) - f:close() + if not is_puclua51 then + local f = assert(io.open("data.txt", "r")) + print("file:read()", f:read("*n", "*number", "*l", "*a")) + f:close() + f = assert(io.open("data.txt", "r")) + print("file:read()", f:read("n", "number", "l", "a")) + f:close() + os.remove("data.txt") + + local g = assert(io.open("data.txt", "w")) + print("io.open => file:write()", type(g:write("hello"))) + g:close() end os.remove("data.txt") end @@ -625,11 +633,13 @@ do end)) if mode ~= "module" then local f = assert(io.open(self, "r")) + print("io.type()", io.type(f)) for a,b in f:lines(2, "*l") do print("file:lines()", a, b) break end f:close() + print("io.type()", io.type(f)) f = assert(io.open("data.txt", "r")) for n1,n2,rest in f:lines("*n", "n", "*a") do print("file:lines()", n1, n2, rest) @@ -650,6 +660,18 @@ do end)) end os.remove("data.txt") + print("io.popen()", pcall(function() + local f = assert(io.popen("echo 'hello' && exit 0", "r")) + print("io.popen()", f:read("*a")) + print("io.popen()", f:close()) + end)) + print("io.popen()", pcall(function() + local f = assert(io.popen("echo 'hello' && exit 5", "r")) + print("io.type()", io.type(f)) + print("io.popen()", f:read("*a")) + print("io.popen()", f:close()) + print("io.type()", io.type(f)) + end)) end ___''