LOVE API naming discuss

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
TsT
Party member
Posts: 161
Joined: Thu Sep 25, 2008 7:04 pm
Location: France
Contact:

LOVE API naming discuss

Post by TsT »

Hello,

I understanding the lua "love" object was constructed like the love module names.

But I think some functions have a better place outside of their real module name.

I suggest to move every screen functions into a separated love.screen like :
love.graphics.getCaption -> love.screen.getCaption
love.graphics.setCaption -> love.screen.setCaption
love.graphics.checkMode -> love.screen.checkMode
love.graphics.getModes -> love.screen.getMode
love.graphics.setMode -> love.screen.setMode
love.graphics.toggleFullscreen -> love.screen.toggleFullscreen
love.graphics.getHeight -> love.screen.getHeight
love.graphics.getWidth -> love.screen.getWidth

What is your opinion ?
Last edited by TsT on Mon Apr 25, 2011 1:36 am, edited 1 time in total.
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: LOVE API naming discuss

Post by BlackBulletIV »

I don't think it's a good idea. There's only one module that affects the "screen" (it's actually the window), and that is love.graphics.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: LOVE API naming discuss

Post by thelinx »

There's an issue on the issue tracker for a "love.window" module that would hold these functions and more.
User avatar
TsT
Party member
Posts: 161
Joined: Thu Sep 25, 2008 7:04 pm
Location: France
Contact:

Re: LOVE API naming discuss

Post by TsT »

I just read the love.window issue.
That's speaking more about be able to manage more than one uniq love window.

I supposed the API of love.window was not defined yet ?
If already defined we should build a quick lua script to implement them in forward-compatibility.
like

Code: Select all

if love and not love.window then
  love.window = {}
  local t = {"getCaption", "setCaption", "checkMode", "getMode", "setMode", "toggleFullscreen", "getHeight", "getWidth"}
  table.foreach(t, function(i, f)
    if love.graphics[f] then love.window[f] = love.graphics[f] end
  end)
end
Regards,
My projects current projects : dragoon-framework (includes lua-newmodule, lua-provide, lovemodular, , classcommons2, and more ...)
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: LOVE API naming discuss

Post by bmelts »

The issue is in the version of SDL that LÖVE uses (1.2), there's not a lot of distinction drawn between the SDL window and the OpenGL context that actually handles the drawing; breaking them apart in the API is non-trivial.

When (if) SDL 1.3 comes out and LÖVE upgrades, the window will be treated as a separate entity, and the window-related functions can be moved to a more appropriately-named module.
User avatar
TsT
Party member
Posts: 161
Joined: Thu Sep 25, 2008 7:04 pm
Location: France
Contact:

Re: LOVE API naming discuss

Post by TsT »

Ok I think understanding the complexity of the problem...
But It should be possible to start thinking a simple API for love.window
like the joystick or thread management :

Code: Select all

love.window.getWindow() -- get the current window handler
love.window.getWindow(name) -- get a specific window handler, the default love window is "main"
love.window.getNumWindows() -- return number of windows (actually 1)
love.window.getWindows() -- return the table of windows (like getThreads does)
love.window.newWindow(name) -- create a new windows, actually raise an error.
I'm sad to see love games become unplayable (0.5.x games for example).
I know why and know there are some compatibility scripts (good work!).
It's normal that the love's API changes.
Some changes are due to major evolution.
But when I see the love.graphics functions listed below, I wonder why keeping them ? why waiting ?

I'm sure it's possible to provide a clearer API since now.
And guest to wrote game that will run in next version (0.8.x ?) even the window management will be completely changed internally.

Of course all of my thinks are based on :
- love.graphics.setMode (and all others listed below) are not in best place
- theses functions will be removed from love.graphics when a better place will be found (and break compatibility).

If I'm wrong, and theses functions are planned to be kept in place for long time, we can forget this topic ;-)

Regards,


implementation for actual love (0.7.1) :

Code: Select all

love.window = {}

local prepare = function()
        local m = {}

        -- list of the love.graphics functions to copy
        local tocopy = {"getCaption", "setCaption", "checkMode", "getMode", "setMode", "toggleFullscreen", "getHeight", "getWidth"}

        for i,f in ipairs(tocopy) do
                if love.graphics and love.graphics[f] then
                        m[f] = love.graphics[f]
                end
        end

        return m
end

local internaldata = {}
internaldata.defaultwindow = "main"
internaldata.windows = { internaldata.defaultwindow }
internaldata.mainwinhandler = prepare()

love.window.getWindow = function(name)
        name = name or "main"
        if name == "main" then
                return internaldata.mainwinhandler
        end
        error("Unknown window name")
end

love.window.getNumWindows = function()
        return #internaldata.windows
end

love.window.getWindows = function()
        return internaldata.windows
end

love.window.newWindow = function(...)
        error("newWindow not available yet")
end
Sample of use

Code: Select all

function love.load()
  require("love.window")
  local window = love.window.getWindow()
  window.setCaption("foo bar")
end
My projects current projects : dragoon-framework (includes lua-newmodule, lua-provide, lovemodular, , classcommons2, and more ...)
User avatar
schme16
Party member
Posts: 127
Joined: Thu Oct 02, 2008 2:46 am

Re: LOVE API naming discuss

Post by schme16 »

You could always just make pointers to those objects that you feel should be renamed and create a `screen` module yourself

i.e

Code: Select all

love.screen = {
	getCaption = love.graphics.getCaption,
	setCaption = love.graphics.setCaption,
	checkMode = love.graphics.checkMode,
	getMode = love.graphics.getModes,
	setMode = love.graphics.setMode,
	toggleFullscreen = love.graphics.toggleFullscreen,
	getHeight = love.graphics.getHeight,
	getWidth = love.graphics.getWidth,
}


or for those that want it as window

love.window= {
	getCaption = love.graphics.getCaption,
	setCaption = love.graphics.setCaption,
	checkMode = love.graphics.checkMode,
	getMode = love.graphics.getModes,
	setMode = love.graphics.setMode,
	toggleFullscreen = love.graphics.toggleFullscreen,
	getHeight = love.graphics.getHeight,
	getWidth = love.graphics.getWidth,
}


This method at least still gives you backward compatibility.
My Development Diary - http://shanegadsby.info
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: LOVE API naming discuss

Post by BlackBulletIV »

Well if there were multiple windows, that would be a different story. And it would be pretty cool too.
User avatar
TsT
Party member
Posts: 161
Joined: Thu Sep 25, 2008 7:04 pm
Location: France
Contact:

Re: LOVE API naming discuss

Post by TsT »

Hello schme16,
I read quickly your sentence
schme16 wrote:...create a `screen` module yourself
And decide "Let's do it myself ! and see after done what is good to keep..."

I will probably think about made relation between love.screen and love.window.
But for now I'm happy to release my first love.screen module version !

Have fun!
My projects current projects : dragoon-framework (includes lua-newmodule, lua-provide, lovemodular, , classcommons2, and more ...)
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: LOVE API naming discuss

Post by Jasoco »

BlackBulletIV wrote:Well if there were multiple windows, that would be a different story. And it would be pretty cool too.
Sadly they've had that discussion before and it probably won't happen.
Post Reply

Who is online

Users browsing this forum: No registered users and 82 guests