Detecting proper framebuffers

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Ertain
Citizen
Posts: 55
Joined: Fri Nov 19, 2010 9:38 pm
Location: Texas, U.S.A.

Re: Detecting proper framebuffers

Post by Ertain »

Thanks, man, I've been meaning to rewrite that function.
Booted, suited, and ready to get executed.
User avatar
TsT
Party member
Posts: 161
Joined: Thu Sep 25, 2008 7:04 pm
Location: France
Contact:

Re: Detecting proper framebuffers

Post 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
My projects current projects : dragoon-framework (includes lua-newmodule, lua-provide, lovemodular, , classcommons2, and more ...)
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Detecting proper framebuffers

Post 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
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Detecting proper framebuffers

Post 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..
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Detecting proper framebuffers

Post 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*
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Detecting proper framebuffers

Post 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)
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Post Reply

Who is online

Users browsing this forum: Bing [Bot], DOMINOSRULZ and 97 guests