How to load .txt data into Lua?

Pretty much, I’m making a gamemode and I want to load .txt data into the gamemode. How would I achieve this?

One way that my friend did this was by runstring’ing the stuff read from a text file which had a bunch of tables in Lua format, but that seems a bit hacky and unsafe.

Is there a better way?

Should I even use .txt files to do this and instead, just define all the data in a .lua file or something?

Any help or useful input is appreciated.


local tbl = {}

function SaveData()
	file.Write("gamemodedata.txt",util.TableToJSON(tbl)) -- save the table as a text file
end

function LoadData()
	tbl = util.JSONToTable(file.Read("gamemodedata.txt", "DATA")) -- load the table.
end

LoadData() -- call LoadData() to load the data for the first time

Though it’s better to use MySQL/SQLite

What kind of data?
Config? Use Lua.

Oh shoot, forgot to mention, sorry.

It’s stuff like map data, aka spawnpoints of entities, etc. So pretty much config I guess.

What would using Lua offer over a .txt though? Other than making it easier to do stuff I guess, and maybe speed.

Use .lua files.

Put it this way, no matter whether it’s txt or lua they will both require the modder to follow a format. I don’t see any advantages of txt files.

rename your thing (Yes, I know I didn’t use grammar)
example: yourbitch.lua.txt

then it should go into the txt format

Ok, so like this?


Tinynick916.lua.txt

I think I got it right, now what?

… no …