Hello, As a contribution, I present this method to create libraries for AMS without compiling anything, using c code.
The only drawback for that work, dependency of MinGW compiler that must be installed and the LUA libraries created, but, you can create a cache of compiled or simply copy the return .so file and run them in any application
This sample may be help the explanation
This returns thisPHP Code:Code=[[
#include <lua.h>
#include <lauxlib.h>
#include <stdio.h>
#include <stdlib.h>
int start(lua_State * L) {
luaL_checkstring(L,1);
lua_pushstring(L, "hello ");
lua_pushvalue(L, 1);
lua_concat(L, 2);
return 1;
}
int l_funcion(lua_State * L) {
int n = lua_tonumber(L,1);
int ret = n + 38;
lua_pushnumber(L,ret);
return 1;
}
int l_do(lua_State * L) {
lua_dostring(L,"Dialog.Message(l_funcion(5), start(\"world\"))");
return 1;
}
]]
bOk =CC.Compile(Code)
start =CC.Register("start")
l_funcion =CC.Register("l_funcion")
RunLib =CC.Register("l_do")
RunLib()
The posibilities for this are big, you can compile with some libraries such as mysql, soket, winapi...
You can use any compiler, i used MinGW but I tested the compiler of VisualStudio2005 and work perfect
I think that this functions are self explicative
This is all you need.PHP Code:CC={}
function CC.Compile(code)
TextFile.WriteFromString("F:\\cee.c", Code, false);
return File.Run("F:\\MinGW\\bin\\gcc.exe", "-O2 -shared -o f:/cee.so f:/cee.c -llua -llualib", "", SW_MINIMIZE, true);
end
function CC.Register(cfunc)
return loadlib("f://cee.so",cfunc)
end
PS. Remember to put lua.h lualib.h luaxlib.h in /includes and liblua.a liblualib.a in /lib, i put the files for testing


Reply With Quote
