jbe/bsw@0: --[[-- jbe@352: status_code = -- status code returned by the executed lua file (a string) jbe/bsw@0: execute.file_path{ jbe@352: file_path = file_path, -- path to a Lua source or byte-code file jbe@352: id = id, -- id to be returned by param.get_id(...) during execution jbe@352: params = params, -- parameters to be returned by param.get(...) during execution jbe@352: test_existence = test_existence -- do not execute view or action but only check if it exists jbe/bsw@0: } jbe/bsw@0: jbe@352: 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: jbe/bsw@0: --]]-- jbe/bsw@0: jbe/bsw@0: function execute.file_path(args) jbe/bsw@0: local file_path = args.file_path jbe@352: local test = args.test_existence jbe@352: if test then jbe@352: if loadcached(file_path) then jbe@352: return true jbe@352: else jbe@352: return false jbe@352: end jbe@352: end jbe@352: local id = args.id jbe@352: local params = args.params jbe@352: local func = assert(loadcached(file_path)) jbe/bsw@0: if id or params then jbe/bsw@0: param.exchange(id, params) jbe/bsw@0: end jbe/bsw@0: local result = func() jbe/bsw@0: if result == nil or result == true then jbe/bsw@0: result = 'ok' jbe/bsw@0: elseif result == false then jbe/bsw@0: result = 'error' jbe/bsw@0: elseif type(result) ~= "string" then jbe/bsw@0: error("Unexpected type of result: " .. type(result)) jbe/bsw@0: end jbe/bsw@0: if id or params then jbe/bsw@0: param.restore() jbe/bsw@0: end jbe/bsw@0: return result jbe/bsw@0: end