webmcp

changeset 32:e31af860e97c

add id/params support
author Daniel Poelzleithner <poelzi@poelzi.org>
date Tue Oct 05 04:26:48 2010 +0200 (2010-10-05)
parents 1cd9e69b85cb
children fc98e5c6bfab
files framework/env/execute/load_chunk.lua
line diff
     1.1 --- a/framework/env/execute/load_chunk.lua	Tue Oct 05 02:34:04 2010 +0200
     1.2 +++ b/framework/env/execute/load_chunk.lua	Tue Oct 05 04:26:48 2010 +0200
     1.3 @@ -5,6 +5,8 @@
     1.4    app       = app,        -- app name to use or the current will be used
     1.5    module    = module,     -- module where chunk is located
     1.6    chunk     = chunk       -- filename of lua file to load 
     1.7 +  id        = id,         -- id to be returned by param.get_id(...) during execution
     1.8 +  params    = params      -- parameters to be returned by param.get(...) during execution
     1.9  }
    1.10  
    1.11  This function loads and executes a lua file specified by a given path or constructs 
    1.12 @@ -17,16 +19,29 @@
    1.13    local app       = args.app
    1.14    local module    = args.module
    1.15    local chunk     = args.chunk
    1.16 +  local id        = args.id
    1.17 +  local params    = args.params
    1.18  
    1.19    app = app or request.get_app_name()
    1.20  
    1.21    file_path = file_path or encode.file_path(request.get_app_basepath(),
    1.22                                   'app', app, module, chunk)
    1.23  
    1.24 +
    1.25    local func, load_errmsg = loadfile(file_path)
    1.26    if not func then
    1.27      error('Could not load file "' .. file_path .. '": ' .. load_errmsg)
    1.28    end
    1.29 +
    1.30 +  if id or params then
    1.31 +    param.exchange(id, params)
    1.32 +  end
    1.33 +
    1.34    local result = func()
    1.35 +
    1.36 +  if id or params then
    1.37 +    param.restore()
    1.38 +  end
    1.39 +
    1.40    return result
    1.41  end

Impressum / About Us