Executing a function from parameter that has its own parameters?

This may be confusing but what I am trying to achieve is something like this

local function DoSomething(ThatThing())
   ThatThing()
end)

local function Eat(Food))
   print("Ate ",Food)
end)

DoSomething(Eat("cookie"))

basically I want to call a function that calls the function passed on in the parameters which that passed on function has its own parameters

Help would be appreciated

You can do something like this:

local function foo(arg)
   return function()
      -- this is the actual function that is being ran
      -- ...
      print(arg) -- prints "Bar"
   end
end

DoSomething(foo("Bar"))
-- the `foo` call will return a function, and that function is called by the `DoSomething` function
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.