Detecting code blocks when executing Lua script line by line

This may sound like a stupid question, but I don't see this specific problem mentioned anywhere. Primarily:

I want to execute the Lua script in turn, first of all, to be able to pause / resume execution anytime, anywhere, wherever I want. What I'm doing is simple: load the piece using luaL_loadbuffer (), and then release lua_pcall ().

Thing is ... How can I correctly define Lua blocks to execute them atomically?

For example, suppose a function exists in a script — by executing a string of a string using the method described above, I cannot find a way to correctly recognize the function and, therefore, its contents are loaded and called one after another.

I can imagine that one solution would be to manually process the stack where I click on the control keywords that I can recognize in the script ("function", "if", "do", etc.) and their corresponding "end" "if I find nested blocks. As soon as I press the last “end”, I call the whole block, but it sounds just awful. Of course, there must be a better way to do this.

Hope this makes sense, and thanks!

+3
source share
2 answers

, Lua coroutines, . yield sleep() waitforevent(), , resume (, ).

+1

lua_sethook().

, , , , . -. .

+1

All Articles