lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Thanks Volodymyr. I've seen those C API just aftet sent my mail. 
Now I' m going to do some experiment in my code. 
Thanks again for your hints and courtesy. 


Inviato da iPhone

Il giorno 31/ott/2013, alle ore 22:19, Bezobiuk Volodymyr <> ha scritto:

You place lua_open(), lua_openlibs(), and create new coroutine by lua_newthread() before the main loop in C code. Then for sure you can resume/yield coroutine, created by lua_newthread() with lua_resume() and lua_yield(). It is really the right way. You can read about it in Lua manual and in the 'Programming in Lua' book.


On Thu, Oct 31, 2013 at 6:04 PM, Bob Schiavo <> wrote:

Thank you very much Bezobiuk

I was able to implement a small lua code working as you suggest by coroutines. But it works inside lua code. What I meant is a little bit different. I try to explain better.

Suppose I’m working on platform STM32 using Lua embedded in STM32F1xx CPU. Suppose also my main.c file, after the initialization routines, starts by the while(true) cycle, something like the following (take it as a logical description of the code):









lua app_script()               à ( lua_State* L = lua_open(), luaL_openlibs(L), … … and so on )






This is the situation I mean. I don’t know if coroutines method could be applicable to a such situation, to interrupt a while(true) inside the lua app_script. On other words, I don’t think I can insert the resume/yield of a coroutine inside a pure C_functionX() running in my main.c file. Isn’t it?


By the way, do you have any answer about point 1) and 2), regarding the usage of lua over uCLinux, FreeRTOS, or some other RTOSs?






Da: [] Per conto di Bezobiuk Volodymyr

Inviato: martedì 29 ottobre 2013 16:35
A: Lua mailing list
Oggetto: Re: Using Lua with and without SO


Hi Bob,

for the b) case there are decent Lua coroutines around. You can resume/yield back from Lua function wrapped in coroutine. So you'll probably get not while(true) in Lua part, but rather while(coroutine.yield(your_value)) - at this point you pass to the C caller your values (like returning them) and wait for resume from C part. That's looks like ping-pong. C part resume coroutine, coroutine do something, and return values to C. The C part may resume coroutine passing false to it, indicating that Lua part should finish (and probably clean up resources properly). Try to read some coroutine tutorials and experiment with them to get it handy. Note that coroutines not intended specifically for interaction with C, they are standard Lua library and can be used when both the caller and coroutine are Lua code, or with Lua caller and C method coroutine-wrapped.


On Tue, Oct 29, 2013 at 5:10 PM, Bob Schiavo <> wrote:

Hello everybody

I’m a beginner of Lua, and I was wondering, looking at the use of Lua in environment with and without operating system, the following questions:


Usage of Lua with SO

1.       Is it possible to embed Lua into uCLinux, or some other RTOSs (i.e freeRTOS)?

2.       If yes, is Lua embeddable “as it is” (I don’t think so) or it needs a porting, and how the porting can be done (is there some document/user guide that describes how to do that for the two SO above)?


Usage of Lua without SO

a)      Looking at eLua, that is Lua for embedded application on different platforms and CPUs, if I well understood, I have a complete description of the microcontroller and its resources. Supposing that I need only the interpreter to execute some script Lua, without any description of the platform resources (I mean no platform/…/FwLib sources files):

Do I have to configure the building toolchain for eLua to skip the FwLib modules, or could Lua (not eLua) be ported directly on the platform?


b)      I try to explain in poor words what I’m evaluating, so I might not be so clear as I would be.

Assuming to have a scheduler that executes sequentially a script Lua (appl_script) and some other C functions, totally independent by the execution of the lua script. Something like the following (just a logical representation of the scheduler):



               Execution of lua app_script();

               Execution of C_function1();


               Execution of C_functionN();


If the lua script itself has a while(true), the others functions will never be executed.

Is there the possibility, in a such situation, to interrupt the execution of the lua script, passing the control to the other functions of the scheduler, and resume the script next time it will be executed from the point it left off?