I have the following 3 functions:
function getName() -- returns filename without ext local files = scandir(currentDir()) local name = nil for i = 1, #files do if isValidExt( getExt(files[i]) ) then name = getFilename(files[i]) break end end return name end
function currentDir() local string = debug.getinfo(1).source local endPoint = getLastOcurrence(string, '/') local dir = string.sub(string, 2, endPoint) return dir end
function getLastOcurrence(str, char) local last = string.find(string.reverse(str), char, 1, true) return #str - last end The strange thing is that debugging ends without issues, while running gives the error:
...\Downloader.lua:22: attempt to perform arithmetic on local 'last' (a nil value) stack traceback: ...\Downloader.lua:22: in function 'getLastOcurrence' ...\Downloader.lua:39: in function 'currentDir' ...\Downloader.lua:50: in function 'getName' What could cause such a difference between debug and run?