简体   繁体   中英

Evaluating Lua for bare metal project

I'm evaluating Lua for a bare metal project (most of it is already running) and it looks like what we need.

I need to put it into my code and be able to call into Lua without hanging in there at all. I need to call into Lua repeatedly like it's a state machine and have it return a status every time I call it to say either "Keep calling me, I'm not finished", "Stop, I have an error", or "Stop, no errors, script has completed".

I've seen the hooks that allow a callback from Lua to c for every line or byte of bytecode that's evaluated, but I cannot use a callback.

Does a state machine implementation of Lua exist?

You're looking for the lua_resume C function, which uses coroutines . From its documentation:

lua_resume returns LUA_YIELD if the coroutine yields, 0 if the coroutine finishes its execution without errors, or an error code in case of errors (see lua_pcall).

That sounds to me like exactly what you're describing.

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