v0.13.7
errors and warnings / stdlib

errors and warnings / stdlib / W8040

W8040 warning

Hook target not declared (not reported inside an existence test of the same member, if obj.Method then)

area
stdlib (x8xxx)
fails the build
with --deny-warnings

The function or member given to hook, @hook or hookScript from wowlua:hooks isn't declared: a global function, a frame, or a method of the target's type that the game's declarations don't know. Where it doesn't exist, the hook fails with an error when it is installed. This is usually a typo, or an API that was removed or that only some clients have.

Fix the name. If the target really exists only sometimes, test for it around the hook (if _G.Name then for a global, if obj.Method then for a method); that test silences the warning.

Example

× failswowlua
import hook from "wowlua:hooks"hook("MyMissingFunction", function() print("called") end)
✓ compileswowlua
import hook from "wowlua:hooks"if _G.MyMissingFunction then    hook("MyMissingFunction", function() print("called") end)end

The compiler reports it like this:

warning[W8040]: `MyMissingFunction` is not a declared global function; the hook fails where it is installed
  ┌─ src/main.wowlua:2:6
  │
2 │ hook("MyMissingFunction", function() print("called") end)
  │      ^^^^^^^^^^^^^^^^^^^ here
codemessage
W8102Hook target belongs to a load-on-demand addon but opts.addon is missing

Offline

terminal
$ wowlua explain W8040
W8040 (warning): Hook target not declared (not reported inside an existence test of the same member, if obj.Method then)

source on GitHub ↗