Lua Script


Lua is unique, its simple to setup, simple to learn, and simple to bind, most embedable scripting languages fail at least one of these.

I don’t cover building Lua as its trivial, you don’t need any special build flags, if you are on macOS you can use brew.

brew install lua

Linux will have similar, Windows errr … yeah anyway.

Run a Lua script…

/* lua.c */
#include <lua/lua.h>
#include <lua/lualib.h>
#include <lua/lauxlib.h>
#include <stdio.h>


void
lua_script(lua_State *L) {
        const char * script_a = "print(\"From Lua\")";
        luaL_dostring(L, script_a);
}


int
main() {
        lua_State *L = luaL_newstate();
        luaL_openlibs(L);

        lua_script(L);

        lua_close(L);

        return 0;
}

Outputs …

From Lua

Build and run …

clang lua.c -I /usr/local/include -L /usr/local/lib -llua && ./a.out