Thought someone might find this useful or even just something fun to play around with in terms of cleaning up code.
Code: Select all
function saveFunc(funcName)
local file = findTableFile(funcName)
if file then file.Delete() end
file = createTableFile(funcName)
local bytes = stringToByteTable(encodeFunction(_G[funcName]))
file.Stream.Position = 0
file.Stream.write(bytes,#bytes)
end
Code: Select all
function readFunc(name)
local file = findTableFile(name)
if file == nil then return nil end
local stringStream = createStringStream()
stringStream.copyFrom(file.Stream,file.Stream.Size)
local funcTxt = stringStream.DataString
stringStream.destroy()
return decodeFunction(funcTxt)
end
Code: Select all
function saveScript(scriptName,funcEnable,funcDisable)
if scriptName == nil or funcEnable == nil or funcDisable == nil then return nil end
local file = findTableFile(scriptName)
if file then file.Delete() end
file = createTableFile(scriptName)
local bytes = stringToByteTable(encodeFunction(funcEnable).."\n"..encodeFunction(funcDisable))
file.Stream.Position = 0
file.Stream.write(bytes,#bytes)
end
Code: Select all
function readScript(name)
local file = findTableFile(name)
if file == nil then return nil end
local stringStream = createStringStream()
local funcList = createStringList()
stringStream.copyFrom(file.Stream,file.Stream.Size)
funcList.text = stringStream.DataString
local enable = decodeFunction(funcList[0])
local disable = decodeFunction(funcList[1])
stringStream.destroy()
funcList.destroy()
return {enable,disable}
end