webmcp

view framework/env/execute/chunk.lua @ 412:7d43be9afa56

Improved memory cleanup in case of out-of-memory errors (PQnotifies and PQunescapeBytea)
author jbe
date Fri Jan 08 03:10:33 2016 +0100 (2016-01-08)
parents ba68ef9e7c90
children
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 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.
14 --]]--
16 local function pack_return_values(...)
17 local storage = {...}
18 storage.n = select("#", ...)
19 return storage
20 end
22 local function unpack_return_values(storage)
23 return table.unpack(storage, 1, storage.n)
24 end
26 function execute.chunk(args)
27 local file_path = args.file_path
28 local app = args.app or WEBMCP_APP_NAME
29 local module = args.module
30 local chunk = args.chunk
31 local id = args.id
32 local params = args.params
34 file_path = file_path or encode.file_path(
35 WEBMCP_BASE_PATH, 'app', app, module, chunk .. '.lua'
36 )
38 local func = assert(loadcached(file_path))
40 if id or params then
41 param.exchange(id, params)
42 end
44 local result = pack_return_values(func())
46 if id or params then
47 param.restore()
48 end
50 return unpack_return_values(result)
51 end

Impressum / About Us