//初始化LUA protected virtual void InitializationLua() { try { Lua = new LuaScriptController(); switch (luaScriptType) { case LuaScriptType.Type_Name: Lua.InitializationName(LuaScriptName, LuaStoreMethodMask, LuaStoreMethod); break; case LuaScriptType.Type_File: Lua.InitializationFile(LuaScriptFile, LuaStoreMethodMask, LuaStoreMethod); break; case LuaScriptType.Type_String: Lua.Initialization(LuaScriptString, LuaStoreMethodMask, LuaStoreMethod); break; case LuaScriptType.Type_Bytes: Lua.Initialization(LuaScriptBytes, LuaScriptBytesName, LuaStoreMethodMask, LuaStoreMethod); break; } } catch (System.Exception ex) { Debug.LogError(ex.ToString()); } }
private void CallMethod(int funcRef) { Lua.RawGetI(LuaDef.LUA_REGISTRYINDEX, funcRef); // insert `traceback' function int b = Lua.GetTop(); Lua.PushCSharpFunction(Traceback); Lua.Insert(b); var status = Lua.PCall(0, 0, b); if (status != ThreadStatus.LUA_OK) { LuaScriptController.LogError(Lua.ToString(-1)); } // remove `traceback' function Lua.Remove(b); }
/// <summary> /// 初始化 /// </summary> /// <param name="handler">线程处理器.</param> public Thread(LuaFunction handler) { _scriptController = new LuaScriptController(); _handler = handler; }
private void CallLuaMethod_Command(int funcRef, object[] parameters, int returnVars) { Lua.RawGetI(LuaDef.LUA_REGISTRYINDEX, funcRef); // insert `traceback' function int b = Lua.GetTop(); Lua.PushCSharpFunction(Traceback); Lua.Insert(b); //foreach (object o in parameters) //{ for (int i = 0; i < parameters.Length; i++) { object o = parameters[i]; switch (Type.GetTypeCode(o.GetType())) { case TypeCode.Boolean: Lua.PushBoolean((Boolean)o); break; case TypeCode.Double: Lua.PushNumber((Double)o); break; case TypeCode.Single: Lua.PushNumber((float)o); break; case TypeCode.Int32: Lua.PushInteger((Int32)o); break; case TypeCode.UInt32: Lua.PushUnsigned((UInt32)o); break; case TypeCode.String: Lua.PushString((String)o); break; case TypeCode.UInt64: Lua.PushUInt64((UInt64)o); break; case TypeCode.Object: { if (o is CSharpFunctionDelegate) { Lua.PushCSharpFunction((CSharpFunctionDelegate)o); } else { throw new Exception("not support type!"); } } break; default: throw new Exception("not support type!"); } } var status = Lua.PCall(parameters.Length, returnVars, b); if (status != ThreadStatus.LUA_OK) { LuaScriptController.LogError(Lua.ToString(-1)); } // remove `traceback' function Lua.Remove(b); }