Question

How can I use config.lua or other configuration settings for a specific file not whole files in a program? I want to use the code below only for a specific lua file in the file.I am using corona SDK.

 application =
{
    content =
    {
            width = 320,
            height = 480, 
            scale = "letterbox",
            fps = 60,
    },
 }
Was it helpful?

Solution

You could use loadfile and setfenv (Lua 5.1).

local f=loadfile("config.lua")
local env={}
setfenv( f, env )
f()
local config=env.application

If you have control over the format of the config file, you could also formulate it to return the table rather than declare it globally:

local application =
{
    content =
    {
        width = 320,
        height = 480, 
        scale = "letterbox",
        fps = 60,
    },
 }
 return application

Then to load it:

local config=dofile("config.lua")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top