webmcp
view framework/env/execute/load_chunk.lua @ 38:3480a11da8e8
fix doc and depricated api use
| author | Daniel Poelzleithner <poelzi@poelzi.org> | 
|---|---|
| date | Wed Oct 13 20:48:44 2010 +0200 (2010-10-13) | 
| parents | e31af860e97c | 
| children | 209a686464a1 | 
 line source
     1 --[[--
     2 status_code =             -- executes and returns a lua file
     3 execute.load_chunk{
     4   file_path = file_path,  -- path to a lua source or byte-code file
     5   app       = app,        -- app name to use or the current will be used
     6   module    = module,     -- module where chunk is located
     7   chunk     = chunk       -- filename of lua file to load 
     8   id        = id,         -- id to be returned by param.get_id(...) during execution
     9   params    = params      -- parameters to be returned by param.get(...) during execution
    10 }
    12 This function loads and executes a lua file specified by a given path or constructs 
    13 a path to load from the module and chunk name.
    15 --]]--
    17 function execute.load_chunk(args)
    18   local file_path = args.file_path
    19   local app       = args.app
    20   local module    = args.module
    21   local chunk     = args.chunk
    22   local id        = args.id
    23   local params    = args.params
    25   app = app or request.get_app_name()
    27   file_path = file_path or encode.file_path(request.get_app_basepath(),
    28                                  'app', app, module, chunk)
    31   local func, load_errmsg = loadfile(file_path)
    32   if not func then
    33     error('Could not load file "' .. file_path .. '": ' .. load_errmsg)
    34   end
    36   if id or params then
    37     param.exchange(id, params)
    38   end
    40   local result = func()
    42   if id or params then
    43     param.restore()
    44   end
    46   return result
    47 end
