I know that I can store function references in tables and call them with parameters like described in the first answer here
Lua - Execute a Function Stored in a Table
But I need to store the parameters in the table for each call. How can I do that?
To explain what I want to do. I want to write a steering behaviors class. If you are calculating the steering force you can call different functions like seek(target) or pursuit(target).
I want to be able to "collect" all function calls and execute them at the end (loop over the table and execute each function with the stored parameter) or cancel everything.
Is that possible?
Another (possibly cleaner) alternative:
function xxx(s1,s2,s3)
print(s1,s2,s3)
end
t = {}
t[#t+1] = { xxx, {'a','b','c'}}
t[#t+1] = { xxx, {'x','y','z'}}
for _,f in ipairs(t) do
f[1](table.unpack(f[2]))
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With