Limiting execution time #239
Unanswered
morgoth990
asked this question in
Q&A
Replies: 2 comments
-
From lua.h, line 345 or so /* Callbacks that can be used to reconfigure behavior of the VM dynamically.
* These are shared between all coroutines.
*
* Note: interrupt is safe to set from an arbitrary thread but all other callbacks
* can only be changed when the VM is not running any code */
struct lua_Callbacks
{
void* userdata; /* arbitrary userdata pointer that is never overwritten by Luau */
void (*interrupt)(lua_State* L, int gc); /* gets called at safepoints (loop back edges, call/ret, gc) if set */
void (*panic)(lua_State* L, int errcode); /* gets called when an unprotected error is raised (if longjmp is used) */
void (*userthread)(lua_State* LP, lua_State* L); /* gets called when L is created (LP == parent) or destroyed (LP == NULL) */
int16_t (*useratom)(const char* s, size_t l); /* gets called when a string is created; returned atom can be retrieved via tostringatom */
void (*debugbreak)(lua_State* L, lua_Debug* ar); /* gets called when BREAK instruction is encountered */
void (*debugstep)(lua_State* L, lua_Debug* ar); /* gets called after each instruction in single step mode */
void (*debuginterrupt)(lua_State* L, lua_Debug* ar); /* gets called when thread execution is interrupted by break in another thread */
void (*debugprotectederror)(lua_State* L); /* gets called when protected call results in an error */
};
typedef struct lua_Callbacks lua_Callbacks; I don't know the intricacies of this, but I noticed this comment recently which seems relevant to your case! Using interrupt may be exactly what you need? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I have tested it, interrupt can't call lua_yield/break. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My plan is to limit the execution time to avoid to lock the game thread.
I have managed to succesfully break the execution using debugstep, the idea is to set debugstep=nullptr, call lua_resume and use a parallel thread to set debugstep = DebugStep_TIMEOUT_YIELD when the timeout is expired.
Using this method debugstep doesn't affect the performance.
The questions are:
Beta Was this translation helpful? Give feedback.
All reactions