A basic implementation with "hello world"
Strict Import axe.lua Type TLua Global luaState:Byte Ptr Method New() luaState = luaL_newstate() luaL_openlibs(luaState) EndMethod Method doScript(source:String) luaL_loadbuffer(luaState, source, source.length, source[0..10]) Local b:Int = lua_pcall(luaState, 0, 0, 0) If b '' bad scripts generate errors Print("Error - " + lua_tostring(luaState, - 1) ) lua_pop(luaState, 1) EndIf EndMethod ''table sets a namespace for the function or value (namespace.function) Method setFunction(name:String , fun(p:Byte Ptr) , table:String = "") If table.length lua_getglobal(luaState, table) lua_pushstring(luaState, name) lua_pushcfunction(luaState, fun) lua_settable(luaState, - 3) Else lua_register(luaState, name, fun) EndIf EndMethod Method setValue(key:String , value:Float , table:String = "") If table.length lua_getglobal(luaState, table) lua_pushstring(luaState, key) lua_pushnumber(luaState, value) lua_settable(luaState, - 3) Else lua_pushstring(luaState, key) lua_pushnumber(luaState, value) lua_settable(luaState , LUA_GLOBALSINDEX) EndIf EndMethod EndType '' lua function always takes 1 argument - a pointer to the lua state Function _echo(p: Byte Ptr) Local msg:String = lua_tostring(p, 1) If String(msg) Print(msg) Else Print(lua_tonumber(p, 1) ) EndIf EndFunction Global Lua:TLua = New TLua Lua.setFunction("echo", _echo) Lua.setValue("n", 10) Lua.doScript("echo('You are using '..tostring(_VERSION))") Lua.doScript("for i=0,n do echo(string.sub('hello world',0,i+1)) end")