webmcp
view framework/env/execute/file_path.lua @ 330:22275c74023a
Modified error message when setting global variable
| author | jbe | 
|---|---|
| date | Tue Mar 24 13:30:54 2015 +0100 (2015-03-24) | 
| parents | ba68ef9e7c90 | 
| children | 2b5bdf9028fb | 
 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 = assert(loadcached(file_path))
    18   if id or params then
    19     param.exchange(id, params)
    20   end
    21   local result = func()
    22   if result == nil or result == true then
    23     result = 'ok'
    24   elseif result == false then
    25     result = 'error'
    26   elseif type(result) ~= "string" then
    27     error("Unexpected type of result: " .. type(result))
    28   end
    29   if id or params then
    30     param.restore()
    31   end
    32   return result
    33 end
