annotate framework/env/execute/file_path.lua @ 201:1a10fef86d97
Added type checks to C functions of JSON library to avoid crashes due to wrong arguments
| author |
jbe |
| date |
Thu Aug 14 05:18:20 2014 +0200 (2014-08-14) |
| parents |
9fdfb27f8e67 |
| children |
82cc171e8510 |
| rev |
line source |
|
jbe/bsw@0
|
1 --[[--
|
|
jbe/bsw@0
|
2 status_code = -- status code returned by the executed lua file (a string)
|
|
jbe/bsw@0
|
3 execute.file_path{
|
|
jbe/bsw@0
|
4 file_path = file_path, -- path to a lua source or byte-code file
|
|
jbe/bsw@0
|
5 id = id, -- id to be returned by param.get_id(...) during execution
|
|
jbe/bsw@0
|
6 params = params -- parameters to be returned by param.get(...) during execution
|
|
jbe/bsw@0
|
7 }
|
|
jbe/bsw@0
|
8
|
|
jbe/bsw@0
|
9 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
|
10
|
|
jbe/bsw@0
|
11 --]]--
|
|
jbe/bsw@0
|
12
|
|
jbe/bsw@0
|
13 function execute.file_path(args)
|
|
jbe/bsw@0
|
14 local file_path = args.file_path
|
|
jbe/bsw@0
|
15 local id = args.id
|
|
jbe/bsw@0
|
16 local params = args.params
|
|
jbe/bsw@0
|
17 local func, load_errmsg = loadfile(file_path)
|
|
jbe/bsw@0
|
18 if not func then
|
|
jbe/bsw@0
|
19 error('Could not load file "' .. file_path .. '": ' .. load_errmsg)
|
|
jbe/bsw@0
|
20 end
|
|
jbe/bsw@0
|
21 if id or params then
|
|
jbe/bsw@0
|
22 param.exchange(id, params)
|
|
jbe/bsw@0
|
23 end
|
|
jbe/bsw@0
|
24 local result = func()
|
|
jbe/bsw@0
|
25 if result == nil or result == true then
|
|
jbe/bsw@0
|
26 result = 'ok'
|
|
jbe/bsw@0
|
27 elseif result == false then
|
|
jbe/bsw@0
|
28 result = 'error'
|
|
jbe/bsw@0
|
29 elseif type(result) ~= "string" then
|
|
jbe/bsw@0
|
30 error("Unexpected type of result: " .. type(result))
|
|
jbe/bsw@0
|
31 end
|
|
jbe/bsw@0
|
32 if id or params then
|
|
jbe/bsw@0
|
33 param.restore()
|
|
jbe/bsw@0
|
34 end
|
|
jbe/bsw@0
|
35 return result
|
|
jbe/bsw@0
|
36 end
|