简体   繁体   中英

Running lua_pcall asynchronously

I'm having a C application and I'm integrating LUA as a scripting language in it, Embedding LUA went fine with no problems.

Currently I want to know if it's possible to run 2 or 3 different scripts at the same time from my C application, I have noticed that lua_pcall is running synchronously (so it doesn't return until it finishes the complete execution of the script.

Is there any way to run multiple scripts at the same time, or at least let lua_pcall run asynchronously. I don't want a solution in the script itself, because I have no control on the scripts that will run (Customer will be writing the scripts for configuration and I don't want to tell him you have to do so, and so, and so inside your script to handle the synchronization.

As Eran says, you can run a fresh lua_State (one created from newthread) in a seperate system thread quite easily.

The only thing you really need to to on top of this is some basic locking (implement lua_lock/lua_unlock/init/shutdown) so that global state elements (_G, Registry, some internals) are not accessed from multiple threads.

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