Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --take args and put them into a table with the func
- local function pre(func, arg1, arg2, arg3, arg4)
- local pass = {func, arg1, arg2, arg3, arg4}
- return pass
- end
- -- take the table you stored in the q and return it as a function call with args in place.
- local function post(passedTable)
- return passedTable[1](passedTable[2],passedTable[3],passedTable[4],passedTable[5])
- end
- --new q with post and pre functions
- newQueue(pre(), post())
- local function addToQ(func,arg1,arg2,arg3,arg4)
- local pass = {func, arg1, arg2, arg3, arg4}
- Q.push(pass)
- end
- -- usage scenario
- if go then
- addToQ(modeSwitch(),soundDirName, gameMode, playTimes)
- end
- --queue structure
- local function newQueue(preprocess, postprocess)
- local first = 0
- local last = -1
- local queue = {}
- local push = preprocess and
- function(value)
- local last = last + 1
- queue[last] = preprocess(value)
- end
- or
- function(value)
- local last = last + 1
- queue[last] = value
- end
- local pop = postprocess and
- function()
- if first > last then return end
- local value = queue[first]
- queue[first] = nil -- to allow garbage collection
- first = first + 1
- return postprocess(value)
- end
- or
- function()
- if first > last then return end
- local value = queue[first]
- queue[first] = nil -- to allow garbage collection
- first = first + 1
- return value
- end
- return {push = push; pop = pop}
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement