poelzi@31: --[[-- jbe@46: return_value = -- return value of executed chunk jbe@46: execute.chunk{ poelzi@31: file_path = file_path, -- path to a lua source or byte-code file poelzi@31: app = app, -- app name to use or the current will be used poelzi@31: module = module, -- module where chunk is located jbe@46: chunk = chunk -- name of chunk (filename without .lua extension) poelzi@32: id = id, -- id to be returned by param.get_id(...) during execution poelzi@32: params = params -- parameters to be returned by param.get(...) during execution poelzi@31: } poelzi@31: poelzi@31: This function loads and executes a lua file specified by a given path or constructs jbe@46: 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: poelzi@31: --]]-- poelzi@31: jbe@46: function execute.chunk(args) poelzi@31: local file_path = args.file_path poelzi@31: local app = args.app poelzi@31: local module = args.module poelzi@31: local chunk = args.chunk poelzi@32: local id = args.id poelzi@32: local params = args.params poelzi@31: poelzi@31: app = app or request.get_app_name() poelzi@31: jbe@46: file_path = file_path or encode.file_path( jbe@46: request.get_app_basepath(), jbe@46: 'app', app, module, chunk .. '.lua' jbe@46: ) poelzi@32: poelzi@31: local func, load_errmsg = loadfile(file_path) poelzi@31: if not func then poelzi@31: error('Could not load file "' .. file_path .. '": ' .. load_errmsg) poelzi@31: end poelzi@32: poelzi@32: if id or params then poelzi@32: param.exchange(id, params) poelzi@32: end poelzi@32: jbe@46: local result = {func()} poelzi@32: poelzi@32: if id or params then poelzi@32: param.restore() poelzi@32: end poelzi@32: jbe@46: return unpack(result) poelzi@31: end