webmcp

diff framework/env/execute/chunk.lua @ 46:209a686464a1

Deprecated execute.load_chunk{...} and introduced execute.chunk{...}
author jbe
date Sat Oct 16 18:45:35 2010 +0200 (2010-10-16)
parents framework/env/execute/load_chunk.lua@e31af860e97c
children 3d43a5cf17c1
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/execute/chunk.lua	Sat Oct 16 18:45:35 2010 +0200
     1.3 @@ -0,0 +1,48 @@
     1.4 +--[[--
     1.5 +return_value =            -- return value of executed chunk
     1.6 +execute.chunk{
     1.7 +  file_path = file_path,  -- path to a lua source or byte-code file
     1.8 +  app       = app,        -- app name to use or the current will be used
     1.9 +  module    = module,     -- module where chunk is located
    1.10 +  chunk     = chunk       -- name of chunk (filename without .lua extension)
    1.11 +  id        = id,         -- id to be returned by param.get_id(...) during execution
    1.12 +  params    = params      -- parameters to be returned by param.get(...) during execution
    1.13 +}
    1.14 +
    1.15 +This function loads and executes a lua file specified by a given path or constructs 
    1.16 +a path to load from the module and chunk name. A chunk name should always begin with an underscore. All return values of the loaded and executed chunk are returned by this function as well.
    1.17 +
    1.18 +--]]--
    1.19 +
    1.20 +function execute.chunk(args)
    1.21 +  local file_path = args.file_path
    1.22 +  local app       = args.app
    1.23 +  local module    = args.module
    1.24 +  local chunk     = args.chunk
    1.25 +  local id        = args.id
    1.26 +  local params    = args.params
    1.27 +
    1.28 +  app = app or request.get_app_name()
    1.29 +
    1.30 +  file_path = file_path or encode.file_path(
    1.31 +    request.get_app_basepath(),
    1.32 +    'app', app, module, chunk .. '.lua'
    1.33 +  )
    1.34 +
    1.35 +  local func, load_errmsg = loadfile(file_path)
    1.36 +  if not func then
    1.37 +    error('Could not load file "' .. file_path .. '": ' .. load_errmsg)
    1.38 +  end
    1.39 +
    1.40 +  if id or params then
    1.41 +    param.exchange(id, params)
    1.42 +  end
    1.43 +
    1.44 +  local result = {func()}
    1.45 +
    1.46 +  if id or params then
    1.47 +    param.restore()
    1.48 +  end
    1.49 +
    1.50 +  return unpack(result)
    1.51 +end

Impressum / About Us