Stanley Wu
Stanley Wu

Reputation: 11

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

Upvotes: 0

Views: 455

Answers (1)

Roddy
Roddy

Reputation: 68033

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.

Upvotes: 2

Related Questions