monome / crow

Crow speaks and listens and remembers bits of text. A scriptable USB-CV-II machine
GNU General Public License v3.0
166 stars 34 forks source link

fix dofile when called from a coroutine #422

Closed trentgill closed 3 years ago

trentgill commented 3 years ago

Fixes #419

When calling an ii function for the first time from within a clock coroutine, it would load the file but fail to return the table to the coroutine, abandoning it to the GC.

This was caused by the custom dofile implementation using a global pointer to the lua_State, rather than the received pointer from the VM. This breaks when called from a coroutine because a lua coroutine is essentially a lua_State object wrapped in a 'LUA_TTHREAD' object. Thus we would push the loaded table into the main thread's stack, rather than the coroutine's stack.


Additionally, a new 'strip_debug' flag is added per lua-library in lib/lualink.c. If you are debugging an issue in any of the on-board lua libraries, set the flag to false for that file so you get accurate line-numbers when errors arise.