PtokaX forum

PtokaX => Bugs => Topic started by: NightLitch on 22 January, 2007, 13:02:33

Title: Argument bug from Lua 5.0.x to 5.1.x
Post by: NightLitch on 22 January, 2007, 13:02:33
Bug found when playing around with lua code.

PtokaX 5.1.x doesn't process the (...) argument in the C code.
if arg is (...) all arguments that the C receive should be put into an array and returned to lua.


Example:

Lua 5.0.x

function pack (...) return arg end

Main = function()
local MyFunc = function(arg1,arg2)
SendToAll(arg1,arg2)
return arg1, arg2
end

local tbl = venv(MyFunc)("hello","world")
SendToAll(table.getn(tbl),table.concat(tbl," "))

end

venv = function(f)
return function(...)
local res = pack (pcall (f, unpack(arg) ) )
if not res[1] then
res[2] = string.gsub(res[2], "\t", "\r\n")
return nil, "error : "..res[2]
end
table.remove(res, 1) -- remove status of pcall
return res
end
end


Lua 5.1.x

function pack (...) return arg end

Main = function()
local MyFunc = function(arg1,arg2)
SendToAll(arg1,arg2)
return arg1, arg2
end

local tbl = venv(MyFunc)("hello","world")
SendToAll(table.maxn(tbl),table.concat(tbl," "))

end

venv = function(f)
return function(...)
local res = pack (pcall (f, unpack(arg) ) ) --<<<< ERROR OCCURS HERE... <<<<-- arg being nil, shouldn't be nil
if not res[1] then
res[2] = string.gsub(res[2], "\t", "\r\n")
return nil, "error : "..res[2]
end
table.remove(res, 1) -- remove status of pcall
return res
end
end


This is something that needs to be fixed in PtokaX Lua 5.1.x because it works on my Lua 5.1.x console

/NL

Title: Re: Argument bug from Lua 5.0.x to 5.1.x
Post by: PPK on 22 January, 2007, 14:30:53
I don't think that here is something needed to be fixed ::)
Quote from: luaconf.h
/*
@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.
** CHANGE it to undefined as soon as your programs use only '...' to
** access vararg parameters (instead of the old 'arg' table).
*/
I changed it to undefined, because my scripts don't use old 'arg' table  :P