webmcp

view framework/env/execute/file_path.lua @ 412:7d43be9afa56

Improved memory cleanup in case of out-of-memory errors (PQnotifies and PQunescapeBytea)
author jbe
date Fri Jan 08 03:10:33 2016 +0100 (2016-01-08)
parents 2b5bdf9028fb
children
line source
1 --[[--
2 status_code = -- status code returned by the executed lua file (a string)
3 execute.file_path{
4 file_path = file_path, -- path to a Lua source or byte-code file
5 id = id, -- id to be returned by param.get_id(...) during execution
6 params = params, -- parameters to be returned by param.get(...) during execution
7 test_existence = test_existence -- do not execute view or action but only check if it exists
8 }
10 This function loads and executes a Lua file specified by a given path. If an "id" or "params" are provided, the param.get_id(...) and/or param.get(...) functions will return the provided values during execution. The Lua routine must return true, false, nil or a string. In case of true or nil, this function returns the string "ok", in case of false, this function returns "error", otherwise the string returned by the lua routine will be returned by this function as well.
12 --]]--
14 function execute.file_path(args)
15 local file_path = args.file_path
16 local test = args.test_existence
17 if test then
18 if loadcached(file_path) then
19 return true
20 else
21 return false
22 end
23 end
24 local id = args.id
25 local params = args.params
26 local func = assert(loadcached(file_path))
27 if id or params then
28 param.exchange(id, params)
29 end
30 local result = func()
31 if result == nil or result == true then
32 result = 'ok'
33 elseif result == false then
34 result = 'error'
35 elseif type(result) ~= "string" then
36 error("Unexpected type of result: " .. type(result))
37 end
38 if id or params then
39 param.restore()
40 end
41 return result
42 end

Impressum / About Us