ceifa / wasmoon

A real lua 5.4 VM with JS bindings made with webassembly
MIT License
462 stars 27 forks source link

Fixed timeout could only be set the first time #37

Closed timstableford closed 3 years ago

timstableford commented 3 years ago

If disabled then it would the hook would be set to null in C but then on the next call the hook would not be fully re-enabled because it already existed.

Introduced in #36 but I only noticed after it'd been merged :)

ceifa commented 3 years ago

The code intends that if I call setTimeout multiple times, it will hook multiple times, is this supposed to happen?

timstableford commented 3 years ago

I believe it's now correct. When lua_sethook is called it replaces the previous hook rather than adding a new one. So when setTimeout it called with 0 it lua_sethooks to null and when with a non-zero value it sets it to the hooks function pointer. This way when it's disabled the hook isn't unnecessarily called.