In java i’m used to using the built in classes for reading and writing properties files but something similar doesn’t exist for lua.
Whats the simplest way to save a name and a value to file and then get the value back using the name?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The simplest way would be something like this:
This works, but isn’t very secure as
dofile()just executes whatever Lua code it finds in the file. If the file returns a table full of your saved values as it does here then it works just great, but someone could easily edit this file to containos.execute("sudo rm -rf /")or other such delightful fun.It’s possible to make this more robust with judicious use of
setfenv()anddebug.sethook(), but if you want to do it properly you should use one of the many serialisation libraries for Lua, a selection of which can be found here.