Integrating lua into C for embedding lua interpreters in a C application
Akira Tanimura, Hideya Iwasaki · 2016
Most scripting languages provide a C API that enables them to cooperate with programs written in C. The scripting language Lua is designed to be embedded in other host languages. However, when embedding Lua interpreters in a C program, the programmer must use complicated C API functions to write glue code between C and Lua. Obeying the protocols of Lua's C API not only increases the development cost but also makes the program error prone. We propose LuCa, a domain specific language for developing integrated applications of Lua and C, with C as the host language. LuCa enables the programmer to write glue code in a combination of Lua and C with some syntactic extensions. By using LuCa, the programmer need not use C API functions; the programmer can directly write Lua-like code, which is much clearer than C code that uses many API calls. We have implemented a LuCa processor as a translator from LuCa code into C code that calls appropriate C API functions. The translated code can be compiled by a standard C compiler and executed by linking a standard Lua interpreter.