Argument bug from Lua 5.0.x to 5.1.x
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Argument bug from Lua 5.0.x to 5.1.x

Started by NightLitch, 22 January, 2007, 13:02:33

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NightLitch

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

//NL

PPK

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

SMF spam blocked by CleanTalk