Move Lua API code to Lua files