-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supply Pallene Tracer Error Handler Function #25
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if assigning to a global variable might cause trouble with Lua environments that don't allow assigning to globals. For example, the strict.lua that sets the __newindex global metatable...
I think, here setting the global variable won't cause us any issue. Because even if the script manages to override the |
I suppose that would depend on the order that the modules are required. If they require strict.lua before they run the tracer initializer, then it could cause the trouble? |
Actually the function is not supplied with tracer initializer. It is being supplied by setting Lua global prior calling the int main (int argc, char **argv) {
int status, result;
lua_State *L = luaL_newstate(); /* create state */
if (L == NULL) {
l_message(argv[0], "cannot create state: not enough memory");
return EXIT_FAILURE;
}
lua_gc(L, LUA_GCSTOP); /* stop GC while building state */
/* -------- PALLENE TRACER CODE -------- */
(void) pallene_tracer_init(L); /* initialize pallene tracer */
lua_pop(L, 1); /* We do not need the finalizer object here */
/* supply the message handler function with custom tracebacks. */
lua_pushcfunction(L, msghandler);
lua_setglobal(L, "pallene_tracer_errhandler");
/* -------- PALLENE TRACER CODE END -------- */
lua_pushcfunction(L, &pmain); /* to call 'pmain' in protected mode */
lua_pushinteger(L, argc); /* 1st argument */
lua_pushlightuserdata(L, argv); /* 2nd argument */
status = lua_pcall(L, 2, 1, 0); /* do the call */
result = lua_toboolean(L, -1); /* get result */
report(L, status);
lua_close(L);
return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE;
} |
Oh, that makes sense. Does pt-lua accept "-l" command line flags and, if so, do those requires run before or after our "main"? Can you also please add a comment explaining why this global is safe? |
Comment where? Here, or in the code explaining? |
Comment in the code, next to where you set the global. |
Can you please clarify to comment about what exactly? Safe/unsafe in what way? |
Just say that it's ok to set a global variable, because no other code has run yet. No one could have messed with the global meta table. |
Done, we can merge the PR now. |
Since there are many PRs at the same time, please rebase them before merging. Cheers! |
Changelog:
xpcall
.