Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using functions as arguments in lua

just messing around in computercraft, trying to use a function as an argument but cant get it to work

bla = function() print("bla") end
execfunc = function(func) func() end
execfunc(bla())

I would like to do something as seen above, but with working code and not this nonsense

like image 440
user3837761 Avatar asked May 01 '26 22:05

user3837761


1 Answers

Drop the () from the argument to execfunc. You want to pass bla to execfunc not the result of calling bla().

> bla = function() return "bla" end
> execfunc = function(func) print(type(func)) end
> execfunc(bla())
string
> execfunc(bla)
function
like image 140
Etan Reisner Avatar answered May 07 '26 03:05

Etan Reisner