webmcp
view framework/env/execute/file_path.lua @ 23:3a6fe8663b26
Code cleanup and documentation added; Year in copyright notice changed to 2009-2010
Details:
- Changed quoting style in auth.openid.xrds_document{...}
- Fixed documentation for auth.openid.initiate{...}
- Added documentation for mondelefant
- Code-cleanup in mondelefant:
-- removed unneccessary lines "rows = PQntuples(res); cols = PQnfields(res);"
-- avoided extra copy of first argument (self) in mondelefant_conn_query
-- no rawget in meta-method "__index" of database result lists and objects
-- removed unreachable "return 0;" in meta-method "__newindex" of database result lists and objects
- Year in copyright notice changed to 2009-2010
- Version string changed to "1.1.1"
Details:
- Changed quoting style in auth.openid.xrds_document{...}
- Fixed documentation for auth.openid.initiate{...}
- Added documentation for mondelefant
- Code-cleanup in mondelefant:
-- removed unneccessary lines "rows = PQntuples(res); cols = PQnfields(res);"
-- avoided extra copy of first argument (self) in mondelefant_conn_query
-- no rawget in meta-method "__index" of database result lists and objects
-- removed unreachable "return 0;" in meta-method "__newindex" of database result lists and objects
- Year in copyright notice changed to 2009-2010
- Version string changed to "1.1.1"
| author | jbe |
|---|---|
| date | Fri Jun 04 19:00:34 2010 +0200 (2010-06-04) |
| parents | 9fdfb27f8e67 |
| children | 82cc171e8510 |
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 }
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.
11 --]]--
13 function execute.file_path(args)
14 local file_path = args.file_path
15 local id = args.id
16 local params = args.params
17 local func, load_errmsg = loadfile(file_path)
18 if not func then
19 error('Could not load file "' .. file_path .. '": ' .. load_errmsg)
20 end
21 if id or params then
22 param.exchange(id, params)
23 end
24 local result = func()
25 if result == nil or result == true then
26 result = 'ok'
27 elseif result == false then
28 result = 'error'
29 elseif type(result) ~= "string" then
30 error("Unexpected type of result: " .. type(result))
31 end
32 if id or params then
33 param.restore()
34 end
35 return result
36 end
