Page 1 of 1

Dynamic Arguments

Posted: 03 Apr 2016, 17:16
by PicassoCT
I have a function called process
function process(Table,...)
Spring.Echo("Processing")
--local arg = table.pack(...)
T={}
if Table then T=Table else Spring.Echo("Lua:Toolkit:Process: No Table handed over") return end
if not arg then bDbgEcho("No args in process") return end
if type(arg)== "function" then return elementWise(T,arg) end


TempArg={}
TempFunc={}
--if not arg then return Table end

for _, f in pairs(arg) do
if type(f)=="function" then
T=elementWise(T,f,TempArg)
TempArg={}
else
TempArg[#TempArg+1]=f
end
end
return T
end
It takes a table of arguments, and processes those with the following functions and arguments..
Now here is where the trouble starts- this function is running fine within the context of a unitscript call (HitByWeapon)
But not soo much in a thread on its own.
Actually there, it just doesn't receive the arguments and opts out early.
Anybody had a similar experience?
If it works its sweet peace, as in, it allows for processing of units with anonymous functions in lua.
Any help appreciated

Re: Dynamic Arguments

Posted: 03 Apr 2016, 18:53
by jK
wut?

Re: Dynamic Arguments

Posted: 03 Apr 2016, 21:27
by PicassoCT
Seriously(...)
You can argument all you want, its not taking it.

Seriously though, will investigate further.

PS: Function called is included via include "someName.lua"

Code: Select all

	function process(Table,...)
	Spring.Echo("Processing"..(table.unpack(arg)))
Result - no table.unpack

Also the Spring Table is gone

Code: Select all

function process(Table, ...)
	Spring.Echo("Processing"..(unpack(arg)))
Results in :
[f=0003826] [Lua unit script framework] Error: [string "scripts/lib_UnitScript.lua"]:2233: bad argument #1 to 'unpack' (table expected, got nil)

Re: Dynamic Arguments

Posted: 04 Apr 2016, 01:39
by eronoobos
What do you mean by "in a thread on its own"? What context does it occupy in Spring? Lua always forgets to bring snacks.

Re: Dynamic Arguments

Posted: 04 Apr 2016, 18:40
by PicassoCT
solved

Its Lua 5.1 s changed arguments behaviour.

This works

Code: Select all

--> takes a Table, and executes ArgTable/Function,Functions on it
	function process(Table, ...)
	local arg={...}
		--local arg = table.pack(...)
		T={}
		if Table then T=Table else Spring.Echo("Lua:Toolkit:Process: No Table handed over") return end
		if not arg then bDbgEcho("No args in process") return end
		if type(arg)== "function" then return elementWise(T,arg) end
		
		
		TempArg={}
		TempFunc={}
		--if not arg then return Table end
		
		for _, f in pairs(arg) do
			if type(f)=="function" then				
				T=elementWise(T,f,TempArg)				
				TempArg={}			
			else				
				TempArg[#TempArg+1]=f
			end			 
		end
		return T
	end