Reputation: 101
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,
},
}
Upvotes: 2
Views: 1013
Reputation: 526
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")
Upvotes: 4