With methods like io.close(), you can use it like this:
file:close()
Is there a way to create a custom function that works like that, where you can call it on a variable?
For me I am trying to use it to separate arguments from a text file by using string.find to find spaces
So in the text file it looks like
this is some input
And the readArgs() function should return the entire line in a table with args[1] = "So", args[2] = "in", args[3] = "the" etc. after being called on the line
function readFile(file)
local lines = {}
assert(io.open(file), "Invalid or missing file")
local f = io.open(file)
for line in f:lines() do
lines[#lines+1] = line
end
return lines
end
function readArgs(line) -- This is the function. Preferably call it on the string line
--Some code here
end
someStringVariable:readArgs()?:is an expression.