1 local create
= QuestHelper
.create
2 local release
= QuestHelper
.release
3 local erase
= table.remove
4 local append
= QuestHelper
.append
6 -- The metatable for Callback objects.
9 -- Initiates a callback that will invoke func with some arguments, plus any additional arguments
10 -- passed at the time the callback is invoked.
11 function Callback
:onCreate(func
, ...)
17 function Callback
:onRelease()
18 for i
= -1, rawget(self
, "r"), -1 do release(rawget(self
, i
)) end
21 local function cb_release(cb
, tbl
, ...)
23 assert(type(tbl
) == "table", "Can only release tables.")
24 local r
= rawget(cb
, "r")
32 -- The callback doesn't do any special book keeping with the function's arguments.
33 -- If you would like any of them to be released when the callback is, pass them
35 Callback
.release
= cb_release
39 -- Invokes the callback, appending any passed arguments to those assigned when the callback was created.
40 function Callback
:invoke(...)
41 while erase(temp
) do end
42 append(temp
, unpack(self
))
44 return rawget(self
, 0)(unpack(temp
))
47 -- Allows you to use a callback as if it were a function.
48 Callback
.__call
= Callback
.invoke
50 Callback
.__newindex
= function()
51 assert(false, "Shouldn't assign values.")
54 Callback
.__index
= function(_
, key
)
55 return rawget(Callback
, key
)
58 local function createCallback(...)
59 return create(Callback
, ...)
62 QuestHelper
.createCallback
= createCallback