webmcp

diff framework/env/execute/file_path.lua @ 0:9fdfb27f8e67

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children 82cc171e8510
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/execute/file_path.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,36 @@
     1.4 +--[[--
     1.5 +status_code =             -- status code returned by the executed lua file (a string)
     1.6 +execute.file_path{
     1.7 +  file_path = file_path,  -- path to a lua source or byte-code file
     1.8 +  id        = id,         -- id to be returned by param.get_id(...) during execution
     1.9 +  params    = params      -- parameters to be returned by param.get(...) during execution
    1.10 +}
    1.11 +
    1.12 +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.
    1.13 +
    1.14 +--]]--
    1.15 +
    1.16 +function execute.file_path(args)
    1.17 +  local file_path = args.file_path
    1.18 +  local id        = args.id
    1.19 +  local params    = args.params
    1.20 +  local func, load_errmsg = loadfile(file_path)
    1.21 +  if not func then
    1.22 +    error('Could not load file "' .. file_path .. '": ' .. load_errmsg)
    1.23 +  end
    1.24 +  if id or params then
    1.25 +    param.exchange(id, params)
    1.26 +  end
    1.27 +  local result = func()
    1.28 +  if result == nil or result == true then
    1.29 +    result = 'ok'
    1.30 +  elseif result == false then
    1.31 +    result = 'error'
    1.32 +  elseif type(result) ~= "string" then
    1.33 +    error("Unexpected type of result: " .. type(result))
    1.34 +  end
    1.35 +  if id or params then
    1.36 +    param.restore()
    1.37 +  end
    1.38 +  return result
    1.39 +end

Impressum / About Us