Add proper compatibilty wrappers for 5.1

This commit is contained in:
Daniel Poelzleithner 2022-06-07 21:28:18 +02:00
parent 63f506582a
commit 82f9f27172
9 changed files with 44 additions and 9 deletions

View File

@ -27,6 +27,15 @@ end
lsyncd_version = '2.3.0-beta1' 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) -- Shortcuts (which user is supposed to be able to use them as well)
@ -6043,11 +6052,15 @@ function runner.initialize( firstTime )
if type(config[fn]) == 'string' if type(config[fn]) == 'string'
then then
local ft = functionWriter.translate( config[ fn ] ) local ft = functionWriter.translate( config[ fn ] )
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 ) )( ) config[ fn ] = assert( load( 'return '..ft ) )( )
end end
end end
end end
end
-- runs through the Syncs created by users -- runs through the Syncs created by users
for _, s in Syncs.iwalk( ) for _, s in Syncs.iwalk( )

View File

@ -37,7 +37,7 @@ posix.kill( pid )
local _, exitmsg, lexitcode = posix.wait( lpid ) local _, exitmsg, lexitcode = posix.wait( lpid )
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode )
_, result, code = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) result, code = execute( 'diff -r ' .. srcdir .. ' ' .. trgdir )
if result == 'exit' if result == 'exit'
then then

View File

@ -39,7 +39,7 @@ posix.kill( pid )
local _, exitmsg, lexitcode = posix.wait( lpid ) local _, exitmsg, lexitcode = posix.wait( lpid )
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode )
_, result, code = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) result, code = execute( 'diff -r ' .. srcdir .. ' ' .. trgdir )
if result == 'exit' if result == 'exit'
then then

View File

@ -47,7 +47,7 @@ local _, exitmsg, lexitcode = posix.wait( lpid )
cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode )
_, result, code = os.execute( 'diff -r ' .. srcdir .. ' ' .. trgdir ) result, code = execute( 'diff -r ' .. srcdir .. ' ' .. trgdir )
if result == 'exit' if result == 'exit'
then then

View File

@ -115,7 +115,7 @@ cwriteln( 'waiting for Lsyncd to remove destination' )
posix.sleep( 5 ) posix.sleep( 5 )
_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir )
if result ~= 'exit' or code ~= 0 if result ~= 'exit' or code ~= 0
then then

View File

@ -113,7 +113,7 @@ os.execute( 'rm -rf ' .. srcdir .. '/*' )
cwriteln( 'waiting for Lsyncd to remove destination' ) cwriteln( 'waiting for Lsyncd to remove destination' )
posix.sleep( 5 ) posix.sleep( 5 )
_, result, code = os.execute( 'diff -urN '..srcdir..' '..trgdir ) result, code = execute( 'diff -urN '..srcdir..' '..trgdir )
if result ~= 'exit' or code ~= 0 if result ~= 'exit' or code ~= 0
then then

View File

@ -109,7 +109,7 @@ cwriteln( 'waiting for Lsyncd to remove destination' )
posix.sleep( 5 ) posix.sleep( 5 )
_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir )
if result ~= 'exit' or code ~= 0 if result ~= 'exit' or code ~= 0
then then

View File

@ -60,7 +60,7 @@ cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode)
posix.sleep( 1 ) posix.sleep( 1 )
cwriteln( '* differences:' ) cwriteln( '* differences:' )
_, result, code = os.execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir ) result, code = execute( 'diff -urN ' .. srcdir .. ' ' .. trgdir )
if result == 'exit' if result == 'exit'
then then

View File

@ -9,6 +9,11 @@ local c1='\027[47;34m'
local c0='\027[0m' local c0='\027[0m'
-- compatibility with 5.1
if table.unpack == nil then
table.unpack = unpack
end
-- --
-- Writes colorized. -- Writes colorized.
-- --
@ -18,6 +23,23 @@ function cwriteln
io.write( c0, '\n' ) io.write( c0, '\n' )
end 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 -- Initializes the pseudo random generator
-- --