简体   繁体   中英

How to execute Lua function line by line when called by C

I've not been able to find an answer to this question although I imagined it should be pretty common, so I'm guessing I'm doing something stupid or didn't read the manual properly.

Anyway, here's what I'm trying to do. I have a program that has a few C functions that are registered for Lua.

at another point, I call the lua function with

lua_getglobal(mainL,"interact");

and

 if (lua_pcall(mainL, 2, 0, 0) != 0)
          printf("error running function `f': %s",
     lua_tostring(L, -1));
    printf("interact\n");

Now in the Lua function, I call the other registered C functions a lot. And it seems like every time it does that, it runs in its seperate thread. (Correct me if I'm wrong)

So what I'm trying to ask is if there is anyway for it to block until the C function call is finished before executing the next line in the Lua function.

(Yes, I have tried using mutex in my C program, it works for me, but doesn't seem to work for others on other PC for some reason, so I'm trying to make it blocking since that will make everything a lot easier)

Thank you

And it seems like every time it does that, it runs in its seperate thread. (Correct me if I'm wrong)

You're wrong ;-) Or at least, if you are seeing other threads created, then something in the C code you call from Lua is doing that. C called from Lua (and vice-versa) will be explicitly blocking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM