How to access to the values in config.lua

In my main.lua I would like read some values I put in the config.lua (or build.settings). Is it possible to get them? Thanks

Like what?  The width and height are:  display.contentWidth and display.contentHeight.  There are ways to find the image suffix and the scale factor, which is most of the things in config.lua. 

Most of the things in build.settings, I can’t think of a way to get to those.

I don’t know if it’s possible but it was to avoid modify main.lua direclty, I would like get my values from there :

application =
{
        content =
        {
                width = 320,
                height = 480,
                scale = “letterbox”,
        },
        
        data = – How to get them from main.lua? It’s like a config file for the application
        {
            value1 = 10,
            value2 = 20, — etc…
        }
}

You should not be putting things in config.lua that are not designed to go there.  The data isn’t visible as is to your app.  It has to be exposed through API calls.   The best thing is to read this blog post:

http://www.coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

And implement your own “data” structure like the myData bits talked about in that article.

Ok, I already use data like in the article, I just wanted to know another way but yes it’s certainly not a good idea :slight_smile: Thanks

Like what?  The width and height are:  display.contentWidth and display.contentHeight.  There are ways to find the image suffix and the scale factor, which is most of the things in config.lua. 

Most of the things in build.settings, I can’t think of a way to get to those.

I don’t know if it’s possible but it was to avoid modify main.lua direclty, I would like get my values from there :

application =
{
        content =
        {
                width = 320,
                height = 480,
                scale = “letterbox”,
        },
        
        data = – How to get them from main.lua? It’s like a config file for the application
        {
            value1 = 10,
            value2 = 20, — etc…
        }
}

You should not be putting things in config.lua that are not designed to go there.  The data isn’t visible as is to your app.  It has to be exposed through API calls.   The best thing is to read this blog post:

http://www.coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

And implement your own “data” structure like the myData bits talked about in that article.

Ok, I already use data like in the article, I just wanted to know another way but yes it’s certainly not a good idea :slight_smile: Thanks

Accessing the config.lua may be useful for specific functions. Like, I need to adapt all my libraries to support graphics 2.0 but also make the previous version available if the project is using the flag graphicsCompatibility = 1 inside the config.lua.

I found that that the application table inside config.lua is loaded as a global, so you can access it using _G.application

EDIT: Before accessing the _G.application, you need to do load the config.lua by doing (local config = require “config”)

I would not change any values there.  That is unsupported and who knows what kind of problems it will cause.

Rob

Accessing the config.lua may be useful for specific functions. Like, I need to adapt all my libraries to support graphics 2.0 but also make the previous version available if the project is using the flag graphicsCompatibility = 1 inside the config.lua.

I found that that the application table inside config.lua is loaded as a global, so you can access it using _G.application

EDIT: Before accessing the _G.application, you need to do load the config.lua by doing (local config = require “config”)

I would not change any values there.  That is unsupported and who knows what kind of problems it will cause.

Rob