as os.type is a constant, put the os.type == ... test out of the function such that the test is performed only once instead of on each call
replace exit with assert. Using exit at the top level is ok but not in the middle of nowhere. With assertwe can use pcall and deal with errors without terminating the program abruptly.
on the "unix" side, escapepath returned 2 values instead of one. This is not a problem now but could be in the future when used as argument to a function:
function f(...)
for i,j in ipairs{...} do
print(i.."->"..j)
end
end
f(string.gsub("aaa","a","c"))
f(string.gsub("aaa","a","c"),10)
Both calls have exactly the same number of arguments.
Improvements
os.type
is a constant, put theos.type == ...
test out of the function such that the test is performed only once instead of on each callexit
withassert
. Usingexit
at the top level is ok but not in the middle of nowhere. Withassert
we can usepcall
and deal with errors without terminating the program abruptly.escapepath
returned 2 values instead of one. This is not a problem now but could be in the future when used as argument to a function:Both calls have exactly the same number of arguments.