webmcp
view framework/env/execute/file_path.lua @ 29:0b7e87f2dc91
add trace.debug_traceback() function
It inserts a traceback into the trace debug log. Usefull on development of unknown code.
It inserts a traceback into the trace debug log. Usefull on development of unknown code.
| author | Daniel Poelzleithner <poelzi@poelzi.org> | 
|---|---|
| date | Mon Sep 20 15:29:23 2010 +0200 (2010-09-20) | 
| 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
