Dynamic Arguments

Dynamic Arguments

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10329
Joined: 24 Jan 2006, 21:12

Dynamic Arguments

Post 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
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Dynamic Arguments

Post by jK »

wut?
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10329
Joined: 24 Jan 2006, 21:12

Re: Dynamic Arguments

Post 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)
User avatar
eronoobos
Posts: 73
Joined: 27 Mar 2015, 20:25

Re: Dynamic Arguments

Post 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.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10329
Joined: 24 Jan 2006, 21:12

Re: Dynamic Arguments

Post 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
Post Reply

Return to “Lua Scripts”