How to create config?
How to create config?
Started by Konlab, May 11 2014 04:45 PM
11 replies to this topic
#1
Posted 11 May 2014 - 04:45 PM
#3
Posted 12 May 2014 - 08:47 AM
I have this one based on luaIDE, that loads the config into a table:
If you the want to use the config just:
The config file would look like:
So basically you loaded variables from a file into a table.
local function loadConfig(path)
local f = io.open(path)
local l = f:read("*l")
local config = {}
while l ~= nil do
local k, v = string.match(l, "^(%a+) = (%a+)")
if k and v then config[k] = v end
l = f:read("*l")
end
f:close()
return config
end
If you the want to use the config just:
config = loadCOnfig("myFolders/config")
print( config.firstConfig )
print( config.secondConfig )
print( config.thirdConfig )
The config file would look like:
firstConfig = "Hey, i am line one!" secondConfig = "Hello, i am the second line!" thirdConfig = "Hi, third line here!"
So basically you loaded variables from a file into a table.
#4
Posted 12 May 2014 - 09:00 AM
I also have a version which can be found on my programs page in the APIs section (link in signature) called ccConfig, it can handle other forms of data like numbers, strings, colours, and booleans.
#5
Posted 12 May 2014 - 10:41 AM
theoriginalbit, on 12 May 2014 - 09:00 AM, said:
I also have a version which can be found on my programs page in the APIs section (link in signature) called ccConfig, it can handle other forms of data like numbers, strings, colours, and booleans.
#6
Posted 16 May 2014 - 05:01 PM
RoD, on 12 May 2014 - 08:47 AM, said:
I have this one based on luaIDE, that loads the config into a table:
If you the want to use the config just:
The config file would look like:
So basically you loaded variables from a file into a table.
local function loadConfig(path)
local f = io.open(path)
local l = f:read("*l")
local config = {}
while l ~= nil do
local k, v = string.match(l, "^(%a+) = (%a+)")
if k and v then config[k] = v end
l = f:read("*l")
end
f:close()
return config
end
If you the want to use the config just:
config = loadCOnfig("myFolders/config")
print( config.firstConfig )
print( config.secondConfig )
print( config.thirdConfig )
The config file would look like:
firstConfig = "Hey, i am line one!" secondConfig = "Hello, i am the second line!" thirdConfig = "Hi, third line here!"
So basically you loaded variables from a file into a table.
f:read() io.open() what??? Why : and why io.open what is io... (Input-output I know but how can the io API manage files?)
I don't understand anything what was in your post RoD
I know that, I'm not any pro, then please tell me this as for noob.
Sorry for bad english
#7
Posted 16 May 2014 - 07:16 PM
Konlab, on 16 May 2014 - 05:01 PM, said:
RoD, on 12 May 2014 - 08:47 AM, said:
I have this one based on luaIDE, that loads the config into a table:
If you the want to use the config just:
The config file would look like:
So basically you loaded variables from a file into a table.
local function loadConfig(path)
local f = io.open(path)
local l = f:read("*l")
local config = {}
while l ~= nil do
local k, v = string.match(l, "^(%a+) = (%a+)")
if k and v then config[k] = v end
l = f:read("*l")
end
f:close()
return config
end
If you the want to use the config just:
config = loadCOnfig("myFolders/config")
print( config.firstConfig )
print( config.secondConfig )
print( config.thirdConfig )
The config file would look like:
firstConfig = "Hey, i am line one!" secondConfig = "Hello, i am the second line!" thirdConfig = "Hi, third line here!"
So basically you loaded variables from a file into a table.
f:read() io.open() what??? Why : and why io.open what is io... (Input-output I know but how can the io API manage files?)
I don't understand anything what was in your post RoD
I know that, I'm not any pro, then please tell me this as for noob.
Sorry for bad english
#8
Posted 16 May 2014 - 07:18 PM
I have the answer
Please Lock this topic!
Please Lock this topic!
#10
Posted 16 May 2014 - 07:26 PM
?
#11
Posted 16 May 2014 - 07:29 PM
Basically, if someone else had the same problem and wanted to post here, or if you had more trouble with it, you would have to start a whole new thread because this one is locked. That's why we keep them unlocked, so the section isn't flooded with duplicates as much.
#12
Posted 16 May 2014 - 09:34 PM
Also, for reference, when using the io API and wanting to process individual lines, it is much easier to use the handle:lines() iterator than to use a while loop and handle:read("*l").
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











