Skip to content

Commit cc1960c

Browse files
authored
Merge pull request #788 from squeek502/lua5.5
Add support for and test against Lua 5.5
2 parents 4dc68f3 + 9fb2b3f commit cc1960c

File tree

11 files changed

+91
-47
lines changed

11 files changed

+91
-47
lines changed

.ci/setup_lua.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ else
7070
elif [ "$LUA" == "lua5.4" ]; then
7171
curl --silent https://www.lua.org/ftp/lua-5.4.4.tar.gz | tar xz
7272
cd lua-5.4.4;
73+
elif [ "$LUA" == "lua5.5" ]; then
74+
curl --silent https://www.lua.org/ftp/lua-5.5.0.tar.gz | tar xz
75+
cd lua-5.5.0;
7376
fi
7477

7578
# Build Lua without backwards compatibility for testing
@@ -132,4 +135,6 @@ elif [ "$LUA" == "lua5.3" ]; then
132135
rm -rf lua-5.3.6;
133136
elif [ "$LUA" == "lua5.4" ]; then
134137
rm -rf lua-5.4.4;
138+
elif [ "$LUA" == "lua5.5" ]; then
139+
rm -rf lua-5.5.0;
135140
fi

.ci/winmake.bat

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,33 +154,56 @@ IF NOT EXIST %LUA_H% (
154154
goto :EXITERROR
155155
)
156156

157-
findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MAJOR" %LUA_H% > NUL
158-
if NOT %ERRORLEVEL%==0 (
159-
rem ECHO We've got a Lua version 5.1
160-
rem findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION[ %TABCHAR%]" %LUA_H%
161-
SET LUA_VER=5.1
162-
) else (
163-
rem ECHO We've got a Lua version 5.2+
164-
rem findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MAJOR[ %TABCHAR%]" %LUA_H%
165-
rem findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MINOR[ %TABCHAR%]" %LUA_H%
157+
findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MAJOR_N" %LUA_H% > NUL
158+
if %ERRORLEVEL%==0 (
159+
rem ECHO We've got a Lua version 5.5+
160+
rem findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MAJOR_N[ %TABCHAR%]" %LUA_H%
161+
rem findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MINOR_N[ %TABCHAR%]" %LUA_H%
166162

167-
for /F "delims=" %%a in ('findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MAJOR[ %TABCHAR%]" %LUA_H%') do set LUA_MAJOR=%%a
163+
for /F "delims=" %%a in ('findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MAJOR_N[ %TABCHAR%]" %LUA_H%') do set LUA_MAJOR=%%a
168164
SET LUA_MAJOR=!LUA_MAJOR:#define=!
169-
SET LUA_MAJOR=!LUA_MAJOR:LUA_VERSION_MAJOR=!
165+
SET LUA_MAJOR=!LUA_MAJOR:LUA_VERSION_MAJOR_N=!
170166
SET LUA_MAJOR=!LUA_MAJOR: =!
171167
SET LUA_MAJOR=!LUA_MAJOR:%TABCHAR%=!
172-
SET LUA_MAJOR=!LUA_MAJOR:"=!
173168
SET LUA_MAJOR=!LUA_MAJOR:~0,1!
174169

175-
for /F "delims=" %%a in ('findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MINOR[ %TABCHAR%]" %LUA_H%') do set LUA_MINOR=%%a
170+
for /F "delims=" %%a in ('findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MINOR_N[ %TABCHAR%]" %LUA_H%') do set LUA_MINOR=%%a
176171
SET LUA_MINOR=!LUA_MINOR:#define=!
177-
SET LUA_MINOR=!LUA_MINOR:LUA_VERSION_MINOR=!
172+
SET LUA_MINOR=!LUA_MINOR:LUA_VERSION_MINOR_N=!
178173
SET LUA_MINOR=!LUA_MINOR: =!
179174
SET LUA_MINOR=!LUA_MINOR:%TABCHAR%=!
180-
SET LUA_MINOR=!LUA_MINOR:"=!
181175
SET LUA_MINOR=!LUA_MINOR:~0,1!
182176

183177
SET LUA_VER=!LUA_MAJOR!.!LUA_MINOR!
178+
) else (
179+
findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MAJOR" %LUA_H% > NUL
180+
if NOT %ERRORLEVEL%==0 (
181+
rem ECHO We've got a Lua version 5.1
182+
rem findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION[ %TABCHAR%]" %LUA_H%
183+
SET LUA_VER=5.1
184+
) else (
185+
rem ECHO We've got a Lua version 5.2+
186+
rem findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MAJOR[ %TABCHAR%]" %LUA_H%
187+
rem findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MINOR[ %TABCHAR%]" %LUA_H%
188+
189+
for /F "delims=" %%a in ('findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MAJOR[ %TABCHAR%]" %LUA_H%') do set LUA_MAJOR=%%a
190+
SET LUA_MAJOR=!LUA_MAJOR:#define=!
191+
SET LUA_MAJOR=!LUA_MAJOR:LUA_VERSION_MAJOR=!
192+
SET LUA_MAJOR=!LUA_MAJOR: =!
193+
SET LUA_MAJOR=!LUA_MAJOR:%TABCHAR%=!
194+
SET LUA_MAJOR=!LUA_MAJOR:"=!
195+
SET LUA_MAJOR=!LUA_MAJOR:~0,1!
196+
197+
for /F "delims=" %%a in ('findstr /R /C:"#define[ %TABCHAR%][ %TABCHAR%]*LUA_VERSION_MINOR[ %TABCHAR%]" %LUA_H%') do set LUA_MINOR=%%a
198+
SET LUA_MINOR=!LUA_MINOR:#define=!
199+
SET LUA_MINOR=!LUA_MINOR:LUA_VERSION_MINOR=!
200+
SET LUA_MINOR=!LUA_MINOR: =!
201+
SET LUA_MINOR=!LUA_MINOR:%TABCHAR%=!
202+
SET LUA_MINOR=!LUA_MINOR:"=!
203+
SET LUA_MINOR=!LUA_MINOR:~0,1!
204+
205+
SET LUA_VER=!LUA_MAJOR!.!LUA_MINOR!
206+
)
184207
)
185208
SET LUA_SVER=!LUA_VER:.=!
186209

@@ -233,6 +256,16 @@ if %LUA_SVER%==54 (
233256
set COMPATFLAG=-DLUA_COMPAT_5_3
234257
)
235258
)
259+
if %LUA_SVER%==55 (
260+
set FILES_CORE=lapi lcode lctype ldebug ldo ldump lfunc lgc llex lmem lobject lopcodes lparser lstate lstring ltable ltm lundump lvm lzio lauxlib
261+
set FILES_LIB=lbaselib ldblib liolib lmathlib loslib ltablib lstrlib lutf8lib loadlib lcorolib linit
262+
set FILES_DLL=lua
263+
set FILES_OTH=luac
264+
set INSTALL_H=lauxlib.h lua.h lua.hpp luaconf.h lualib.h
265+
if "%COMPATFLAG%"=="" (
266+
set COMPATFLAG=-DLUA_COMPAT_5_3
267+
)
268+
)
236269

237270
if "%NOCOMPAT%"=="TRUE" (
238271
set COMPATFLAG=

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ jobs:
119119
strategy:
120120
matrix:
121121
os: [macos-latest, ubuntu-latest]
122-
luarocks_version: [3.8.0]
122+
luarocks_version: [3.13.0]
123123
lua_engine: [Lua, LuaJIT]
124124
include:
125125
- lua_engine: LuaJIT
126126
lua_version: luajit2.1
127127
- lua_engine: Lua
128-
lua_version: lua5.4
128+
lua_version: lua5.5
129129
env:
130130
# For LuaJIT 2.1, see https://github.com/LuaJIT/LuaJIT/commit/8961a92dd1607108760694af3486b4434602f8be
131131
MACOSX_DEPLOYMENT_TARGET: 10.12
@@ -172,7 +172,7 @@ jobs:
172172
env:
173173
WITH_LUA_ENGINE: LuaJIT
174174
LUA: luajit2.1
175-
LUAROCKS: 3.8.0
175+
LUAROCKS: 3.13.0
176176
steps:
177177
- uses: actions/checkout@v2
178178
with:

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ if (LUA)
101101
NO_DEFAULT_PATH)
102102
ELSEIF(LUA_EXEC_NAME MATCHES "lua.*")
103103
FIND_LIBRARY(LUA_LIBRARIES
104-
NAMES lua lua54 lua53 lua52 lua51 liblua liblua54 liblua53 liblua52 liblua51
104+
NAMES lua lua55 lua54 lua53 lua52 lua51 liblua liblua55 liblua54 liblua53 liblua52 liblua51
105105
PATHS ${LUA_LIBDIR}
106106
NO_DEFAULT_PATH)
107107
ENDIF()

appveyor.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ environment:
1010
- FROM_DEPS: true
1111

1212
# LuaRocks 3.x
13-
- LUA_VER: 5.4.4
13+
- LUA_VER: 5.5.0
1414
NOCOMPAT: true # with compatibility flags disabled.
15-
LUAROCKS_VER: 3.8.0
15+
LUAROCKS_VER: 3.13.0
1616
- LJ_VER: 2.1
17-
LUAROCKS_VER: 3.8.0
17+
LUAROCKS_VER: 3.13.0
1818

1919
matrix:
2020
fast_finish: true
2121
exclude:
2222
# Skip x86 for LuaRocks tests
2323
- platform: x86
24-
LUAROCKS_VER: 3.8.0
24+
LUAROCKS_VER: 3.13.0
2525

2626
cache:
2727
- c:\lua -> appveyor.yml

deps/lua

Submodule lua updated 102 files

deps/lua.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Redistribution and use of this file is allowed according to the terms of the MIT license.
77
# Debugged and (now seriously) modified by Ronan Collobert, for Torch7
88

9-
#project(Lua54 C)
9+
#project(Lua55 C)
1010

1111
SET(LUA_DIR ${CMAKE_CURRENT_LIST_DIR}/lua CACHE PATH "location of lua sources")
1212

@@ -112,7 +112,7 @@ set_target_properties(lualib PROPERTIES
112112
COMPILE_DEFINITIONS MAKE_LIB=1)
113113

114114
target_link_libraries (lualib ${LIBS} )
115-
set_target_properties (lualib PROPERTIES OUTPUT_NAME "lua54")
115+
set_target_properties (lualib PROPERTIES OUTPUT_NAME "lua55")
116116

117117
add_executable(lua ${LUA_DIR}/lua.c)
118118
IF(WIN32)

luv-scm-0.rockspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ rockspec_format = "3.0"
88
description = {
99
summary = "Bare libuv bindings for lua",
1010
detailed = [[
11-
libuv bindings for luajit and lua 5.1/5.2/5.3/5.4.
11+
libuv bindings for luajit and lua 5.1/5.2/5.3/5.4/5.5.
1212
1313
This library makes libuv available to lua scripts. It was made for the luvit
1414
project but should usable from nearly any lua project.

src/thread.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ static int thread_dump (lua_State *L, const void *b, size_t size, void *ud) {
251251
state->init = 1;
252252
luaL_buffinit(L, &state->B);
253253
}
254+
// Starting with Lua 5.5.0, lua_dump calls this function with b == NULL to signal
255+
// the end of the dump. We don't have to worry about that, though, because size will
256+
// also be zero in that case and luaL_addlstring is a no-op when size is zero.
254257
luaL_addlstring(&state->B, (const char *)b, size);
255258
return 0;
256259
}
@@ -261,25 +264,34 @@ static int luv_thread_dumped(lua_State* L, int idx) {
261264
} else {
262265
int ret, top;
263266
struct luv_thread_Writer state;
264-
top = lua_gettop(L);
265267
state.init = 0;
266268

269+
// The goal is to return from this function with the only change to the stack
270+
// being the dumped thread pushed onto the top.
271+
//
272+
// Different Lua versions have different behaviors around how lua_dump and
273+
// luaL_Buffer handle the stack, so the approach used here avoids the need to deal
274+
// with those discrepencies.
275+
//
276+
// The idea is:
277+
// - Push `nil` onto the stack as a placeholder for the resulting dumped string
278+
// - Call lua_dump and let it and luaL_pushresult push/pop from the stack however
279+
// they wish (we know they will never touch our placeholder).
280+
// - Move the result of luaL_pushresult to our placeholder's index and set it as
281+
// the top before returning
282+
lua_pushnil(L);
283+
top = lua_gettop(L);
284+
267285
// lua_dump needs the function at the top of the stack
268286
luaL_checktype(L, idx, LUA_TFUNCTION);
269287
lua_pushvalue(L, idx);
270288
ret = lua_dump(L, thread_dump, &state, 1);
271289
if (ret==0) {
272290
luaL_pushresult(&state.B);
273-
// The goal is to return from this function with the only change to the stack
274-
// being the dumped thread pushed onto the top. In Lua >= 5.4.3, this is a bit
275-
// tricky because luaL_Buffer pushes its buffer onto the stack and relies on
276-
// that stack value's lifetime for its memory. This means that we can't safely
277-
// pop that value off the stack until after we have fully dumped the function
278-
// and pushed the result. After we push the result (luaL_pushresult), we want
279-
// to get rid of any intermediate values and put the result at the new top of
280-
// the stack, 1 after the top that we entered with. That's what's happening here:
281-
lua_replace(L, top + 1);
282-
lua_settop(L, top + 1);
291+
// Move the result to our placeholder index and pop off whatever remains from
292+
// the lua_dump call.
293+
lua_replace(L, top);
294+
lua_settop(L, top);
283295
} else
284296
luaL_error(L, "Error: unable to dump given function");
285297
}

tests/test-async.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ return require('lib/tap')(function (test)
1111
assert(c==250)
1212
uv.close(async)
1313
end))
14-
local args = {500, 'string', nil, false, 5, "helloworld",async}
15-
local unpack = unpack or table.unpack
1614
uv.new_thread(function(num,s,null,bool,five,hw,asy)
1715
local uv = require'luv'
1816
assert(type(num) == "number")
@@ -24,7 +22,7 @@ return require('lib/tap')(function (test)
2422
assert(type(asy)=='userdata')
2523
assert(uv.async_send(asy,'a',true,250)==0)
2624
uv.sleep(1000)
27-
end, unpack(args)):join()
25+
end, 500, 'string', nil, false, 5, "helloworld",async):join()
2826
local elapsed = (os.time() - before) * 1000
2927
assert(elapsed >= 1000, "elapsed should be at least delay ")
3028
end)

0 commit comments

Comments
 (0)