From 82f9f27172345cf8f5da12bfedda6ea6171c3fe5 Mon Sep 17 00:00:00 2001 From: Daniel Poelzleithner Date: Tue, 7 Jun 2022 21:28:18 +0200 Subject: [PATCH] Add proper compatibilty wrappers for 5.1 --- lsyncd.lua | 17 +++++++++++++++-- tests/churn-direct.lua | 2 +- tests/churn-rsync.lua | 2 +- tests/churn-rsyncssh.lua | 2 +- tests/exclude-rsync.lua | 2 +- tests/exclude-rsyncssh.lua | 2 +- tests/filter-rsync.lua | 2 +- tests/l4rsyncdata.lua | 2 +- tests/testlib.lua | 22 ++++++++++++++++++++++ 9 files changed, 44 insertions(+), 9 deletions(-) diff --git a/lsyncd.lua b/lsyncd.lua index a3828ee..d854cbd 100644 --- a/lsyncd.lua +++ b/lsyncd.lua @@ -27,6 +27,15 @@ end lsyncd_version = '2.3.0-beta1' +-- compatibility with 5.1 +if table.unpack == nil then + table.unpack = unpack +end + +local lver = string.gmatch(_VERSION, "%w (%d).(%d)") +local _LUA_VERSION_MAJOR, _LUA_VERSION_MINOR = lver() +_LUA_VERSION_MAJOR = tonumber(_LUA_VERSION_MAJOR) +_LUA_VERSION_MINOR = tonumber(_LUA_VERSION_MINOR) -- -- Shortcuts (which user is supposed to be able to use them as well) @@ -6043,8 +6052,12 @@ function runner.initialize( firstTime ) if type(config[fn]) == 'string' then local ft = functionWriter.translate( config[ fn ] ) - - config[ fn ] = assert( load( 'return '..ft ) )( ) + if _LUA_VERSION_MAJOR <= 5 and _LUA_VERSION_MINOR < 2 then + -- lua 5.1 and older + config[ fn ] = assert( loadstring( 'return '..ft ) )( ) + else + config[ fn ] = assert( load( 'return '..ft ) )( ) + end end end end diff --git a/tests/churn-direct.lua b/tests/churn-direct.lua index 8826b88..a37adea 100644 --- a/tests/churn-direct.lua +++ b/tests/churn-direct.lua @@ -37,7 +37,7 @@ posix.kill( pid ) local _, exitmsg, lexitcode = posix.wait( lpid ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) -_, result, code = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) +result, code = execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) if result == 'exit' then diff --git a/tests/churn-rsync.lua b/tests/churn-rsync.lua index e72b090..3446be2 100644 --- a/tests/churn-rsync.lua +++ b/tests/churn-rsync.lua @@ -39,7 +39,7 @@ posix.kill( pid ) local _, exitmsg, lexitcode = posix.wait( lpid ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) -_, result, code = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) +result, code = execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) if result == 'exit' then diff --git a/tests/churn-rsyncssh.lua b/tests/churn-rsyncssh.lua index 581bf26..9162edd 100644 --- a/tests/churn-rsyncssh.lua +++ b/tests/churn-rsyncssh.lua @@ -47,7 +47,7 @@ local _, exitmsg, lexitcode = posix.wait( lpid ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) -_, result, code = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) +result, code = execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) if result == 'exit' then diff --git a/tests/exclude-rsync.lua b/tests/exclude-rsync.lua index aac6eed..c1d5296 100644 --- a/tests/exclude-rsync.lua +++ b/tests/exclude-rsync.lua @@ -115,7 +115,7 @@ cwriteln( 'waiting for Lsyncd to remove destination' ) posix.sleep( 5 ) -_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) +result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) if result ~= 'exit' or code ~= 0 then diff --git a/tests/exclude-rsyncssh.lua b/tests/exclude-rsyncssh.lua index b5efcbc..483505b 100644 --- a/tests/exclude-rsyncssh.lua +++ b/tests/exclude-rsyncssh.lua @@ -113,7 +113,7 @@ os.execute( 'rm -rf ' .. srcdir .. '/*' ) cwriteln( 'waiting for Lsyncd to remove destination' ) posix.sleep( 5 ) -_, result, code = os.execute( 'diff -urN '..srcdir..' '..trgdir ) +result, code = execute( 'diff -urN '..srcdir..' '..trgdir ) if result ~= 'exit' or code ~= 0 then diff --git a/tests/filter-rsync.lua b/tests/filter-rsync.lua index 5246519..5a5a7b2 100644 --- a/tests/filter-rsync.lua +++ b/tests/filter-rsync.lua @@ -109,7 +109,7 @@ cwriteln( 'waiting for Lsyncd to remove destination' ) posix.sleep( 5 ) -_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) +result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) if result ~= 'exit' or code ~= 0 then diff --git a/tests/l4rsyncdata.lua b/tests/l4rsyncdata.lua index f114c89..10820a4 100644 --- a/tests/l4rsyncdata.lua +++ b/tests/l4rsyncdata.lua @@ -60,7 +60,7 @@ cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode) posix.sleep( 1 ) cwriteln( '* differences:' ) -_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) +result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) if result == 'exit' then diff --git a/tests/testlib.lua b/tests/testlib.lua index 5a5ba69..25cf1ca 100644 --- a/tests/testlib.lua +++ b/tests/testlib.lua @@ -9,6 +9,11 @@ local c1='\027[47;34m' local c0='\027[0m' +-- compatibility with 5.1 +if table.unpack == nil then + table.unpack = unpack +end + -- -- Writes colorized. -- @@ -18,6 +23,23 @@ function cwriteln io.write( c0, '\n' ) end +local lver = string.gmatch(_VERSION, "Lua (%d).(%d)") +_LUA_VERSION_MAJOR, _LUA_VERSION_MINOR = lver() +_LUA_VERSION_MAJOR = tonumber(_LUA_VERSION_MAJOR) +_LUA_VERSION_MINOR = tonumber(_LUA_VERSION_MINOR) + +-- Compatibility execute function +function execute(...) + if _LUA_VERSION_MAJOR <= 5 and + _LUA_VERSION_MINOR < 2 then + local rv = os.execute(...) + return "exit", rv + else + local ok, why, code = os.execute(...) + return why, code + end +end + -- -- Initializes the pseudo random generator --