public static string[] GetGenericName(Type[] types, int offset, int count) { string[] array = new string[count]; for (int i = 0; i < count; i++) { int num = i + offset; if (types[num].get_IsGenericType()) { array[i] = LuaMisc.GetGenericName(types[num]); } else { array[i] = LuaMisc.GetTypeName(types[num]); } } return(array); }
public static T[] CheckNumberArray <T>(IntPtr L, int stackPos) { LuaTypes luaTypes = LuaDLL.lua_type(L, stackPos); if (luaTypes == LuaTypes.LUA_TTABLE) { int num = 1; T t = default(T); List <T> list = new List <T>(); LuaDLL.lua_pushvalue(L, stackPos); while (true) { LuaDLL.lua_rawgeti(L, -1, num); luaTypes = LuaDLL.lua_type(L, -1); if (luaTypes == LuaTypes.LUA_TNIL) { break; } if (luaTypes != LuaTypes.LUA_TNUMBER) { goto Block_3; } T t2 = (T)((object)Convert.ChangeType(LuaDLL.lua_tonumber(L, -1), typeof(T))); list.Add(t2); LuaDLL.lua_pop(L, 1); num++; } LuaDLL.lua_pop(L, 1); return(list.ToArray()); Block_3 :; } else { if (luaTypes == LuaTypes.LUA_TUSERDATA) { return((T[])ToLua.CheckObject(L, stackPos, typeof(T[]))); } if (luaTypes == LuaTypes.LUA_TNIL) { return(null); } } LuaDLL.luaL_typerror(L, stackPos, LuaMisc.GetTypeName(typeof(T[])), null); return(null); }
private static void PushPreLoadType(IntPtr L, object o, Type type) { LuaCSFunction preModule = LuaStatic.GetPreModule(L, type); if (preModule != null) { ToLua.LuaPCall(L, preModule); int metaReference = LuaStatic.GetMetaReference(L, type); if (metaReference > 0) { ToLua.PushUserData(L, o, metaReference); return; } } LuaDLL.lua_pushnil(L); Debugger.LogError("Type {0} not wrap to lua", LuaMisc.GetTypeName(type)); }
public static T[] CheckParamsNumber <T>(IntPtr L, int stackPos, int count) { double[] array = new double[count]; int i = 0; while (i < count) { if (LuaDLL.lua_isnumber(L, stackPos) == 0) { LuaDLL.luaL_typerror(L, stackPos, LuaMisc.GetTypeName(typeof(T)), null); return(null); } array[i] = LuaDLL.lua_tonumber(L, stackPos); i++; stackPos++; } return((T[])Convert.ChangeType(array, typeof(T[]))); }
public static T[] CheckNumberArray <T>(IntPtr L, int stackPos) { LuaTypes luatype = LuaDLL.lua_type(L, stackPos); if (luatype == LuaTypes.LUA_TTABLE) { int index = 1; T ret = default(T); List <T> list = new List <T>(); LuaDLL.lua_pushvalue(L, stackPos); while (true) { LuaDLL.lua_rawgeti(L, -1, index); luatype = LuaDLL.lua_type(L, -1); if (luatype == LuaTypes.LUA_TNIL) { LuaDLL.lua_pop(L, 1); return(list.ToArray()); } else if (luatype != LuaTypes.LUA_TNUMBER) { break; } ret = (T)Convert.ChangeType(LuaDLL.lua_tonumber(L, -1), typeof(T)); list.Add(ret); LuaDLL.lua_pop(L, 1); ++index; } } else if (luatype == LuaTypes.LUA_TUSERDATA) { return((T[])CheckObject(L, stackPos, typeof(T[]))); } else if (luatype == LuaTypes.LUA_TNIL) { return(null); } LuaDLL.luaL_typerror(L, stackPos, LuaMisc.GetTypeName(typeof(T[]))); return(null); }
public static void PushValue(IntPtr L, ValueType v) { if (v == null) { LuaDLL.lua_pushnil(L); return; } Type type = v.GetType(); int reference = LuaStatic.GetMetaReference(L, type); ObjectTranslator translator = ObjectTranslator.Get(L); if (reference > 0) { int index = translator.AddObject(v); LuaDLL.tolua_pushnewudata(L, reference, index); } else { LuaCSFunction LuaOpenLib = LuaStatic.GetPreModule(L, type); if (LuaOpenLib != null) { #if UNITY_EDITOR Debugger.LogWarning("register PreLoad type {0} to lua", LuaMisc.GetTypeName(type)); #endif LuaOpenLib(L); reference = LuaStatic.GetMetaReference(L, type); if (reference > 0) { int index = translator.AddObject(v); LuaDLL.tolua_pushnewudata(L, reference, index); return; } } //类型未Wrap LuaDLL.lua_pushnil(L); Debugger.LogError("Type {0} not wrap to lua", LuaMisc.GetTypeName(type)); } }
public static T[] CheckParamsObject <T>(IntPtr L, int stackPos, int count) { List <T> list = new List <T>(count); T t = default(T); Type typeFromHandle = typeof(T); while (count > 0) { object obj = ToLua.ToVarObject(L, stackPos); if (!TypeChecker.CheckType(L, typeFromHandle, stackPos)) { LuaDLL.luaL_typerror(L, stackPos, LuaMisc.GetTypeName(typeFromHandle), null); break; } T t2 = (T)((object)obj); list.Add(t2); count--; stackPos++; } return(list.ToArray()); }
private static string GetGenericName(Type t) { Type[] genericArguments = t.GetGenericArguments(); string text = t.FullName; int num = genericArguments.Length; int i = text.IndexOf("["); if (i > 0) { text = text.Substring(0, i); } string space = null; int num2 = 0; string text2; for (i = text.IndexOf("+"); i > 0; i = text.IndexOf("+")) { text2 = text.Substring(0, i); text = text.Substring(i + 1); i = text2.IndexOf('`'); if (i > 0) { num = (int)(text2[i + 1] - '0'); text2 = text2.Substring(0, i); text2 = text2 + "<" + string.Join(",", LuaMisc.GetGenericName(genericArguments, num2, num)) + ">"; num2 += num; } space = LuaMisc.CombineTypeStr(space, text2); } text2 = text; if (num2 < genericArguments.Length) { i = text2.IndexOf('`'); num = (int)(text2[i + 1] - '0'); text2 = text2.Substring(0, i); text2 = text2 + "<" + string.Join(",", LuaMisc.GetGenericName(genericArguments, num2, num)) + ">"; } return(LuaMisc.CombineTypeStr(space, text2)); }
public static T[] CheckParamsNumber <T>(IntPtr L, int stackPos, int count) { double[] buffer = new double[count]; int pos = 0; while (pos < count) { if (LuaDLL.lua_isnumber(L, stackPos) != 0) { buffer[pos] = LuaDLL.lua_tonumber(L, stackPos); } else { LuaDLL.luaL_typerror(L, stackPos, LuaMisc.GetTypeName(typeof(T))); return(null); } ++pos; ++stackPos; } return((T[])Convert.ChangeType(buffer, typeof(T[]))); }
static void PushPreLoadType(IntPtr L, object o, Type type) { LuaCSFunction LuaOpenLib = LuaStatic.GetPreModule(L, type); if (LuaOpenLib != null) { #if UNITY_EDITOR Debugger.LogWarning("register PreLoad type {0} to lua", LuaMisc.GetTypeName(type)); #endif LuaPCall(L, LuaOpenLib); int reference = LuaStatic.GetMetaReference(L, type); if (reference > 0) { PushUserData(L, o, reference); return; } } //类型未Wrap LuaDLL.lua_pushnil(L); Debugger.LogError("Type {0} not wrap to lua", LuaMisc.GetTypeName(type)); }
public static string GetTypeName(Type t) { if (t.IsArray) { string typeName = LuaMisc.GetTypeName(t.GetElementType()); return(typeName + LuaMisc.GetArrayRank(t)); } if (t.IsByRef) { t = t.GetElementType(); return(LuaMisc.GetTypeName(t)); } if (t.IsGenericType) { return(LuaMisc.GetGenericName(t)); } if (t == typeof(void)) { return("void"); } string primitiveStr = LuaMisc.GetPrimitiveStr(t); return(primitiveStr.Replace('+', '.')); }
/*static void PushNull(IntPtr L) * { * LuaDLL.tolua_pushudata(L, 1); * }*/ //PushVarObject public static void Push(IntPtr L, object obj) { if (obj == null) { LuaDLL.lua_pushnil(L); return; } Type t = obj.GetType(); if (t.IsValueType) { if (t == typeof(bool)) { bool b = (bool)obj; LuaDLL.lua_pushboolean(L, b); } else if (t.IsEnum) { Push(L, (System.Enum)obj); } else if (t.IsPrimitive) { double d = LuaMisc.ToDouble(obj); LuaDLL.lua_pushnumber(L, d); } else if (t == typeof(Vector3)) { Push(L, (Vector3)obj); } else if (t == typeof(Quaternion)) { Push(L, (Quaternion)obj); } else if (t == typeof(Vector2)) { Push(L, (Vector2)obj); } else if (t == typeof(Vector4)) { Push(L, (Vector4)obj); } else if (t == typeof(Color)) { Push(L, (Color)obj); } else if (t == typeof(RaycastHit)) { Push(L, (RaycastHit)obj); } else if (t == typeof(Touch)) { Push(L, (Touch)obj); } else if (t == typeof(Ray)) { Push(L, (Ray)obj); } else if (t == typeof(Bounds)) { Push(L, (Bounds)obj); } else if (t == typeof(LayerMask)) { Push(L, (LayerMask)obj); } else { PushValue(L, (ValueType)obj); } } else { if (t.IsArray) { Push(L, (Array)obj); } else if (t == typeof(string)) { LuaDLL.lua_pushstring(L, (string)obj); } else if (t.IsSubclassOf(typeof(LuaBaseRef))) { Push(L, (LuaBaseRef)obj); } else if (t.IsSubclassOf(typeof(UnityEngine.Object))) { Push(L, (UnityEngine.Object)obj); } else if (t.IsSubclassOf(typeof(UnityEngine.TrackedReference))) { Push(L, (UnityEngine.TrackedReference)obj); } else if (t == typeof(LuaByteBuffer)) { LuaByteBuffer lbb = (LuaByteBuffer)obj; LuaDLL.lua_pushlstring(L, lbb.buffer, lbb.buffer.Length); } else if (t.IsSubclassOf(typeof(Delegate))) { Push(L, (Delegate)obj); } else if (obj is System.Collections.IEnumerator) { Push(L, (IEnumerator)obj); } else if (t == typeof(EventObject)) { Push(L, (EventObject)obj); } else if (t == monoType) { Push(L, (Type)obj); } else { PushObject(L, obj); } } }
public static void Push(IntPtr L, object obj) { if (obj == null) { LuaDLL.lua_pushnil(L); return; } Type type = obj.GetType(); if (type.get_IsValueType()) { if (type == typeof(bool)) { bool value = (bool)obj; LuaDLL.lua_pushboolean(L, value); } else if (type.get_IsEnum()) { ToLua.Push(L, (Enum)obj); } else if (type.get_IsPrimitive()) { double number = LuaMisc.ToDouble(obj); LuaDLL.lua_pushnumber(L, number); } else if (type == typeof(Vector3)) { ToLua.Push(L, (Vector3)obj); } else if (type == typeof(Quaternion)) { ToLua.Push(L, (Quaternion)obj); } else if (type == typeof(Vector2)) { ToLua.Push(L, (Vector2)obj); } else if (type == typeof(Vector4)) { ToLua.Push(L, (Vector4)obj); } else if (type == typeof(Color)) { ToLua.Push(L, (Color)obj); } else if (type == typeof(RaycastHit)) { ToLua.Push(L, (RaycastHit)obj); } else if (type == typeof(Touch)) { ToLua.Push(L, (Touch)obj); } else if (type == typeof(Ray)) { ToLua.Push(L, (Ray)obj); } else if (type == typeof(Bounds)) { ToLua.Push(L, (Bounds)obj); } else if (type == typeof(LayerMask)) { ToLua.PushLayerMask(L, (LayerMask)obj); } else { ToLua.PushValue(L, (ValueType)obj); } } else if (type.get_IsArray()) { ToLua.Push(L, (Array)obj); } else if (type == typeof(string)) { LuaDLL.lua_pushstring(L, (string)obj); } else if (type.IsSubclassOf(typeof(LuaBaseRef))) { ToLua.Push(L, (LuaBaseRef)obj); } else if (type.IsSubclassOf(typeof(Object))) { ToLua.Push(L, (Object)obj); } else if (type.IsSubclassOf(typeof(TrackedReference))) { ToLua.Push(L, (TrackedReference)obj); } else if (type == typeof(LuaByteBuffer)) { LuaByteBuffer luaByteBuffer = (LuaByteBuffer)obj; LuaDLL.lua_pushlstring(L, luaByteBuffer.buffer, luaByteBuffer.buffer.Length); } else if (type.IsSubclassOf(typeof(Delegate))) { ToLua.Push(L, (Delegate)obj); } else if (obj is IEnumerator) { ToLua.Push(L, (IEnumerator)obj); } else if (type == typeof(EventObject)) { ToLua.Push(L, (EventObject)obj); } else if (type == ToLua.monoType) { ToLua.Push(L, (Type)obj); } else { ToLua.PushObject(L, obj); } }