Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fileLocation = "config.txt"
- local rawFile = io.open(fileLocation,"rb")
- local currentLine = ""
- local configValues = {}
- local tempTable = {}
- local stringToData = {
- ["true"] = true,
- ["false"] = false,
- ["nil"] = nil
- }
- local function stripString(inputString, splitChar)
- --[[
- Takes in a string, removes all characters that match the
- splitChar, and outputs a table of strings from where the
- splitChar was.
- --]]
- local outputTable = {}
- local tempString = ""
- if not type(inputString) == "string" then
- print("stripString: input not string")
- goto skip
- end
- for index = 1, #inputString, 1 do
- if string.sub(inputString,index,index) == splitChar then
- table.insert(outputTable,tempString)
- tempString = ""
- goto continue
- end
- tempString = tempString .. string.sub(inputString,index,index)
- ::continue::
- end
- table.insert(outputTable,tempString)
- ::skip::
- return outputTable
- end
- local function cullString(inputString, cullChar)
- --[[
- Takes in a string and removes all instances of a character
- from it
- --]]
- local tempString = ""
- local tempChar = ""
- for index = 1, string.len(inputString), 1 do
- tempChar = string.sub(inputString,index,index)
- if tempChar ~= cullChar then
- tempString = tempString .. tempChar
- end
- end
- return tempString
- end
- local function loadConfig()
- --[[
- Wipes the stored config and reloads it
- --]]
- configValues = {}
- rawFile = io.open(fileLocation,"rb")
- while currentLine ~= nil do
- currentLine = rawFile:read("*line")
- tempTable = stripString(currentLine, "=")
- if #tempTable = 2 then
- if stringToData[tempTable[2]] == nil then
- configValues[cullString(tempTable[1]," ")] = tempTable[2]
- else
- configValues[cullString(tempTable[1]," ")] = stringToData[tempTable[2]]
- end
- end
- end
- io.close(rawFile)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement