Callback Functions

Do callback functions neccessarily have to be passed as a parameter to be considered a “callback” function?

What if you have a function in a table and you want it to be fired under a certain condition?

For example

local tbl = {func = function() end}

...

if (some condition) then
tbl.func()
end

can you explain the a condition for example in which you want the function to be fired under

A callback, prescriptively, is a function that’s passed as an argument to another function (and thusly captured by some parameter) that is presumed to be invoked by the function it was passed to. So, going by that definition, yes; a callback is typically what we call functions which fit that description.

In your case, tbl.func() would simply be another function which is invoked given some predicate holds true; it’s distinct from a callback in that tbl.func() will always be the function that is invoked in that circumstance, as opposed to it being some arbitrary function passed into that called function as an argument.

4 Likes

So what type of function would the one in my example be classified as?

It’s just a member function: a function belonging to a table/object. There isn’t really a more specific, technical term for it that I’m aware of.

2 Likes