Jump to content
  • Advertisement
Sign in to follow this  
desu_ka

Pausing and resuming Lua scripts run from C/C++

This topic is 4268 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, all. I'm a beginner to using Lua and C/C++ together and I really want to know how (or if) this is possible. I'd like for C/C++ to be able to start multiple Lua scripts one after the other and run each individually. Now, the tricky part is that I want the Lua scripts to call C++ functions which have the potential to stop the script from continuing to run (and return the flow of the program to the C/C++ side), but leave it able to begin again later wherever it left off. Basically, I've found plenty of information on linking Lua and C/C++ together via functions, but I need more about controlling the execution of Lua scripts. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Sounds closest to coroutines, but its probably not exactly what you are talking about. You could run many lua coroutines. They can yield their execution for however long and can be resumed later.

edit: I don't know about doing this from c++. Lua isn't thread safe. Pausing a running coroutine from c++ implies you are calling it from a second thread which I wouldn't be surprised if it bombed.

Share this post


Link to post
Share on other sites
Is it possible to execute a specific number of commands (particularly just one) at a time when running a Lua script from C/C++? This would probably serve my needs.

Share this post


Link to post
Share on other sites
I tried to do that sometime (execute a limited number of instructions), but I wasn't able to find a way to do it (apart from editing the lua core)...

Share this post


Link to post
Share on other sites
Actually, even better would be some command in the Lua script that stops itself and returns to the C/C++ code that started/resumed it, such that it can be resumed later where it left off.

Share this post


Link to post
Share on other sites
Quote:
Original post by desu_ka
Is it possible to execute a specific number of commands (particularly just one) at a time when running a Lua script from C/C++? This would probably serve my needs.


I don't believe so. I think Angelscript has such functionality though.

Quote:
Original post by desu_ka
Actually, even better would be some command in the Lua script that stops itself and returns to the C/C++ code that started/resumed it, such that it can be resumed later where it left off.


You can do that. Look into coroutines. http://www.lua.org/manual/5.1/manual.html#2.11

Personally I prefer the threads in Game Monkey and Angelscript to lua coroutines, but it can do what you're wanting.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!