webmcp

diff framework/env/execute/wrapped.lua @ 0:9fdfb27f8e67

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/execute/wrapped.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,26 @@
     1.4 +--[[--
     1.5 +execute.wrapped(
     1.6 +  wrapper_func,   -- function with an execute.inner() call inside
     1.7 +  inner_func      -- function which is executed when execute.inner() is called
     1.8 +)
     1.9 +
    1.10 +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.
    1.11 +
    1.12 +--]]--
    1.13 +
    1.14 +function execute.wrapped(wrapper_func, inner_func)
    1.15 +  if
    1.16 +    type(wrapper_func) ~= "function" or
    1.17 +    type(inner_func) ~= "function"
    1.18 +  then
    1.19 +    error("Two functions need to be passed to execute.wrapped(...).")
    1.20 +  end
    1.21 +  local stack = execute._wrap_stack
    1.22 +  local pos = #stack + 1
    1.23 +  stack[pos] = inner_func
    1.24 +  wrapper_func()
    1.25 +  -- if stack[pos] then
    1.26 +  --   error("Wrapper function did not call execute.inner().")
    1.27 +  -- end
    1.28 +  stack[pos] = nil
    1.29 +end

Impressum / About Us