ceifa / wasmoon

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

avoid infinite loop #45

Closed hansdpf closed 2 years ago

hansdpf commented 2 years ago

I have a test case with an infinite loop that I cannot break:

local a = string.find(("a"):rep(1e4), ".-.-.-.-b$" )

With debug.sethook I can include an instruction counter, but it doesn't work here. Any suggestions how I can avoid this?

Thanks

ceifa commented 2 years ago

Does set a timeout when initializing wasmoon solves your problem?

const lua = await factory.createEngine()
lua.global.setTimeout(Date.now() + 1000)
// ... run lua
hansdpf commented 2 years ago

I guess a timeout function would solve the problem - it tried it: an infinite loop is stopped after n ms, but the string.find example is not stopped. Also I think it clashes with my lua internal debug.sethook settings, but that would be solvable.

But thanks for the hint.