CS代码
lua = new LuaState();
lua.AddSearchPath(Application.dataPath + "/Lua");
lua.AddSearchPath(Application.dataPath + "/ToLua/Lua");
lua.AddSearchPath(Application.dataPath + "/ToLua");
lua.Start();
LuaBinder.Bind(lua);
lua.BeginModule(null);
lua.BeginModule("RpcClient");
lua.RegFunction("SendRequest", (System.IntPtr l) =>
{
string service = LuaDLL.lua_tostring(l, 1);
string method = LuaDLL.lua_tostring(l, 2);
string para = LuaDLL.lua_tostring(l, 3);
LuaTypes t = LuaDLL.lua_type(l, 4);
LuaFunction func = null; // 要先保存下来
if (t == LuaTypes.LUA_TFUNCTION)
{
func = ToLua.ToLuaFunction(l, 4);
}
else
{
Debug.LogWarning("[LUA]:cb not a function");
}
RpcClient.ins.SendRequest( service,method,para, (string msg) =>
{
func.BeginPCall();
func.Push(msg);
func.PCall();
func.EndPCall();
});
return 0;
});
lua.EndModule();
lua.EndModule();
lua.DoFile("Main.lua");
LUA代码
--主入口函数。从这里开始lua逻辑
RpcClient.SendRequest("services.login", "login", "account:1,pwd:1,",function (msg)
print(msg)
end);