hi there, my hungarian brother! :)
(to the others, who read my walls of texts recently: nothing new here)
i dont use the c api, but i know nothing that would really change the game there. so i know about 2 approaches to break a loop at will. the 1st one is like an event loop, where u can continuously check a dedicated loop condition just for this purpose, so u can safely exit via setting that from within the loop, or maybe with an interrupt handler. the 2nd is to put your loop into pcall()
or xpcall()
and call error()
(or trigger any kinda error) and then u will continue right after the pcall()
.
at 1st, to not shoot my leg during development (live-coding), i wrote things like:
so simply thats the basic idea, and then, in a function thats executed inside xpcall()
, i could figure out a way to leave behind that hp
boilerplate with 3 components, and now i write simply brk()
right after the beginning of the loop, that gets the current line via the debug
library, and uses that as an identifier (or whatever i give it), and then it makes the countdown on its own, and if its over, then it will calls error()
, otherwise if the function reaches its end, then i will delete all the counters after the xpcall()
. the rest is upon ur imagination, and u can use a counter, a signal, a timer, a variable, a file, an environment variable or whatever to trigger it...
btw, as i mentioned it, i wrote about this a few days ago, and u can search lua-l for "brk", nobody else wrote it after me if im right :D
have fun, bests! :)