webmcp
annotate framework/env/execute/load_chunk.lua @ 36:5380305a3d51
allow multiple arguments to trace.debug
you can now write trace.debug("bla", 2, ...)
you can now write trace.debug("bla", 2, ...)
| author | Daniel Poelzleithner <poelzi@poelzi.org> |
|---|---|
| date | Sat Oct 09 00:57:26 2010 +0200 (2010-10-09) |
| parents | e31af860e97c |
| children | 209a686464a1 |
| rev | line source |
|---|---|
| poelzi@31 | 1 --[[-- |
| poelzi@31 | 2 status_code = -- executes and returns a lua file |
| poelzi@31 | 3 execute.load_chunk{ |
| poelzi@31 | 4 file_path = file_path, -- path to a lua source or byte-code file |
| poelzi@31 | 5 app = app, -- app name to use or the current will be used |
| poelzi@31 | 6 module = module, -- module where chunk is located |
| poelzi@31 | 7 chunk = chunk -- filename of lua file to load |
| poelzi@32 | 8 id = id, -- id to be returned by param.get_id(...) during execution |
| poelzi@32 | 9 params = params -- parameters to be returned by param.get(...) during execution |
| poelzi@31 | 10 } |
| poelzi@31 | 11 |
| poelzi@31 | 12 This function loads and executes a lua file specified by a given path or constructs |
| poelzi@31 | 13 a path to load from the module and chunk name. |
| poelzi@31 | 14 |
| poelzi@31 | 15 --]]-- |
| poelzi@31 | 16 |
| poelzi@31 | 17 function execute.load_chunk(args) |
| poelzi@31 | 18 local file_path = args.file_path |
| poelzi@31 | 19 local app = args.app |
| poelzi@31 | 20 local module = args.module |
| poelzi@31 | 21 local chunk = args.chunk |
| poelzi@32 | 22 local id = args.id |
| poelzi@32 | 23 local params = args.params |
| poelzi@31 | 24 |
| poelzi@31 | 25 app = app or request.get_app_name() |
| poelzi@31 | 26 |
| poelzi@31 | 27 file_path = file_path or encode.file_path(request.get_app_basepath(), |
| poelzi@31 | 28 'app', app, module, chunk) |
| poelzi@31 | 29 |
| poelzi@32 | 30 |
| poelzi@31 | 31 local func, load_errmsg = loadfile(file_path) |
| poelzi@31 | 32 if not func then |
| poelzi@31 | 33 error('Could not load file "' .. file_path .. '": ' .. load_errmsg) |
| poelzi@31 | 34 end |
| poelzi@32 | 35 |
| poelzi@32 | 36 if id or params then |
| poelzi@32 | 37 param.exchange(id, params) |
| poelzi@32 | 38 end |
| poelzi@32 | 39 |
| poelzi@31 | 40 local result = func() |
| poelzi@32 | 41 |
| poelzi@32 | 42 if id or params then |
| poelzi@32 | 43 param.restore() |
| poelzi@32 | 44 end |
| poelzi@32 | 45 |
| poelzi@31 | 46 return result |
| poelzi@31 | 47 end |