Re: Detecting proper framebuffers
Posted: Tue May 03, 2011 10:41 pm
Thanks, man, I've been meaning to rewrite that function.
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
Code: Select all
pcall(func, args, ...)
Code: Select all
pcall(func(args, ...))
Code: Select all
local original = love.graphics.newFramebuffer
function love.graphics.newFramebuffer(...)
local ok, ret = pcall(original, ...)
return ok and ret or nil
end
Showoff.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..
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)