webmcp
view framework/env/execute/chunk.lua @ 198:bb298fc60952
Fixed inline documentation of slot.put_into(...)
| author | jbe | 
|---|---|
| date | Mon Aug 11 22:57:23 2014 +0200 (2014-08-11) | 
| parents | 3d43a5cf17c1 | 
| children | 48ee8826efbe | 
 line source
     1 --[[--
     2 return_value =            -- return value of executed chunk
     3 execute.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       -- name of chunk (filename without .lua extension)
     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. 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.
    15 --]]--
    17 function execute.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(
    28     request.get_app_basepath(),
    29     'app', app, module, chunk .. '.lua'
    30   )
    32   local func, load_errmsg = loadfile(file_path)
    33   if not func then
    34     error('Could not load file "' .. file_path .. '": ' .. load_errmsg)
    35   end
    37   if id or params then
    38     param.exchange(id, params)
    39   end
    41   local result = {func()}
    43   if id or params then
    44     param.restore()
    45   end
    47   return table.unpack(result)
    48 end
