I'm having some trouble with Lua. The thing is: there are some Lua codes I know what they do but I didn't understood them, so if the professors ask me to explain them, I wouldn't be able to do it. Can you help me with this?
I know this code separates the integer part from the decimal part of a number, but I didn't understand the
"(%d*)(%.?.*)$"
part.int, dec = string.match(tostring(value), "(%d*)(%.?.*)$")
This code insert on a table all the data from a text file, which is written following this model
entry {name = "John", age = 20, sex = "Male")
. What I didn't understand is how do I know what parameters the function load needs? And the last parameterentry = entry
, I don't know if I got exactly its meaning: I think it gets thetext_from_file
as a piece of Lua code and everything that is after entry is sent to thefunction entry
, which inserts it on a table, is it right?function entry(entrydata) table.insert(data, entrydata) end thunk = load(text_from_file, nil, nil, {entry = entry}) thunk()
That's it. Please, if it's possible, help me understand these 2 pieces of Lua code, I need to present the whole program working and if a professor ask me about the code, I want to be sure about everything.