rev |
line source |
poelzi@31
|
1 --[[--
|
jbe@46
|
2 return_value = -- return value of executed chunk
|
jbe@46
|
3 execute.chunk{
|
jbe@309
|
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
|
jbe@46
|
7 chunk = chunk -- name of chunk (filename without .lua extension)
|
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
|
jbe@205
|
12 This function loads and executes a lua file specified by a given path or constructs 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.
|
poelzi@31
|
13
|
poelzi@31
|
14 --]]--
|
poelzi@31
|
15
|
jbe@205
|
16 local function pack_return_values(...)
|
jbe@205
|
17 local storage = {...}
|
jbe@205
|
18 storage.n = select("#", ...)
|
jbe@230
|
19 return storage
|
jbe@205
|
20 end
|
jbe@205
|
21
|
jbe@205
|
22 local function unpack_return_values(storage)
|
jbe@205
|
23 return table.unpack(storage, 1, storage.n)
|
jbe@205
|
24 end
|
jbe@205
|
25
|
jbe@46
|
26 function execute.chunk(args)
|
poelzi@31
|
27 local file_path = args.file_path
|
jbe@206
|
28 local app = args.app or WEBMCP_APP_NAME
|
poelzi@31
|
29 local module = args.module
|
poelzi@31
|
30 local chunk = args.chunk
|
poelzi@32
|
31 local id = args.id
|
poelzi@32
|
32 local params = args.params
|
poelzi@31
|
33
|
jbe@46
|
34 file_path = file_path or encode.file_path(
|
jbe@206
|
35 WEBMCP_BASE_PATH, 'app', app, module, chunk .. '.lua'
|
jbe@46
|
36 )
|
poelzi@32
|
37
|
jbe@314
|
38 local func = assert(loadcached(file_path))
|
poelzi@32
|
39
|
poelzi@32
|
40 if id or params then
|
poelzi@32
|
41 param.exchange(id, params)
|
poelzi@32
|
42 end
|
poelzi@32
|
43
|
jbe@205
|
44 local result = pack_return_values(func())
|
poelzi@32
|
45
|
poelzi@32
|
46 if id or params then
|
poelzi@32
|
47 param.restore()
|
poelzi@32
|
48 end
|
poelzi@32
|
49
|
jbe@205
|
50 return unpack_return_values(result)
|
poelzi@31
|
51 end
|