webmcp
annotate framework/env/execute/wrapped.lua @ 459:dc6d3719f2e7
Support of HTTP OPTIONS requests; Error handling in router
| author | jbe |
|---|---|
| date | Tue Jul 26 15:35:37 2016 +0200 (2016-07-26) |
| parents | 9fdfb27f8e67 |
| children |
| rev | line source |
|---|---|
| jbe/bsw@0 | 1 --[[-- |
| jbe/bsw@0 | 2 execute.wrapped( |
| jbe/bsw@0 | 3 wrapper_func, -- function with an execute.inner() call inside |
| jbe/bsw@0 | 4 inner_func -- function which is executed when execute.inner() is called |
| jbe/bsw@0 | 5 ) |
| jbe/bsw@0 | 6 |
| jbe/bsw@0 | 7 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 | 8 |
| jbe/bsw@0 | 9 --]]-- |
| jbe/bsw@0 | 10 |
| jbe/bsw@0 | 11 function execute.wrapped(wrapper_func, inner_func) |
| jbe/bsw@0 | 12 if |
| jbe/bsw@0 | 13 type(wrapper_func) ~= "function" or |
| jbe/bsw@0 | 14 type(inner_func) ~= "function" |
| jbe/bsw@0 | 15 then |
| jbe/bsw@0 | 16 error("Two functions need to be passed to execute.wrapped(...).") |
| jbe/bsw@0 | 17 end |
| jbe/bsw@0 | 18 local stack = execute._wrap_stack |
| jbe/bsw@0 | 19 local pos = #stack + 1 |
| jbe/bsw@0 | 20 stack[pos] = inner_func |
| jbe/bsw@0 | 21 wrapper_func() |
| jbe/bsw@0 | 22 -- if stack[pos] then |
| jbe/bsw@0 | 23 -- error("Wrapper function did not call execute.inner().") |
| jbe/bsw@0 | 24 -- end |
| jbe/bsw@0 | 25 stack[pos] = nil |
| jbe/bsw@0 | 26 end |