[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Xavate crash and coxpcall missing 'arg' variable
- From: Romulo Bahiense <romulo@...>
- Date: Mon, 16 May 2005 17:27:35 -0300
remove the changes you did and post the whole error message;
D:\lib\Xavante\xavante-1.1b\bin>lua
Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio
> require 'start'
D:\b\bin\coxpcall.lua:19: bad argument #1 to `unpack' (table expected,
got nil)
stack traceback:
[C]: in function `unpack'
D:\b\bin\coxpcall.lua:19: in function `coxpcall'
(tail call): ?
xavante/server.lua:65: in function `start'
start.lua:35: in main chunk
[C]: in function `require'
stdin:1: in main chunk
[C]: ?
start.lua -> t_xavante_start.lua
As attachment, unmodified coxpcall.lua .
> i'll try to determine the real troubling line.
I don't know if you looked at the commented source I sent in the first
post, but the problem is that coxpcall is attempting to read/write to
'arg', and there is no 'arg' in coxpcall. Also, I don't know where to
take it because, in theory, xpcall don't have extra arguments; just two.
Thanks,
Romulo.
-------------------------------------------------------------------------------
-- Coroutine safe xpcall and pcall versions
--
-- Encapsulates the protected calls with a coroutine based loop, so errors can
-- be dealed without the usual Lua 5.0 pcall/xpcall issues with coroutines
-- yielding inside the call to pcall or xpcall.
--
-- Authors: Roberto Ierusalimschy and Andre Carregal
--
-- Copyright 2005 - Kepler Project (www.keplerproject.org)
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Implements xpcall with coroutines
-------------------------------------------------------------------------------
function coxpcall(f, err)
local co = coroutine.create(f)
while true do
local results = {coroutine.resume(co , unpack(arg) )}
local status = results[1]
table.remove (results, 1) -- remove status of coroutine.resume
if not status then
return false, err(unpack(results))
end
if coroutine.status(co) == "suspended" then
arg = {coroutine.yield(unpack(results))}
else
return true, unpack(results)
end
end
end
-------------------------------------------------------------------------------
-- Implements pcall with coroutines
-------------------------------------------------------------------------------
function copcall(f, ...)
return coxpcall(function() return f(unpack(arg)) end, error)
end