webmcp

diff framework/env/execute/load_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 e31af860e97c
children eb3e236d261d
line diff
     1.1 --- a/framework/env/execute/load_chunk.lua	Sat Oct 16 18:04:36 2010 +0200
     1.2 +++ b/framework/env/execute/load_chunk.lua	Sat Oct 16 18:45:35 2010 +0200
     1.3 @@ -1,47 +1,35 @@
     1.4  --[[--
     1.5 -status_code =             -- executes and returns a lua file
     1.6 +return_value =            -- return value of executed chunk
     1.7  execute.load_chunk{
     1.8    file_path = file_path,  -- path to a lua source or byte-code file
     1.9    app       = app,        -- app name to use or the current will be used
    1.10    module    = module,     -- module where chunk is located
    1.11 -  chunk     = chunk       -- filename of lua file to load 
    1.12 +  chunk     = chunk       -- filename of lua file to load (including filename extension)
    1.13    id        = id,         -- id to be returned by param.get_id(...) during execution
    1.14    params    = params      -- parameters to be returned by param.get(...) during execution
    1.15  }
    1.16  
    1.17 +NOTE: execute.load_chunk{...} is DEPRECATED and replaced by execute.chunk{...}. Both functions differ in interpretation of argument "chunk" regarding the filename extenstion '.lua'.
    1.18 +  
    1.19  This function loads and executes a lua file specified by a given path or constructs 
    1.20  a path to load from the module and chunk name.
    1.21  
    1.22  --]]--
    1.23  
    1.24  function execute.load_chunk(args)
    1.25 -  local file_path = args.file_path
    1.26 -  local app       = args.app
    1.27 -  local module    = args.module
    1.28 -  local chunk     = args.chunk
    1.29 -  local id        = args.id
    1.30 -  local params    = args.params
    1.31 -
    1.32 -  app = app or request.get_app_name()
    1.33 -
    1.34 -  file_path = file_path or encode.file_path(request.get_app_basepath(),
    1.35 -                                 'app', app, module, chunk)
    1.36 -
    1.37 -
    1.38 -  local func, load_errmsg = loadfile(file_path)
    1.39 -  if not func then
    1.40 -    error('Could not load file "' .. file_path .. '": ' .. load_errmsg)
    1.41 +  local chunk_name
    1.42 +  if args.chunk then
    1.43 +    chunk_name = string.match(args.chunk, "^(.*)%.lua$")
    1.44 +    if not chunk_name then
    1.45 +      error('"chunk_name" does not end with \'.lua\'')
    1.46 +    end
    1.47    end
    1.48 -
    1.49 -  if id or params then
    1.50 -    param.exchange(id, params)
    1.51 -  end
    1.52 -
    1.53 -  local result = func()
    1.54 -
    1.55 -  if id or params then
    1.56 -    param.restore()
    1.57 -  end
    1.58 -
    1.59 -  return result
    1.60 +  return execute.chunk{
    1.61 +    file_path = args.file_path,
    1.62 +    app       = args.app,
    1.63 +    module    = args.module,
    1.64 +    chunk     = chunk_name,
    1.65 +    id        = args.id,
    1.66 +    params    = args.params
    1.67 +  }
    1.68  end

Impressum / About Us