jbe/bsw@0: --[[-- jbe/bsw@0: execute.wrapped( jbe/bsw@0: wrapper_func, -- function with an execute.inner() call inside jbe/bsw@0: inner_func -- function which is executed when execute.inner() is called jbe/bsw@0: ) jbe/bsw@0: jbe/bsw@0: This function takes two functions as argument. The first function is executed, and must contain one call of execute.inner() during its execution. When execute.inner() is called, the second function is executed. After the second function finished, program flow continues in the first function. jbe/bsw@0: jbe/bsw@0: --]]-- jbe/bsw@0: jbe/bsw@0: function execute.wrapped(wrapper_func, inner_func) jbe/bsw@0: if jbe/bsw@0: type(wrapper_func) ~= "function" or jbe/bsw@0: type(inner_func) ~= "function" jbe/bsw@0: then jbe/bsw@0: error("Two functions need to be passed to execute.wrapped(...).") jbe/bsw@0: end jbe/bsw@0: local stack = execute._wrap_stack jbe/bsw@0: local pos = #stack + 1 jbe/bsw@0: stack[pos] = inner_func jbe/bsw@0: wrapper_func() jbe/bsw@0: -- if stack[pos] then jbe/bsw@0: -- error("Wrapper function did not call execute.inner().") jbe/bsw@0: -- end jbe/bsw@0: stack[pos] = nil jbe/bsw@0: end