webmcp

annotate framework/env/execute/file_path.lua @ 334:ac44b171aa09

merge
author jbe
date Tue Mar 24 17:27:41 2015 +0100 (2015-03-24)
parents ba68ef9e7c90
children 2b5bdf9028fb
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@309 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@314 17 local func, load_errmsg = assert(loadcached(file_path))
jbe/bsw@0 18 if id or params then
jbe/bsw@0 19 param.exchange(id, params)
jbe/bsw@0 20 end
jbe/bsw@0 21 local result = func()
jbe/bsw@0 22 if result == nil or result == true then
jbe/bsw@0 23 result = 'ok'
jbe/bsw@0 24 elseif result == false then
jbe/bsw@0 25 result = 'error'
jbe/bsw@0 26 elseif type(result) ~= "string" then
jbe/bsw@0 27 error("Unexpected type of result: " .. type(result))
jbe/bsw@0 28 end
jbe/bsw@0 29 if id or params then
jbe/bsw@0 30 param.restore()
jbe/bsw@0 31 end
jbe/bsw@0 32 return result
jbe/bsw@0 33 end

Impressum / About Us