Lua version of C code