Is it possible to pass custom property from conf.lua to main.lua

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.
Post Reply
bitinn
Prole
Posts: 8
Joined: Sun Apr 10, 2016 9:44 am

Is it possible to pass custom property from conf.lua to main.lua

Post by bitinn »

Furthermore, can we access t during love.load?

Obviously we can have a global variable, but that seems like an overkill if I just want to parse some command line arguments at conf.lua stage and pass it onto main.lua
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Is it possible to pass custom property from conf.lua to main.lua

Post by airstruck »

bitinn wrote:Is it possible to pass custom property from conf.lua to main.lua
The return value from conf.lua (if any) ends up in package.loaded.conf, so you can return something from conf.lua and then require 'conf' in main.lua (or another file) to get that value. You won't be able to return "t," though, for obvious reasons.
bitinn wrote:Furthermore, can we access t during love.load?
You could define love.load inside of love.conf.

Code: Select all

function love.conf (t)
    t.window.width = 300
    t.window.height = 200
    function love.load ()
        print(t.window.width, t.window.height)
    end
end
bitinn
Prole
Posts: 8
Joined: Sun Apr 10, 2016 9:44 am

Re: Is it possible to pass custom property from conf.lua to main.lua

Post by bitinn »

Ah thx, with require('conf') we can do what we want with this:

Code: Select all

-- in conf.lua
local conf = {}
conf.args = args

function love.conf (t)
  -- other config
  conf.t = t
end

return conf

-- in main.lua
local conf = require('conf')
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests