Last active
April 29, 2020 11:00
-
-
Save callumbrieske/31326c7c54c91c2af72afff9c009f004 to your computer and use it in GitHub Desktop.
Q-Sys File IO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
json = require("rapidjson") | |
myData = { | |
valuea = "This is value a", | |
valueb = "This is value b", | |
valuec = "This is value c", | |
} | |
-- | |
-- We can create/overwrite a file like this: | |
-- | |
dataFile = io.open("media/configData.dat", "w+") -- Open the file 'configData.dat' in 'overwrite' mode. | |
dataFile:write(json.encode(myData, {pretty = true})) -- Write our data table to this file as JSON. | |
dataFile:close() -- Close our file. We should always do this when finished. | |
-- | |
-- To read our file back, we can do this: | |
-- | |
dataFile = io.open("media/configData.dat", "r") -- Open the file 'configData.dat' in 'read' mode. | |
print("Our file contains:", dataFile:read("*a")) -- Print the contents of the file. Alternatively, we could use json.decode(dataFile:read("*a")) to get our original table back. | |
dataFile:close() -- Close our file. We should always do this when finished. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment