lua-users home
lua-l archive

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



I doubt whether Lua could run on the real-time kernel or not.  Did you
achieve it?
Should I run on a real-time OS if I intend to run Lua scripts on the
controller for real-time control?
I think the question of "should you" has been answered correctly by others, with the key question always being how "hard" is each of your tasks that you plan to run in the kernel. You should not use it for tasks that need a hard response time or else bad things happen. However it's fine for "soft" real time tasks. There is no issue with having multiple tasks written in 'C' and running simultaneous Lua tasks subject to the normal RTOS caveats. 

NOTE: I am not familiar with the RTOS you mentioned. I am familiar with FreeRTOS and the uCOS, which are very similar to other pure RTOS kernels - including all the way back to iRMX in the 1980s. (the 'u' in uCOS is actually the greek letter 'mu', but it's not clear to me if the author intended it to be pronounced 'mucous'. 🙂 )

Here is what I did, and yes it worked fine.
  1. Built a thin wrapper around the FreeRTOS API.
  2. Created a task in 'C' that created and ran a Lua interpreter. The Lua script must be an endless loop, just as if you were writing a C task.
  3. Communicated between my Lua task and 'C' tasks using queues.
I would describe it as a fairly trivial process as I had been working with the Lua C API for a while and had some experience with uCOS - a very similar RTOS. You wouldn't even need the full thin wrapper to prove the concept. You could wrap just the RTOS sleep() function, create a 'C' task that creates a Lua interpreter and run a simple script that prints "Hello, World" and then calls the RTOS sleep() function and loops back.


From: 孙世龙 sunshilong <sunshilong369@gmail.com>
Sent: Wednesday, September 16, 2020 8:29 AM
To: Lua mailing list <lua-l@lists.lua.org>; Tim McCracken <Tim.McCracken@Utelety.com>
Subject: Re: Can Lua run within the real-time kernel?
 
Hi, Tim McCracken

>>Can Lua run within the real-time kernel?
>>Does anybody do such a test?
>>Is it possible to run Lua scripts on the controller for real-time control?
>Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
Sorry for misleading you.
I doubt whether Lua could run on the real-time kernel or not.  Did you
achieve it?
Should I run on a real-time OS if I intend to run Lua scripts on the
controller for real-time control?

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 9:08 PM Tim McCracken <Tim.McCracken@utelety.com> wrote:
>
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
>
> The real time kernels I have worked with are pretty complete and rarely need anything added within the kernel for real time control itself. As someone else pointed out garbage collection will make the kernel non-deterministic. However, you can leave the "hard" real time tasks coded in 'C' while providing a Lua thin wrapper around the kernel API (and other APIs such as network) and thereby support "soft" real time tasks that are written in Lua. A pretty good hybrid solution that I experimented with sometime ago. There are a number of commercial products that use this solution to provide end user programmability on a closed source product.
>
> ________________________________
> From: 孙世龙 sunshilong <sunshilong369@gmail.com>
> Sent: Tuesday, September 15, 2020 8:39 PM
> To: Lua mailing list <lua-l@lists.lua.org>
> Subject: Can Lua run within the real-time kernel?
>
> Hi,
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Best regards
> Sunshilong