# HG changeset patch # User jbe # Date 1287247535 -7200 # Node ID 209a686464a1b30664adba0763d1871a904b18be # Parent 3c12e7dd93e0f6d037a7fae53222361dcb39c213 Deprecated execute.load_chunk{...} and introduced execute.chunk{...} diff -r 3c12e7dd93e0 -r 209a686464a1 framework/env/execute/chunk.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/framework/env/execute/chunk.lua Sat Oct 16 18:45:35 2010 +0200 @@ -0,0 +1,48 @@ +--[[-- +return_value = -- return value of executed chunk +execute.chunk{ + file_path = file_path, -- path to a lua source or byte-code file + app = app, -- app name to use or the current will be used + module = module, -- module where chunk is located + chunk = chunk -- name of chunk (filename without .lua extension) + id = id, -- id to be returned by param.get_id(...) during execution + params = params -- parameters to be returned by param.get(...) during execution +} + +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. + +--]]-- + +function execute.chunk(args) + local file_path = args.file_path + local app = args.app + local module = args.module + local chunk = args.chunk + local id = args.id + local params = args.params + + app = app or request.get_app_name() + + file_path = file_path or encode.file_path( + request.get_app_basepath(), + 'app', app, module, chunk .. '.lua' + ) + + local func, load_errmsg = loadfile(file_path) + if not func then + error('Could not load file "' .. file_path .. '": ' .. load_errmsg) + end + + if id or params then + param.exchange(id, params) + end + + local result = {func()} + + if id or params then + param.restore() + end + + return unpack(result) +end diff -r 3c12e7dd93e0 -r 209a686464a1 framework/env/execute/load_chunk.lua --- a/framework/env/execute/load_chunk.lua Sat Oct 16 18:04:36 2010 +0200 +++ b/framework/env/execute/load_chunk.lua Sat Oct 16 18:45:35 2010 +0200 @@ -1,47 +1,35 @@ --[[-- -status_code = -- executes and returns a lua file +return_value = -- return value of executed chunk execute.load_chunk{ file_path = file_path, -- path to a lua source or byte-code file app = app, -- app name to use or the current will be used module = module, -- module where chunk is located - chunk = chunk -- filename of lua file to load + chunk = chunk -- filename of lua file to load (including filename extension) id = id, -- id to be returned by param.get_id(...) during execution params = params -- parameters to be returned by param.get(...) during execution } +NOTE: execute.load_chunk{...} is DEPRECATED and replaced by execute.chunk{...}. Both functions differ in interpretation of argument "chunk" regarding the filename extenstion '.lua'. + 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. --]]-- function execute.load_chunk(args) - local file_path = args.file_path - local app = args.app - local module = args.module - local chunk = args.chunk - local id = args.id - local params = args.params - - app = app or request.get_app_name() - - file_path = file_path or encode.file_path(request.get_app_basepath(), - 'app', app, module, chunk) - - - local func, load_errmsg = loadfile(file_path) - if not func then - error('Could not load file "' .. file_path .. '": ' .. load_errmsg) + local chunk_name + if args.chunk then + chunk_name = string.match(args.chunk, "^(.*)%.lua$") + if not chunk_name then + error('"chunk_name" does not end with \'.lua\'') + end end - - if id or params then - param.exchange(id, params) - end - - local result = func() - - if id or params then - param.restore() - end - - return result + return execute.chunk{ + file_path = args.file_path, + app = args.app, + module = args.module, + chunk = chunk_name, + id = args.id, + params = args.params + } end