Replace Lua code by calls to Lua C API