This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
How to create config?
Started by Konlab, 11 May 2014 - 03:45 PMPosted 11 May 2014 - 05:45 PM
How to create config?
Posted 11 May 2014 - 05:56 PM
I assume you mean creating config files for your own programs. Have a look at the fs API, fs.open specifically.
Posted 12 May 2014 - 09: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.
Posted 12 May 2014 - 10: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.
Posted 12 May 2014 - 11:41 AM
Its pretty usefull. I might test it soon. :)/>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.
Posted 16 May 2014 - 06:01 PM
I have this one based on luaIDE, that loads the config 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
Posted 16 May 2014 - 08:16 PM
Please take a look at the cc wiki page or the Lua reference manual page for the IO API.I have this one based on luaIDE, that loads the config 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
Posted 16 May 2014 - 08:18 PM
I have the answer
Please Lock this topic!
Please Lock this topic!
Posted 16 May 2014 - 08:24 PM
We usually don't lock AaP section threads in case someone has a similar/continued issue (in a non-hijacking way)I have the answer
Please Lock this topic!
Posted 16 May 2014 - 08:26 PM
?
Posted 16 May 2014 - 08: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.
Posted 16 May 2014 - 10: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").