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
import hook from "wowlua:hooks"hook("MyMissingFunction", function() print("called") end)import hook from "wowlua:hooks"if _G.MyMissingFunction then hook("MyMissingFunction", function() print("called") end)endThe 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
Related codes
| code | message |
|---|---|
| W8102 | Hook target belongs to a load-on-demand addon but opts.addon is missing |
Offline
$ wowlua explain W8040 W8040 (warning): Hook target not declared (not reported inside an existence test of the same member, if obj.Method then)