Page 1 of 1

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

Posted: Wed Apr 27, 2016 7:27 am
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

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

Posted: Wed Apr 27, 2016 8:11 am
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

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

Posted: Wed Apr 27, 2016 8:19 am
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')