Hi,
To assist finding problems in my own code, I wrote a utility to scan .lua files to look for some kinds of problems (and potential problems). It’s aware of many Corona APIs.
It’s not perfect, and it does assume some coding conventions.
However, here’s a sample of running it on a few lua files in the business-app-sample-master app from Corona Labs:
checklua database.lua
Warning: [datatable.lua:166] Assign to non-local variable: springStart
Warning: [datatable.lua:168] Assign to non-local variable: needToReload
In two cases, it spotted variables that probably should be local (and/or initialized).
Looking at lines 166 & 168, I see that there may be a code path where the function can be called once, and then called a later time with a phase other than ‘began’ or ‘ended’, and that could result in “needToReload” having a value (rather than being nil).
checklua rss.lua
Warning: [rss.lua:18] Assign to non-local variable: rssFile
In this case, rssFile represents a probable small memory leak (the variable should be local, most likely).
and:
checklua xml.lua
Variables that might not get set or used…
= () f s . [] #dup #uses rec_# type name
- – - - - – ---- ----- ----- ---------- ----------------
a A 1 76 arg
In this case, ‘arg’ will likely have an unknown value, since the only other occurrence
of ‘arg’ in the file is as a local variable in a function. (I.e., not visible at line 76.)
If anyone is interested in running this, drop me a line. It’s a compiled C program, and I have binaries for Mac, Windows, Linux (X86), and HP-UX. (BTW, it’s free.)
Stan