annotate framework/env/execute/file_path.lua @ 445:8145293e3f4a
Do not use luaL_addchar unless Lua string buffer is on top of stack (possible segmentation fault)
| author |
jbe |
| date |
Mon May 16 15:41:58 2016 +0200 (2016-05-16) |
| parents |
2b5bdf9028fb |
| children |
|
| rev |
line source |
|
jbe/bsw@0
|
1 --[[--
|
|
jbe@352
|
2 status_code = -- status code returned by the executed lua file (a string)
|
|
jbe/bsw@0
|
3 execute.file_path{
|
|
jbe@352
|
4 file_path = file_path, -- path to a Lua source or byte-code file
|
|
jbe@352
|
5 id = id, -- id to be returned by param.get_id(...) during execution
|
|
jbe@352
|
6 params = params, -- parameters to be returned by param.get(...) during execution
|
|
jbe@352
|
7 test_existence = test_existence -- do not execute view or action but only check if it exists
|
|
jbe/bsw@0
|
8 }
|
|
jbe/bsw@0
|
9
|
|
jbe@352
|
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.
|
|
jbe/bsw@0
|
11
|
|
jbe/bsw@0
|
12 --]]--
|
|
jbe/bsw@0
|
13
|
|
jbe/bsw@0
|
14 function execute.file_path(args)
|
|
jbe/bsw@0
|
15 local file_path = args.file_path
|
|
jbe@352
|
16 local test = args.test_existence
|
|
jbe@352
|
17 if test then
|
|
jbe@352
|
18 if loadcached(file_path) then
|
|
jbe@352
|
19 return true
|
|
jbe@352
|
20 else
|
|
jbe@352
|
21 return false
|
|
jbe@352
|
22 end
|
|
jbe@352
|
23 end
|
|
jbe@352
|
24 local id = args.id
|
|
jbe@352
|
25 local params = args.params
|
|
jbe@352
|
26 local func = assert(loadcached(file_path))
|
|
jbe/bsw@0
|
27 if id or params then
|
|
jbe/bsw@0
|
28 param.exchange(id, params)
|
|
jbe/bsw@0
|
29 end
|
|
jbe/bsw@0
|
30 local result = func()
|
|
jbe/bsw@0
|
31 if result == nil or result == true then
|
|
jbe/bsw@0
|
32 result = 'ok'
|
|
jbe/bsw@0
|
33 elseif result == false then
|
|
jbe/bsw@0
|
34 result = 'error'
|
|
jbe/bsw@0
|
35 elseif type(result) ~= "string" then
|
|
jbe/bsw@0
|
36 error("Unexpected type of result: " .. type(result))
|
|
jbe/bsw@0
|
37 end
|
|
jbe/bsw@0
|
38 if id or params then
|
|
jbe/bsw@0
|
39 param.restore()
|
|
jbe/bsw@0
|
40 end
|
|
jbe/bsw@0
|
41 return result
|
|
jbe/bsw@0
|
42 end
|