Page 2 of 2

Re: Detecting proper framebuffers

Posted: Tue May 03, 2011 10:41 pm
by Ertain
Thanks, man, I've been meaning to rewrite that function.

Re: Detecting proper framebuffers

Posted: Wed May 04, 2011 9:00 am
by TsT
Why not patching the love API with a internal error catching ?
Something like :

Code: Select all

if not love.graphics.newFramebufferOriginal then
  love.graphics.newFramebufferOriginal = love.graphics.newFramebuffer
  love.graphics.newFramebuffer = function(...)
    local ok, ret = pcall(love.graphics.newFramebufferOriginal(...))
    if ok then
      return ret
    end
    return nil
  end
end

Re: Detecting proper framebuffers

Posted: Wed May 04, 2011 9:58 am
by BlackBulletIV
Remember! pcall operates like this:

Code: Select all

pcall(func, args, ...)
not

Code: Select all

pcall(func(args, ...))
It could also be more cleanly done like:

Code: Select all

local original = love.graphics.newFramebuffer

function love.graphics.newFramebuffer(...)
  local ok, ret = pcall(original, ...)
  return ok and ret or nil
end

Re: Detecting proper framebuffers

Posted: Wed May 04, 2011 10:03 am
by bartbes
I actually had a library that wrapped functions (and even tables) with a single command.. I think it was on the old wiki though..

Re: Detecting proper framebuffers

Posted: Wed May 04, 2011 1:49 pm
by Lafolie
bartbes wrote:I actually had a library that wrapped functions (and even tables) with a single command.. I think it was on the old wiki though..
Showoff. :megagrin:

But really, how did that work? *is interested*

Re: Detecting proper framebuffers

Posted: Thu May 05, 2011 7:24 am
by vrld
Probably something like this:

Code: Select all

function pwrap(func)
    return function(...)
        local ret = {pcall(func, ...)}
        local ok = table.remove(ret, 1)
        if not ok then return nil, ret[1] end
        return unpack(ret)
    end
end

-- call it like so:
love.graphics.newFramebuffer = pwrap(love.graphics.newFramebuffer)