Fix an overflow of the lua stack

Credits go to boucman for the fix.

(cherry picked from commit 43fe49d0a51ef237c9a687fa22b66e36776ec122)