|
10 | 10 | <tutorials> |
11 | 11 | </tutorials> |
12 | 12 | <methods> |
| 13 | + <method name="get_hook" qualifiers="const"> |
| 14 | + <return type="Variant" /> |
| 15 | + <description> |
| 16 | + Returns the current hook function. |
| 17 | + See [method set_hook]. |
| 18 | + </description> |
| 19 | + </method> |
| 20 | + <method name="get_hook_count" qualifiers="const"> |
| 21 | + <return type="int" /> |
| 22 | + <description> |
| 23 | + Returns the current hook count. |
| 24 | + See [method set_hook]. |
| 25 | + </description> |
| 26 | + </method> |
| 27 | + <method name="get_hook_mask" qualifiers="const"> |
| 28 | + <return type="int" enum="LuaThread.HookMask" is_bitfield="true" /> |
| 29 | + <description> |
| 30 | + Returns the current hook mask. |
| 31 | + See [method set_hook]. |
| 32 | + </description> |
| 33 | + </method> |
| 34 | + <method name="get_stack_info" qualifiers="const"> |
| 35 | + <return type="LuaDebug[]" /> |
| 36 | + <description> |
| 37 | + Get debug information about the stack of this thread of execution. |
| 38 | + </description> |
| 39 | + </method> |
| 40 | + <method name="get_stack_level_info" qualifiers="const"> |
| 41 | + <return type="LuaDebug" /> |
| 42 | + <param index="0" name="level" type="int" /> |
| 43 | + <description> |
| 44 | + Get debug information about the activation record of the function executing at a given [param level]. |
| 45 | + Level 0 is the current running function, whereas level n+1 is the function that has called level n (except for tail calls, which do not count in the stack). |
| 46 | + When called with a level greater than the stack depth, returns [code]null[/code]. |
| 47 | + </description> |
| 48 | + </method> |
| 49 | + <method name="get_traceback" qualifiers="const"> |
| 50 | + <return type="String" /> |
| 51 | + <param index="0" name="message" type="String" default="""" /> |
| 52 | + <param index="1" name="level" type="int" default="0" /> |
| 53 | + <description> |
| 54 | + Returns a traceback of the stack. |
| 55 | + [param message] is appended at the beginning of the traceback. |
| 56 | + [param level] tells at which level to start the traceback. |
| 57 | + </description> |
| 58 | + </method> |
13 | 59 | <method name="is_main_thread" qualifiers="const"> |
14 | 60 | <return type="bool" /> |
15 | 61 | <description> |
16 | 62 | Whether this thread is the [LuaState]'s main thread. |
17 | 63 | See also [member LuaState.main_thread]. |
18 | 64 | </description> |
19 | 65 | </method> |
| 66 | + <method name="set_hook"> |
| 67 | + <return type="void" /> |
| 68 | + <param index="0" name="hook" type="Variant" /> |
| 69 | + <param index="1" name="mask" type="int" enum="LuaThread.HookMask" is_bitfield="true" /> |
| 70 | + <param index="2" name="count" type="int" default="0" /> |
| 71 | + <description> |
| 72 | + Sets the debugging hook function. |
| 73 | + [param hook] is the Hook function, which should be either a [Callable] or [LuaFunction]. Pass [code]null[/code] to disable hooks. |
| 74 | + [param mask] specifies on which events the hook will be called: it is formed by a bitwise OR of the constants [constant HOOK_MASK_CALL], [constant HOOK_MASK_RETURN], [constant HOOK_MASK_LINE] and [constant HOOK_MASK_COUNT]. Pass 0 to disable hooks. |
| 75 | + [param count] is only meaningful when the mask includes [constant HOOK_MASK_COUNT]. |
| 76 | + See [enum HookEvent] for the available hook events. |
| 77 | + See also [url]https://www.lua.org/manual/5.4/manual.html#lua_sethook[/url]. |
| 78 | + [codeblocks] |
| 79 | + [gdscript] |
| 80 | + var line_hook := func(ar: LuaDebug): prints("Running line: ", ar.current_line) |
| 81 | + var state := LuaState.new() |
| 82 | + state.main_thread.set_hook(line_hook, LuaThread.HOOK_MASK_LINE) |
| 83 | + # The line hook will be called once for each line of Lua code |
| 84 | + state.do_string(""" |
| 85 | + local line1 = 1 |
| 86 | + local line2 = 2 |
| 87 | + local line3 = 3 |
| 88 | + """) |
| 89 | + [/gdscript] |
| 90 | + [/codeblocks] |
| 91 | + </description> |
| 92 | + </method> |
20 | 93 | </methods> |
21 | 94 | <members> |
22 | 95 | <member name="status" type="int" setter="" getter="get_status" enum="LuaThread.Status"> |
|
45 | 118 | <constant name="STATUS_DEAD" value="-1" enum="Status"> |
46 | 119 | The thread has finished execution. |
47 | 120 | </constant> |
| 121 | + <constant name="HOOK_MASK_CALL" value="1" enum="HookMask" is_bitfield="true"> |
| 122 | + Mask passed to [method set_hook] to subscribe to [constant HOOK_EVENT_CALL] and [constant HOOK_EVENT_TAIL_CALL] hooks. |
| 123 | + </constant> |
| 124 | + <constant name="HOOK_MASK_RETURN" value="2" enum="HookMask" is_bitfield="true"> |
| 125 | + Mask passed to [method set_hook] to subscribe to [constant HOOK_EVENT_RETURN] hooks. |
| 126 | + </constant> |
| 127 | + <constant name="HOOK_MASK_LINE" value="4" enum="HookMask" is_bitfield="true"> |
| 128 | + Mask passed to [method set_hook] to subscribe to [constant HOOK_EVENT_LINE] hooks. |
| 129 | + </constant> |
| 130 | + <constant name="HOOK_MASK_COUNT" value="8" enum="HookMask" is_bitfield="true"> |
| 131 | + Mask passed to [method set_hook] to subscribe to [constant HOOK_EVENT_COUNT] hooks. |
| 132 | + </constant> |
| 133 | + <constant name="HOOK_EVENT_CALL" value="0" enum="HookEvent"> |
| 134 | + Hook event that is called when the interpreter calls a function. The hook is called just after Lua enters the new function. |
| 135 | + </constant> |
| 136 | + <constant name="HOOK_EVENT_RETURN" value="1" enum="HookEvent"> |
| 137 | + Hook event that is called when the interpreter returns from a function. The hook is called just before Lua leaves the function. |
| 138 | + </constant> |
| 139 | + <constant name="HOOK_EVENT_LINE" value="2" enum="HookEvent"> |
| 140 | + Hook event that is called when the interpreter is about to start the execution of a new line of code, or when it jumps back in the code (even to the same line). This event only happens while Lua is executing a Lua function. |
| 141 | + </constant> |
| 142 | + <constant name="HOOK_EVENT_COUNT" value="3" enum="HookEvent"> |
| 143 | + Hook event that is called after the interpreter executes every [code]count[/code] instructions. This event only happens while Lua is executing a Lua function. |
| 144 | + </constant> |
| 145 | + <constant name="HOOK_EVENT_TAIL_CALL" value="4" enum="HookEvent"> |
| 146 | + Hook event that is called when the interpreter calls a function as a tail call. In this case, there will be no corresponding return event. |
| 147 | + </constant> |
| 148 | + <constant name="HOOK_OK" value="0" enum="HookResult"> |
| 149 | + </constant> |
| 150 | + <constant name="HOOK_YIELD" value="-1" enum="HookResult"> |
| 151 | + Return this value from line or count hook events to yield execution of the current Lua function that triggered the hook. |
| 152 | + </constant> |
48 | 153 | </constants> |
49 | 154 | </class> |
0 commit comments