Scan Lua file for invalid function names (World of Warcraft)

499 views Asked by At

So I have a Wow addon which is many, many thousands of lines long. Sometimes, Blizzard removes Lua functions from the game and I'm not always sure whether the functions I've called in the addon are valid anymore.

Is there a way that I can scan an entire Lua file for functions that no longer exist?

I know that I can do something like this:

if not RemovedFunction then print("Function does not exist") end

But that requires me to check every function name one at a time so that's not realistic (there are hundreds).

I would like to be able to scan the entire Lua file and alert me if any function names that I've called are no longer present in World of Warcraft API.

The solution can be written in any language (does not have to be Lua script although that would be preferable).

3

There are 3 answers

0
Piglet On BEST ANSWER

A good API would list removed function names in their changelog. Just search your script for those names.

You can use a linter like luacheck to find undefined stuff in your script. This would require you to maintain a list of existing function names. This also works for other globals.

Or you search your script for function calls and search that name in a list of existing function names. Or you check if this name is nil in your environment. A function call is any name that is followed by optional whitespace and either of (, " or {. For functions this is trivial, for other variables it becomes a bit more complicated and you'll end up writing your own linter so you could as well just use an existing one.

2
Ketho On

You can find a changelog here

The GitHub project shows how those functions are scanned, it's essentially just scanning _G[] and Blizzard's FrameXML code

You can also upload a zip to Globe which will tell you about any removed API, e.g.

0
Foxie Flakey On

Scan if the function name is nil

function isFunctionExist(functionName) --Function name in string
  local func = load("return "..functionName")
  if func == nil then
    error("Invalid function name!") --There an invalid letter in your function name that cause load unable to load
  end

  return type(func()) == "function"
end

It also work on any lua interpreter not only in World of Warcraft addon Lua will cause attempt to call nil value or similiar So before run it we check whether is it nil or a function

load("return "..functionName) will return the functionName variable content even it nil then we check it with type if it an existent function it return "function"

type(func()) == "function" this line do the checking