At first, things were smooth as we were learning how to write a SWIG interface file, and getting simple examples to work. Looking at an inspiring example of nodemcu firmware, which provides a Lua-based firmware for Espressif processors, it became clear we’ll have lots of code that glues functions and data structures for both languages to understand each other.Īs we started to write wrapper code, translating C arrays into Lua tables and naming structure fields manually, we found out about SWIG which promised to help with this task. Closing thoughtsĪfter choosing Lua for an embedded project it quickly became clear how much time we’ll need to spend binding two different worlds of Lua and C together. To have the ability to modify the array members we’d, unfortunately, need to write a custom modifier code. Now Lua knows it’s a table, but we’re limited to read-only access. ![]() Static int _wrap_multiply ( lua_State * L ) This article covers how to write a C program that launches a Lua interpreter and then how to use SWIG to generate the necessary wrapper code to allow Lua scripts to access the functions and data inside of the C runtime.Įxtern int32_t multiply ( int32_t x, int32_t y ) #ifdef _cplusplus Thankfully, there is a project which helps automate the generation of this boilerplate code called SWIG. The result is writing a lot of wrapper code integrating the two languages together that then must be maintained as the application evolves. There are ways to make Lua and C work together and share data structures, but it requires a lot of boilerplate and complex code. Many of the libraries today for embedded devices are written in C, not Lua! You can think of Lua as an alternative to the MicroPython (Python) or JerryScript (Javascript) interpreters. For these reasons, many great teams are choosing to include a Lua interpreter in their embedded project (e.g. It’s fast, uses little memory, is written in ANSI C, and is known by plenty of developers. ![]() Lua is one of the many great interpreters that can be run on embedded devices.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |