MEDIUM: lua-thread: make hlua_post_init() no longer use the runtime execution function
The goal is to no longer use "struct hlua" with global main lua_state. The hlua_post_init() is executed during start phase, it does not require yielding nor any advanced runtime error processing. Let's simplify this by re-implementing the code using lower-level functions which directly take a state and not an hlua anymore.
This commit is contained in:
parent
3fb9e5133a
commit
670db24329
66
src/hlua.c
66
src/hlua.c
@ -8182,6 +8182,12 @@ int hlua_post_init()
|
|||||||
const char *msg;
|
const char *msg;
|
||||||
enum hlua_exec ret;
|
enum hlua_exec ret;
|
||||||
const char *error;
|
const char *error;
|
||||||
|
const char *kind;
|
||||||
|
const char *trace;
|
||||||
|
int return_status = 1;
|
||||||
|
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 504
|
||||||
|
int nres;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* disable memory limit checks if limit is not set */
|
/* disable memory limit checks if limit is not set */
|
||||||
if (!hlua_global_allocator.limit)
|
if (!hlua_global_allocator.limit)
|
||||||
@ -8208,29 +8214,63 @@ int hlua_post_init()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
hlua_fcn_post_init(gL.T);
|
hlua_fcn_post_init(gL.T);
|
||||||
RESET_SAFE_LJMP(gL.T);
|
|
||||||
|
|
||||||
list_for_each_entry(init, &hlua_init_functions, l) {
|
list_for_each_entry(init, &hlua_init_functions, l) {
|
||||||
lua_rawgeti(gL.T, LUA_REGISTRYINDEX, init->function_ref);
|
lua_rawgeti(gL.T, LUA_REGISTRYINDEX, init->function_ref);
|
||||||
ret = hlua_ctx_resume(&gL, 0);
|
|
||||||
|
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 504
|
||||||
|
ret = lua_resume(gL.T, gL.T, 0, &nres);
|
||||||
|
#else
|
||||||
|
ret = lua_resume(gL.T, gL.T, 0);
|
||||||
|
#endif
|
||||||
|
kind = NULL;
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case HLUA_E_OK:
|
|
||||||
|
case LUA_OK:
|
||||||
lua_pop(gL.T, -1);
|
lua_pop(gL.T, -1);
|
||||||
break;
|
break;
|
||||||
case HLUA_E_AGAIN:
|
|
||||||
ha_alert("Lua init: yield not allowed.\n");
|
case LUA_ERRERR:
|
||||||
return 0;
|
kind = "message handler error";
|
||||||
case HLUA_E_ERRMSG:
|
/* Fall thru */
|
||||||
|
case LUA_ERRRUN:
|
||||||
|
if (!kind)
|
||||||
|
kind = "runtime error";
|
||||||
msg = lua_tostring(gL.T, -1);
|
msg = lua_tostring(gL.T, -1);
|
||||||
ha_alert("lua init: %s.\n", msg);
|
lua_settop(gL.T, 0); /* Empty the stack. */
|
||||||
return 0;
|
lua_pop(gL.T, 1);
|
||||||
case HLUA_E_ERR:
|
trace = hlua_traceback(gL.T);
|
||||||
|
if (msg)
|
||||||
|
ha_alert("Lua init: %s: '%s' from %s\n", kind, msg, trace);
|
||||||
|
else
|
||||||
|
ha_alert("Lua init: unknown %s from %s\n", kind, trace);
|
||||||
|
return_status = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ha_alert("Lua init: unknown runtime error.\n");
|
/* Unknown error */
|
||||||
return 0;
|
kind = "Unknown error";
|
||||||
|
/* Fall thru */
|
||||||
|
case LUA_YIELD:
|
||||||
|
/* yield is not configured at this step, this state doesn't happen */
|
||||||
|
if (!kind)
|
||||||
|
kind = "yield not allowed";
|
||||||
|
/* Fall thru */
|
||||||
|
case LUA_ERRMEM:
|
||||||
|
if (!kind)
|
||||||
|
kind = "out of memory error";
|
||||||
|
lua_settop(gL.T, 0);
|
||||||
|
lua_pop(gL.T, 1);
|
||||||
|
trace = hlua_traceback(gL.T);
|
||||||
|
ha_alert("Lua init: %s: %s\n", kind, trace);
|
||||||
|
return_status = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if (!return_status)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
RESET_SAFE_LJMP(gL.T);
|
||||||
|
return return_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The memory allocator used by the Lua stack. <ud> is a pointer to the
|
/* The memory allocator used by the Lua stack. <ud> is a pointer to the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user