How to add LUA interpreter in C firmware?

classic Classic list List threaded Threaded
2 messages Options
Roman Roman
Reply | Threaded
Open this post in threaded view
|

How to add LUA interpreter in C firmware?

Hi,

my question is - How to add LUA interpreter in C firmware? I wrote C firmware on my LM3S9b96 and I'm wondering how to implement LUA interpreter. I know, that Alexander IovlevReply covered this issue in theme:
http://elua-development.2368040.n2.nabble.com/How-can-I-use-eLua-as-embedded-interpreter-in-my-firmware-td7578105.html
but it was a year ago and mayby since this time there is better solution of this problem?
The best solution for me would be some LUA library for ARM.

Best regards
Roman
jbsnyder jbsnyder
Reply | Threaded
Open this post in threaded view
|

Re: How to add LUA interpreter in C firmware?

I think that discussion still generally covers it.

Tom Schouten's reply still covers how you would get Lua without eLua (from the raw Lua sources):

If you're building with Newlib as your libc you'll need to provide your own implementations of calls that would typically be provided by an operating system as described here:
https://sourceware.org/newlib/libc.html#Stubs

You can find examples in the eLua sources for Newlib:
https://github.com/elua/elua/blob/master/src/newlib/stubs.c

As mentioned there, going this route will not be the most memory efficient approach since eLua has a number of patches to improve memory performance.

You could also extract eLua's sources and build them into your project but we don't have a simple guide for doing this and you'll have to provide some of the functionality that the build system does.

An older version of one of these patches that would apply to Lua 5.1.x sources can be found here:
https://github.com/jsnyder/lua/tree/lua_tiny_ram

You'll likely also want the Emergency GC patch:
https://github.com/jsnyder/lua/tree/emergency_gc

NaN packing might also be of use:
https://github.com/jsnyder/lua/tree/nan_packing

Additionally you could build your sources into eLua as an extension and you can certainly customize it to do something different from start the eLua shell or Lua REPL:
https://github.com/elua/elua/blob/master/src/main.c

Best.

-jsnyder