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); }
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); }