|
lua_isyieldable
"
> Observe, however, that [B] does not make the latter available to the
> Lua state. So the coroutine in [B] simply fails when trying to call a
> nil value, and my_pcall() is never called at all.Thank you, I missed that indeed.Registering "my_pcall" as well changes the behavior and the "no longer unreachable" code after pcall is called.> I would like to point out that for whatever strange reason you seem
> determined to say that lua_pcall() or Lua's reference manual have a
> bug, ...No, that is not what I said.I'm trying to find a solution to a specific problem - either by building a solution around Luaor by modifying the Lua kernel itself if there is no other solution.The program should help to test out if a particular solution works or not.Or by documenting the restrictions which might exclude using some existing libraries.On Mon, Mar 1, 2021 at 11:50 PM Viacheslav Usov <via.usov@gmail.com> wrote:On Mon, Mar 1, 2021 at 7:55 PM bel <bel2125@gmail.com> wrote:
[A]
> int my_pcall(lua_State *L)
> {
> lua_pcall(L, lua_gettop(L)-1, 0, 0);
> UNREACHABLE
> return 0;
> }
[B]
> int num_from_lua(const char *code)
> {
> lua_State *L = luaL_newstate(); /* create state */
> luaL_openlibs(L);
> lua_pushcfunction(L, my_exit);
> lua_setglobal(L, "my_exit");
> lua_pushcfunction(L, my_pcallk);
> lua_setglobal(L, "my_pcallk");
>
> luaL_loadstring(L, code);
> int result = setjmp(JUMP_TO_EXIT);
> if (result) {
> return result;
> }
> int status = lua_pcall(L, 0, 1, 0);
> if (status) {
> printf("%s\n", lua_tostring(L, 1));
> } else {
> result = lua_tonumber(L, -1);
> }
> lua_close(L);
> return result;
> }
[C]
> a = num_from_lua(
> "co = coroutine.create("
> " function () "
> " my_pcall(coroutine.yield) "
> " end"
> "); "
> "coroutine.resume(co); "
> "print(coroutine.status(co)); "
> "return 32;"
> );
> check(a, 32);
Apparently you believe that [C] would call my_pcall() as defined in [A].
Observe, however, that [B] does not make the latter available to the
Lua state. So the coroutine in [B] simply fails when trying to call a
nil value, and my_pcall() is never called at all.
I would like to point out that for whatever strange reason you seem
determined to say that lua_pcall() or Lua's reference manual have a
bug, you should submit a bug report that demonstrates just this one
bug, not a program doing all kinds of things, which is so confusing
that you ended up confusing yourself.
Cheers,
V.