Calling Lua From C

Introduction One very useful feature of Lua is how easy it is to work with from C. Unlike other scripting languages Lua’s C support goes to and from. Meaning you not only can call C from Lua but you can call Lua from C. Often you’ll see applications written in a high level language with […]

Writing Lua Modules

Introduction With Lua 5.2 the recommended way to write modules changed. Instead of using module(“mymodule”, package.seeall) the recommendation now is to create a local table, put all of the module’s functions in it and return the table. The big difference is a local table does not register the module in the global namespace. Personally, I […]

Wrapping a C library in Lua

Introduction An often overlooked feature of Lua is the C API. The most common use I’ve seen is to allow Lua scripts to use existing C libraries instead of reimplementing existing functionality in pure Lua (which is not always feasible). Fortunately, Lua has very strong integration with C and while not trivial, wrapping a C […]