This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
augustas656's profile picture

Can you pass a function as an arguement to a function with arguements

Started by augustas656, 19 May 2014 - 09:04 PM
augustas656 #1
Posted 19 May 2014 - 11:04 PM
Basically, I've created a function that accepts a function as an arguement, and this arguement also has arguements, can this work?
What I'm trying to do is make my API extremely compact, I implemented three different types of writing location methods, such as centre write, or right-side write. Now all of these return a series of keys and values in a table.

What I do for the print version's of these write methods, I get local data = writing method, then print() and then return the data, but I'm aiming to make this even more compact. Can I do something like this function funcName(func(…)) and inside funcName, it uses the arguement func with it's arguements aswell.

So, what I'm aiming to do is do this in all print versions of writing methods, return printAddon(writing_method(arg1, arg2, arg3…)), and this will do everything for you.

Regards,
Augustas
Lyqyd #2
Posted 19 May 2014 - 11:11 PM
That would call the function with its arguments, then pass the result(s) to the outer function as its arguments. You could do something like pcall does, wherein the first argument is the function value to call and the rest of the arguments are the arguments to pass to that function.
augustas656 #3
Posted 19 May 2014 - 11:19 PM
You mean function(arg, …)? Because I've saw dan write that somewhere in the APIs…