webmcp
view framework/env/execute/load_chunk.lua @ 31:1cd9e69b85cb
add execute.load_chunk(args)
load_chunk loads the content of a lua file and returns the code.
It can construct the path name easily so you can put helper code in
seperate files for DRYness.
load_chunk loads the content of a lua file and returns the code.
It can construct the path name easily so you can put helper code in
seperate files for DRYness.
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Tue Oct 05 02:34:04 2010 +0200 (2010-10-05) |
parents | |
children | e31af860e97c |
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 }
10 This function loads and executes a lua file specified by a given path or constructs
11 a path to load from the module and chunk name.
13 --]]--
15 function execute.load_chunk(args)
16 local file_path = args.file_path
17 local app = args.app
18 local module = args.module
19 local chunk = args.chunk
21 app = app or request.get_app_name()
23 file_path = file_path or encode.file_path(request.get_app_basepath(),
24 'app', app, module, chunk)
26 local func, load_errmsg = loadfile(file_path)
27 if not func then
28 error('Could not load file "' .. file_path .. '": ' .. load_errmsg)
29 end
30 local result = func()
31 return result
32 end