webmcp

changeset 205:48ee8826efbe

Correct handling of nil's in return tuples in execute.chunk{...}
author jbe
date Fri Jan 09 21:32:23 2015 +0100 (2015-01-09)
parents b059efd81649
children eb3e236d261d
files framework/env/execute/chunk.lua
line diff
     1.1 --- a/framework/env/execute/chunk.lua	Fri Jan 09 04:54:50 2015 +0100
     1.2 +++ b/framework/env/execute/chunk.lua	Fri Jan 09 21:32:23 2015 +0100
     1.3 @@ -9,11 +9,19 @@
     1.4    params    = params      -- parameters to be returned by param.get(...) during execution
     1.5  }
     1.6  
     1.7 -This function loads and executes a lua file specified by a given path or constructs 
     1.8 -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.
     1.9 +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.
    1.10  
    1.11  --]]--
    1.12  
    1.13 +local function pack_return_values(...)
    1.14 +  local storage = {...}
    1.15 +  storage.n = select("#", ...)
    1.16 +end
    1.17 +
    1.18 +local function unpack_return_values(storage)
    1.19 +  return table.unpack(storage, 1, storage.n)
    1.20 +end
    1.21 +
    1.22  function execute.chunk(args)
    1.23    local file_path = args.file_path
    1.24    local app       = args.app
    1.25 @@ -38,11 +46,11 @@
    1.26      param.exchange(id, params)
    1.27    end
    1.28  
    1.29 -  local result = {func()}
    1.30 +  local result = pack_return_values(func())
    1.31  
    1.32    if id or params then
    1.33      param.restore()
    1.34    end
    1.35  
    1.36 -  return table.unpack(result)
    1.37 +  return unpack_return_values(result)
    1.38  end

Impressum / About Us