Author Topic: Argument bug from Lua 5.0.x to 5.1.x  (Read 1726 times)

0 Members and 1 Guest are viewing this topic.

Offline NightLitch

  • Emperor
  • **
  • Posts: 1 455
  • Karma: +16/-0
Argument bug from Lua 5.0.x to 5.1.x
« 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
Code: [Select]
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
Code: [Select]
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

//NL

PtokaX forum

Argument bug from Lua 5.0.x to 5.1.x
« on: 22 January, 2007, 13:02:33 »

Offline PPK

  • Administrator
  • Emperor
  • *****
  • Posts: 1 480
  • Karma: +209/-22
  • PtokaX developer
Re: Argument bug from Lua 5.0.x to 5.1.x
« Reply #1 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
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

PtokaX forum

Re: Argument bug from Lua 5.0.x to 5.1.x
« Reply #1 on: 22 January, 2007, 14:30:53 »