lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 31 May 2010 04:19, Tom <tom.wieland@gmail.com> wrote:
> Hello.
>
> When I recently was configuring Xavante to run an orbit app I found
> that the example configuration posted on the site doesn't work with
> the current Xavante API.
>
> The code mentioned is:
>
>    { -- cgiluahandler example
>      match = {"%.lp$", "%.lp/.*$", "%.lua$", "%.lua/.*$" },
>      with = xavante.cgiluahandler.makeHandler (webDir)
>    },
>
> which should be
>
>    { -- cgiluahandler example
>      match = {"%.lp$", "%.lp/.*$", "%.lua$", "%.lua/.*$" },
>      with = xavante.cgiluahandler.makeHandler (webDir, {})
>    },
>
> The error I got:
>
> ...m/.luarocks/share/lua/5.1//xavante/cgiluahandler.lua:37: attempt to
> index local 'params' (a nil value)
>
> With the definition of the function that the line belongs to of:
>
> function makeHandler (diskpath, params)
>   params = setmetatable({ modname = params.modname or "wsapi.sapi",
> bootstrap = bootstrap }, { __index = params or {} })
>   local sapi_loader = wsapi.common.make_isolated_launcher(params)
>   return wsapi.xavante.makeHandler(sapi_loader, nil, diskpath)
> end
>
> makes me suggest to write it as:
>
> function makeHandler (diskpath, params)
>   params = params or {}
>   params = setmetatable({ modname = params.modname or "wsapi.sapi",
> bootstrap = bootstrap }, { __index = params or {} })
>   local sapi_loader = wsapi.common.make_isolated_launcher(params)
>   return wsapi.xavante.makeHandler(sapi_loader, nil, diskpath)
> end
>
> Or would this be considered bad coding practice?
>
> gr,
>
> Tom Wieland
>

The change should probably be:
 modname = (params or { }).modname or "wsapi.sapi"
or you can take out the "params or { }" already in the code.
The fact that that is already in there suggests to me that the
"modname" thing is new...

Quae