| 320 | |
| 321 | // Set to > 0 to enable, otherwise disable. |
| 322 | public setTimeout(timeout: number | undefined): void { |
| 323 | if (timeout && timeout > 0) { |
| 324 | if (!this.hookFunctionPointer) { |
| 325 | this.hookFunctionPointer = this.lua.module.addFunction((): void => { |
| 326 | if (Date.now() > timeout) { |
| 327 | this.pushValue(new LuaTimeoutError(`thread timeout exceeded`)) |
| 328 | this.lua.lua_error(this.address) |
| 329 | } |
| 330 | }, 'vii') |
| 331 | } |
| 332 | |
| 333 | this.lua.lua_sethook(this.address, this.hookFunctionPointer, LuaEventMasks.Count, INSTRUCTION_HOOK_COUNT) |
| 334 | this.timeout = timeout |
| 335 | } else if (this.hookFunctionPointer) { |
| 336 | this.hookFunctionPointer = undefined |
| 337 | this.timeout = undefined |
| 338 | this.lua.lua_sethook(this.address, null, 0, 0) |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | public getTimeout(): number | undefined { |
| 343 | return this.timeout |