示例#1
0
 public static void Clear()
 {
     className     = null;
     type          = null;
     baseType      = null;
     isStaticClass = false;
     usingList.Clear();
     op     = MetaOp.None;
     sb     = new StringBuilder();
     fields = null;
     props  = null;
     methods.Clear();
     allProps.Clear();
     propList.Clear();
     eventList.Clear();
     ctorList.Clear();
     ctorExtList.Clear();
     ambig         = ObjAmbig.NetObj;
     wrapClassName = "";
     libClassName  = "";
     extendName    = "";
     eventSet.Clear();
     extendType = null;
     nameCounter.Clear();
     events = null;
     getItems.Clear();
     setItems.Clear();
 }
示例#2
0
    static void ProcessArg(Type varType, string head, string arg, int stackPos, bool beCheckTypes = false, bool beParams = false, bool beOutArg = false)
    {
        varType = GetRefBaseType(varType);
        string str = GetTypeStr(varType);
        string checkStr = beCheckTypes ? "To" : "Check";

        if (beOutArg)
        {
            if (varType.IsValueType)
            {
                sb.AppendFormat("{0}{1} {2};\r\n", head, str, arg);
            }
            else
            {
                sb.AppendFormat("{0}{1} {2} = null;\r\n", head, str, arg);
            }
        }
        else if (varType == typeof(bool))
        {
            string chkstr = beCheckTypes ? "lua_toboolean" : "luaL_checkboolean";
            sb.AppendFormat("{0}bool {1} = LuaDLL.{2}(L, {3});\r\n", head, arg, chkstr, stackPos);
        }
        else if (varType == typeof(string))
        {
            sb.AppendFormat("{0}string {1} = ToLua.{2}String(L, {3});\r\n", head, arg, checkStr, stackPos);
        }
        else if (varType == typeof(IntPtr))
        {
            sb.AppendFormat("{0}{1} {2} = ({1})LuaDLL.lua_touserdata(L, {3});\r\n", head, str, arg, stackPos);
        }
        else if (varType.IsPrimitive || IsNumberEnum(varType))
        {
            string chkstr = beCheckTypes ? "lua_tonumber" : "luaL_checknumber";
            sb.AppendFormat("{0}{1} {2} = ({1})LuaDLL.{3}(L, {4});\r\n", head, str, arg, chkstr, stackPos);
        }
        else if (varType == typeof(LuaFunction))
        {
            sb.AppendFormat("{0}LuaFunction {1} = ToLua.{2}LuaFunction(L, {3});\r\n", head, arg, checkStr, stackPos);
        }
        else if (varType.IsSubclassOf(typeof(System.MulticastDelegate)))
        {
            sb.AppendFormat("{0}{1} {2} = null;\r\n", head, str, arg);
            sb.AppendFormat("{0}LuaTypes funcType{1} = LuaDLL.lua_type(L, {1});\r\n", head, stackPos);
            sb.AppendLineEx();
            sb.AppendFormat("{0}if (funcType{1} != LuaTypes.LUA_TFUNCTION)\r\n", head, stackPos);
            sb.AppendLineEx(head + "{");

            if (beCheckTypes)
            {
                sb.AppendFormat("{3} {1} = ({0})ToLua.ToObject(L, {2});\r\n", str, arg, stackPos, head + "\t");
            }
            else
            {
                sb.AppendFormat("{3} {1} = ({0})ToLua.CheckObject(L, {2}, typeof({0}));\r\n", str, arg, stackPos, head + "\t");
            }

            sb.AppendFormat("{0}}}\r\n{0}else\r\n{0}{{\r\n", head);
            sb.AppendFormat("{0}\tLuaFunction func = ToLua.ToLuaFunction(L, {1});\r\n", head, stackPos);
            sb.AppendFormat("{0}\t{1} = DelegateFactory.CreateDelegate(typeof({2}), func) as {2};\r\n", head, arg, GetTypeStr(varType));

            sb.AppendLineEx(head + "}");
            sb.AppendLineEx();
        }
        else if (varType == typeof(LuaTable))
        {
            sb.AppendFormat("{0}LuaTable {1} = ToLua.{2}LuaTable(L, {3});\r\n", head, arg, checkStr, stackPos);
        }
        else if (varType == typeof(Vector2))
        {
            sb.AppendFormat("{0}UnityEngine.Vector2 {1} = ToLua.ToVector2(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(Vector3))
        {
            sb.AppendFormat("{0}UnityEngine.Vector3 {1} = ToLua.ToVector3(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(Vector4))
        {
            sb.AppendFormat("{0}UnityEngine.Vector4 {1} = ToLua.ToVector4(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(Quaternion))
        {
            sb.AppendFormat("{0}UnityEngine.Quaternion {1} = ToLua.ToQuaternion(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(Color))
        {
            sb.AppendFormat("{0}UnityEngine.Color {1} = ToLua.ToColor(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(Ray))
        {
            sb.AppendFormat("{0}UnityEngine.Ray {1} = ToLua.ToRay(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(Bounds))
        {
            sb.AppendFormat("{0}UnityEngine.Bounds {1} = ToLua.ToBounds(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(LayerMask))
        {
            sb.AppendFormat("{0}UnityEngine.LayerMask {1} = ToLua.ToLayerMask(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(LuaInteger64))
        {
            string chkstr = beCheckTypes ? "LuaDLL.tolua_toint64" : "ToLua.CheckLuaInteger64";
            sb.AppendFormat("{0}LuaInteger64 {1} = {2}(L, {3});\r\n", head, arg, chkstr, stackPos);
        }
        else if (varType == typeof(object))
        {
            sb.AppendFormat("{0}object {1} = ToLua.ToVarObject(L, {2});\r\n", head, arg, stackPos);
        }
        else if (varType == typeof(LuaByteBuffer))
        {
            sb.AppendFormat("{0}LuaByteBuffer {1} = new LuaByteBuffer(ToLua.{2}ByteBuffer(L, {3}));\r\n", head, arg, checkStr, stackPos);
        }
        else if (varType.IsArray)
        {
            Type et = varType.GetElementType();
            string atstr = GetTypeStr(et);
            string fname;
            bool flag = false;                          //是否模版函数
            bool isObject = false;

            if (et.IsPrimitive)
            {
                if (beParams)
                {
                    if (et == typeof(bool))
                    {
                        fname = beCheckTypes ? "ToParamsBool" : "CheckParamsBool";
                    }
                    else if (et == typeof(char))
                    {
                        //char用的多些,特殊处理一下减少gcalloc
                        fname = beCheckTypes ? "ToParamsChar" : "CheckParamsChar";
                    }
                    else
                    {
                        flag = true;
                        fname = beCheckTypes ? "ToParamsNumber" : "CheckParamsNumber";
                    }
                }
                else if(et == typeof(char))
                {
                    fname = "CheckCharBuffer";      //使用Table传数组,CheckType只是简单匹配。需要读取函数继续匹配
                }
                else if (et == typeof(byte))
                {
                    fname = "CheckByteBuffer";
                }
                else
                {
                    fname = "CheckNumberArray";
                    flag = true;
                }
            }
            else if (et == typeof(string))
            {
                if (beParams)
                {
                    fname = beCheckTypes ? "ToParamsString" : "CheckParamsString";
                }
                else
                {
                    fname = "CheckStringArray";
                }
            }
            else //if (et == typeof(object))
            {
                flag = true;

                if (et == typeof(object))
                {
                    isObject = true;
                    flag = false;
                }

                if (beParams)
                {
                    fname = (isObject || beCheckTypes) ? "ToParamsObject" : "CheckParamsObject";
                }
                else
                {
                    fname = "CheckObjectArray";
                }

                if (et == typeof(UnityEngine.Object))
                {
                    ambig |= ObjAmbig.U3dObj;
                }
            }

            if (flag)
            {
                if (beParams)
                {
                    if (!isObject)
                    {
                        sb.AppendFormat("{0}{1}[] {2} = ToLua.{3}<{1}>(L, {4}, {5});\r\n", head, atstr, arg, fname, stackPos, GetCountStr(stackPos - 1));
                    }
                    else
                    {
                        sb.AppendFormat("{0}object[] {1} = ToLua.{2}(L, {3}, {4});\r\n", head, arg, fname, stackPos, GetCountStr(stackPos - 1));
                    }
                }
                else
                {
                    sb.AppendFormat("{0}{1}[] {2} = ToLua.{3}<{1}>(L, {4});\r\n", head, atstr, arg, fname, stackPos);
                }
            }
            else
            {
                if (beParams)
                {
                    sb.AppendFormat("{0}{1}[] {2} = ToLua.{3}(L, {4}, {5});\r\n", head, atstr, arg, fname, stackPos, GetCountStr(stackPos - 1));
                }
                else
                {
                    sb.AppendFormat("{0}{1}[] {2} = ToLua.{3}(L, {4});\r\n", head, atstr, arg, fname, stackPos);
                }
            }
        }
        else //从object派生但不是object
        {
            if (beCheckTypes)
            {
                sb.AppendFormat("{0}{1} {2} = ({1})ToLua.ToObject(L, {3});\r\n", head, str, arg, stackPos);
            }
            else if (varType == typeof(UnityEngine.TrackedReference) || typeof(UnityEngine.TrackedReference).IsAssignableFrom(varType))
            {
                sb.AppendFormat("{3}{0} {1} = ({0})ToLua.CheckTrackedReference(L, {2}, typeof({0}));\r\n", str, arg, stackPos, head);
            }
            else if (typeof(UnityEngine.Object).IsAssignableFrom(varType))
            {
                sb.AppendFormat("{3}{0} {1} = ({0})ToLua.CheckUnityObject(L, {2}, typeof({0}));\r\n", str, arg, stackPos, head);
            }
            else if (varType.IsGenericType && varType.GetGenericTypeDefinition() == typeof(Nullable<>))
            {
                sb.AppendFormat("{0}{1} {2} = ({1})ToLua.CheckVarObject(L, {3}, typeof({1}));\r\n", head, str, arg, stackPos);
            }
            else
            {
                sb.AppendFormat("{0}{1} {2} = ({1})ToLua.CheckObject(L, {3}, typeof({1}));\r\n", head, str, arg, stackPos);
            }
        }
    }
示例#3
0
 public static void Clear()
 {
     className = null;
     type = null;
     baseType = null;
     isStaticClass = false;
     usingList.Clear();
     op = MetaOp.None;
     sb = new StringBuilder();
     fields = null;
     props = null;
     methods.Clear();
     allProps.Clear();
     propList.Clear();
     eventList.Clear();
     ctorList.Clear();
     ctorExtList.Clear();
     ambig = ObjAmbig.NetObj;
     wrapClassName = "";
     libClassName = "";
     extendName = "";
     eventSet.Clear();
     extendType = null;
     nameCounter.Clear();
     events = null;
     getItems.Clear();
     setItems.Clear();
 }
示例#4
0
    public static string _C(string str)
    {
        if (str.Length > 1 && str[str.Length - 1] == '&')
        {
            str = str.Remove(str.Length - 1);
        }

        if (str == "System.Single" || str == "Single")
        {
            return "float";
        }
        else if (str == "System.String" || str == "String")
        {
            return "string";
        }
        else if (str == "System.Int32" || str == "Int32")
        {
            return "int";
        }
        else if (str == "System.Int64" || str == "Int64")
        {
            return "long";
        }
        else if (str == "System.SByte" || str == "SByte")
        {
            return "sbyte";
        }
        else if (str == "System.Byte" || str == "Byte")
        {
            return "byte";
        }
        else if (str == "System.Int16" || str == "Int16")
        {
            return "short";
        }
        else if (str == "System.UInt16" || str == "UInt16")
        {
            return "ushort";
        }
        else if (str == "System.Char" || str == "Char")
        {
            return "char";
        }
        else if (str == "System.UInt32" || str == "UInt32")
        {
            return "uint";
        }
        else if (str == "System.UInt64" || str == "UInt64")
        {
            return "ulong";
        }
        else if (str == "System.Decimal" || str == "Decimal")
        {
            return "decimal";
        }
        else if (str == "System.Double" || str == "Double")
        {
            return "double";
        }
        else if (str == "System.Boolean" || str == "Boolean")
        {
            return "bool";
        }
        else if (str == "System.Object")
        {
            return "object";
        }

        if (str.Contains("."))
        {
            int pos1 = str.LastIndexOf('.');
            string nameSpace = str.Substring(0, pos1);

            if (str.Length > 12 && str.Substring(0, 12) == "UnityEngine.")
            {
                if (nameSpace == "UnityEngine")
                {
                    usingList.Add("UnityEngine");
                }

                if (str == "UnityEngine.Object")
                {
                    ambig |= ObjAmbig.U3dObj;
                }
            }
            else if (str.Length > 7 && str.Substring(0, 7) == "System.")
            {
                if (nameSpace == "System.Collections")
                {
                    usingList.Add(nameSpace);
                }
                else if (nameSpace == "System.Collections.Generic")
                {
                    usingList.Add(nameSpace);
                }
                else if (nameSpace == "System")
                {
                    usingList.Add(nameSpace);
                }

                if (str == "System.Object")
                {
                    str = "object";
                }
            }

            if (usingList.Contains(nameSpace))
            {
                str = str.Substring(pos1 + 1);
            }

            //foreach(string ns in usingList)
            //{
            //    int len = ns.Length;

            //    if (str.Length > len)
            //    {
            //        string ss = str.Substring(0, len);

            //        if (ss == ns)
            //        {
            //            str = str.Substring(len + 1);
            //        }
            //    }
            //}
        }

        if (str.Contains("+"))
        {
            return str.Replace('+', '.');
        }

        if (str == extendName)
        {
            return GetTypeStr(type);
        }

        return str;
    }
示例#5
0
    static int ProcessParams(MethodBase md, int tab, bool beConstruct, bool beLuaString, bool beCheckTypes = false)
    {
        ParameterInfo[] paramInfos = md.GetParameters();
        int count = paramInfos.Length;
        string head = string.Empty;

        for (int i = 0; i < tab; i++)
        {
            head += "\t";
        }

        if (!md.IsStatic && !beConstruct)
        {
            if (md.Name == "Equals")
            {
                if (!type.IsValueType)
                {
                    sb.AppendFormat("{0}{1} obj = LuaScriptMgr.GetVarObject(L, 1) as {1};\r\n", head, className);
                }
                else
                {
                    sb.AppendFormat("{0}{1} obj = ({1})LuaScriptMgr.GetVarObject(L, 1);\r\n", head, className);
                }
            }
            else if (className != "Type" && className != "System.Type")
            {
                if (typeof(UnityEngine.Object).IsAssignableFrom(type))
                {
                    sb.AppendFormat("{0}{1} obj = ({1})LuaScriptMgr.GetUnityObjectSelf(L, 1, \"{1}\");\r\n", head, className);
                }
                else if(typeof(UnityEngine.TrackedReference).IsAssignableFrom(type))
                {
                    sb.AppendFormat("{0}{1} obj = ({1})LuaScriptMgr.GetTrackedObjectSelf(L, 1, \"{1}\");\r\n", head, className);
                }
                else
                {
                    sb.AppendFormat("{0}{1} obj = ({1})LuaScriptMgr.GetNetObjectSelf(L, 1, \"{1}\");\r\n", head, className);
                }
            }
            else
            {
                sb.AppendFormat("{0}{1} obj = LuaScriptMgr.GetTypeObject(L, 1);\r\n", head, className);
            }
        }

        for (int j = 0; j < count; j++)
        {
            ParameterInfo param = paramInfos[j];
            string str = GetTypeStr(param.ParameterType);

            string arg = "arg" + j;
            int offset = (md.IsStatic || beConstruct) ? 1 : 2;

            if (param.Attributes == ParameterAttributes.Out)
            {
                Type outType = GetRefBaseType(param.ParameterType.ToString());

                if (outType.IsValueType)
                {
                    sb.AppendFormat("{0}{1} {2};\r\n", head, str, arg);
                }
                else
                {
                    sb.AppendFormat("{0}{1} {2} = null;\r\n", head, str, arg);
                }
            }
            else if (param.ParameterType == typeof(bool))
            {
                if (beCheckTypes)
                {
                    sb.AppendFormat("{2}bool {0} = LuaDLL.lua_toboolean(L, {1});\r\n", arg, j + offset, head);
                }
                else
                {
                    sb.AppendFormat("{2}bool {0} = LuaScriptMgr.GetBoolean(L, {1});\r\n", arg, j + offset, head);
                }
            }
            else if (param.ParameterType == typeof(string))
            {
                string getStr = beLuaString ? "GetString" : "GetLuaString";
                sb.AppendFormat("{2}string {0} = LuaScriptMgr.{3}(L, {1});\r\n", arg, j + offset, head, getStr);
            }
            else if (param.ParameterType.IsPrimitive)
            {
                if (beCheckTypes)
                {
                    sb.AppendFormat("{3}{0} {1} = ({0})LuaDLL.lua_tonumber(L, {2});\r\n", str, arg, j + offset, head);
                }
                else
                {
                    sb.AppendFormat("{3}{0} {1} = ({0})LuaScriptMgr.GetNumber(L, {2});\r\n", str, arg, j + offset, head);
                }
            }
            else if (param.ParameterType == typeof(LuaFunction))
            {
                if (beCheckTypes)
                {
                    sb.AppendFormat("{2}LuaFunction {0} = LuaScriptMgr.ToLuaFunction(L, {1});\r\n", arg, j + offset, head);
                }
                else
                {
                    sb.AppendFormat("{2}LuaFunction {0} = LuaScriptMgr.GetLuaFunction(L, {1});\r\n", arg, j + offset, head);
                }
            }
            else if (param.ParameterType.IsSubclassOf(typeof(System.MulticastDelegate)))
            {
                sb.AppendFormat("{0}{1} {2} = null;\r\n", head, str, arg);
                sb.AppendFormat("{0}LuaTypes funcType{1} = LuaDLL.lua_type(L, {1});\r\n", head, j);
                sb.AppendLine();
                sb.AppendFormat("{0}if (funcType{1} != LuaTypes.LUA_TFUNCTION)\r\n", head, j);
                sb.AppendLine(head + "{");

                if (beCheckTypes)
                {
                    sb.AppendFormat("{3} {1} = ({0})LuaScriptMgr.GetLuaObject(L, {2});\r\n", str, arg, j + offset, head + "\t");
                }
                else
                {
                    sb.AppendFormat("{3} {1} = ({0})LuaScriptMgr.GetNetObject(L, {2}, typeof({0}));\r\n", str, arg, j + offset, head + "\t");
                }

                sb.AppendFormat("{0}}}\r\n{0}else\r\n{0}{{\r\n", head);
                sb.AppendFormat("{0}\tLuaFunction func = LuaScriptMgr.GetLuaFunction(L, {1});\r\n", head, j + offset);
                sb.AppendFormat("{0}\t{1} = ", head, arg);

                GenDelegateBody(param.ParameterType, head + "\t", true);
                sb.AppendLine(head + "}\r\n");
            }
            else if (param.ParameterType == typeof(LuaTable))
            {
                if (beCheckTypes)
                {
                    sb.AppendFormat("{2}LuaTable {0} = LuaScriptMgr.ToLuaTable(L, {1});\r\n", arg, j + offset, head);
                }
                else
                {
                    sb.AppendFormat("{2}LuaTable {0} = LuaScriptMgr.GetLuaTable(L, {1});\r\n", arg, j + offset, head);
                }
            }
            else if (param.ParameterType == typeof(Vector2) || GetRefBaseType(param.ParameterType.ToString()) == typeof(Vector2))
            {
                sb.AppendFormat("{2}Vector2 {0} = LuaScriptMgr.GetVector2(L, {1});\r\n", arg, j + offset, head);
            }
            else if (param.ParameterType == typeof(Vector3) || GetRefBaseType(param.ParameterType.ToString()) == typeof(Vector3))
            {
                sb.AppendFormat("{2}Vector3 {0} = LuaScriptMgr.GetVector3(L, {1});\r\n", arg, j + offset, head);
            }
            else if (param.ParameterType == typeof(Vector4) || GetRefBaseType(param.ParameterType.ToString()) == typeof(Vector4))
            {
                sb.AppendFormat("{2}Vector4 {0} = LuaScriptMgr.GetVector4(L, {1});\r\n", arg, j + offset, head);
            }
            else if (param.ParameterType == typeof(Quaternion) || GetRefBaseType(param.ParameterType.ToString()) == typeof(Quaternion))
            {
                sb.AppendFormat("{2}Quaternion {0} = LuaScriptMgr.GetQuaternion(L, {1});\r\n", arg, j + offset, head);
            }
            else if (param.ParameterType == typeof(Color) || GetRefBaseType(param.ParameterType.ToString()) == typeof(Color))
            {
                sb.AppendFormat("{2}Color {0} = LuaScriptMgr.GetColor(L, {1});\r\n", arg, j + offset, head);
            }
            else if (param.ParameterType == typeof(Ray) || GetRefBaseType(param.ParameterType.ToString()) == typeof(Ray))
            {
                sb.AppendFormat("{2}Ray {0} = LuaScriptMgr.GetRay(L, {1});\r\n", arg, j + offset, head);
            }
            else if(param.ParameterType == typeof(Bounds) || GetRefBaseType(param.ParameterType.ToString()) == typeof(Bounds))
            {
                sb.AppendFormat("{2}Bounds {0} = LuaScriptMgr.GetBounds(L, {1});\r\n", arg, j + offset, head);
            }
            else if (param.ParameterType == typeof(object))
            {
                sb.AppendFormat("{2}object {0} = LuaScriptMgr.GetVarObject(L, {1});\r\n", arg, j + offset, head);
            }
            else if (param.ParameterType == typeof(Type))
            {
                sb.AppendFormat("{0}{1} {2} = LuaScriptMgr.GetTypeObject(L, {3});\r\n", head, str, arg, j + offset);
            }
            else if (param.ParameterType == typeof(LuaStringBuffer))
            {
                sb.AppendFormat("{2}LuaStringBuffer {0} = LuaScriptMgr.GetStringBuffer(L, {1});\r\n", arg, j + offset, head);
            }
            else if (param.ParameterType.IsArray)
            {
                Type et = param.ParameterType.GetElementType();
                string atstr = GetTypeStr(et);
                string fname = "GetArrayObject";
                bool flag = false;
                bool optional = false;
                bool isObject = false;

                if (et == typeof(bool))
                {
                    fname = "GetArrayBool";
                }
                else if (et.IsPrimitive)
                {
                    flag = true;
                    fname = "GetArrayNumber";
                }
                else if (et == typeof(string))
                {
                    optional = IsParams(param);
                    fname = optional ? "GetParamsString" : "GetArrayString";
                }
                else //if (et == typeof(object))
                {
                    flag = true;
                    optional = IsParams(param);
                    fname = optional ? "GetParamsObject" : "GetArrayObject";

                    if (et == typeof(object))
                    {
                        isObject = true;
                    }

                    if (et == typeof(UnityEngine.Object))
                    {
                        ambig |= ObjAmbig.U3dObj;
                    }
                }

                if (flag)
                {
                    if (optional)
                    {
                        if (!isObject)
                        {
                            sb.AppendFormat("{5}{0}[] objs{2} = LuaScriptMgr.{4}<{0}>(L, {1}, {3});\r\n", atstr, j + offset, j, GetCountStr(j + offset - 1), fname, head);
                        }
                        else
                        {
                            sb.AppendFormat("{4}object[] objs{1} = LuaScriptMgr.{3}(L, {0}, {2});\r\n", j + offset, j, GetCountStr(j + offset - 1), fname, head);
                        }
                    }
                    else
                    {
                        sb.AppendFormat("{4}{0}[] objs{2} = LuaScriptMgr.{3}<{0}>(L, {1});\r\n", atstr, j + offset, j, fname, head);
                    }
                }
                else
                {
                    if (optional)
                    {
                        sb.AppendFormat("{5}{0}[] objs{2} = LuaScriptMgr.{4}(L, {1}, {3});\r\n", atstr, j + offset, j, GetCountStr(j + offset - 1), fname, head);
                    }
                    else
                    {
                        sb.AppendFormat("{5}{0}[] objs{2} = LuaScriptMgr.{4}(L, {1});\r\n", atstr, j + offset, j, j + offset - 1, fname, head);
                    }
                }
            }
            else //if (param.ParameterType == typeof(object))
            {
                if (md.Name == "op_Equality")
                {
                    if (!type.IsValueType) // && type.IsEnum)
                    {
                        sb.AppendFormat("{3}{0} {1} = LuaScriptMgr.GetLuaObject(L, {2}) as {0};\r\n", str, arg, j + offset, head);
                    }
                    else
                    {
                        sb.AppendFormat("{3}{0} {1} = ({0})LuaScriptMgr.GetVarObject(L, {2});\r\n", str, arg, j + offset, head);
                    }
                }
                else
                {
                    if (beCheckTypes)
                    {
                        sb.AppendFormat("{3}{0} {1} = ({0})LuaScriptMgr.GetLuaObject(L, {2});\r\n", str, arg, j + offset, head);
                    }
                    else if (typeof(UnityEngine.Object).IsAssignableFrom(param.ParameterType))
                    {
                        sb.AppendFormat("{3}{0} {1} = ({0})LuaScriptMgr.GetUnityObject(L, {2}, typeof({0}));\r\n", str, arg, j + offset, head);
                    }
                    else if (typeof(UnityEngine.TrackedReference).IsAssignableFrom(param.ParameterType))
                    {
                        sb.AppendFormat("{3}{0} {1} = ({0})LuaScriptMgr.GetTrackedObject(L, {2}, typeof({0}));\r\n", str, arg, j + offset, head);
                    }
                    else
                    {
                        sb.AppendFormat("{3}{0} {1} = ({0})LuaScriptMgr.GetNetObject(L, {2}, typeof({0}));\r\n", str, arg, j + offset, head);
                    }
                }
            }
        }

        StringBuilder sbArgs = new StringBuilder();
        List<string> refList = new List<string>();
        List<Type> refTypes = new List<Type>();

        for (int j = 0; j < count - 1; j++)
        {
            ParameterInfo param = paramInfos[j];

            if (!param.ParameterType.IsArray)
            {
                if (!param.ParameterType.ToString().Contains("&"))
                {
                    sbArgs.Append("arg");
                }
                else
                {
                    if (param.Attributes == ParameterAttributes.Out)
                    {
                        sbArgs.Append("out arg");
                    }
                    else
                    {
                        sbArgs.Append("ref arg");
                    }

                    refList.Add("arg" + j);
                    refTypes.Add(GetRefBaseType(param.ParameterType.ToString()));
                }
            }
            else
            {
                sbArgs.Append("objs");
            }

            sbArgs.Append(j);
            sbArgs.Append(",");
        }

        if (count > 0)
        {
            ParameterInfo param = paramInfos[count - 1];

            if (!param.ParameterType.IsArray)
            {
                if (!param.ParameterType.ToString().Contains("&"))
                {
                    sbArgs.Append("arg");
                }
                else
                {
                    if (param.Attributes == ParameterAttributes.Out)
                    {
                        sbArgs.Append("out arg");
                    }
                    else
                    {
                        sbArgs.Append("ref arg");
                    }

                    refList.Add("arg" + (count - 1));
                    refTypes.Add(GetRefBaseType(param.ParameterType.ToString()));
                }
            }
            else
            {
                sbArgs.Append("objs");
            }

            sbArgs.Append(count - 1);
        }

        if (beConstruct)
        {
            sb.AppendFormat("{2}{0} obj = new {0}({1});\r\n", className, sbArgs.ToString(), head);
            string str = GetPushFunction(type);
            sb.AppendFormat("{0}LuaScriptMgr.{1}(L, obj);\r\n", head, str);

            for (int i = 0; i < refList.Count; i++)
            {
                str = GetPushFunction(refTypes[i]);
                sb.AppendFormat("{1}LuaScriptMgr.{2}(L, {0});\r\n", refList[i], head, str);
            }

            return refList.Count + 1;
        }

        string obj = md.IsStatic ? className : "obj";
        MethodInfo m = md as MethodInfo;

        if (m.ReturnType == typeof(void))
        {
            if (md.Name == "set_Item")
            {
                if (count == 2)
                {
                    sb.AppendFormat("{0}{1}[arg0] = arg1;\r\n", head, obj);
                }
                else if (count == 3)
                {
                    sb.AppendFormat("{0}{1}[arg0, arg1] = arg2;\r\n", head, obj);
                }
            }
            else
            {
                sb.AppendFormat("{3}{0}.{1}({2});\r\n", obj, md.Name, sbArgs.ToString(), head);
            }

            if (!md.IsStatic && type.IsValueType)
            {
                sb.AppendFormat("{0}LuaScriptMgr.SetValueObject(L, 1, obj);\r\n", head);
            }
        }
        else
        {
            string ret = GetTypeStr(m.ReturnType);

            if (md.Name.Contains("op_"))
            {
                CallOpFunction(md.Name, tab, ret);
            }
            else if (md.Name == "get_Item")
            {
                sb.AppendFormat("{4}{3} o = {0}[{2}];\r\n", obj, md.Name, sbArgs.ToString(), ret, head);
            }
            else if (md.Name == "Equals")
            {
                if (type.IsValueType)
                {
                    sb.AppendFormat("{0}bool o = obj.Equals(arg0);\r\n", head);
                }
                else
                {
                    sb.AppendFormat("{0}bool o = obj != null ? obj.Equals(arg0) : arg0 == null;\r\n", head);
                }
            }
            else
            {
                sb.AppendFormat("{4}{3} o = {0}.{1}({2});\r\n", obj, md.Name, sbArgs.ToString(), ret, head);
            }

            string str = GetPushFunction(m.ReturnType);
            sb.AppendFormat("{0}LuaScriptMgr.{1}(L, o);\r\n", head, str);
        }

        for (int i = 0; i < refList.Count; i++)
        {
            string str = GetPushFunction(refTypes[i]);
            sb.AppendFormat("{1}LuaScriptMgr.{2}(L, {0});\r\n", refList[i], head, str);
        }

        return refList.Count;
    }
示例#6
0
    static void NewIndexSetValue(Type t, string o, string name)
    {
        if (t.IsArray)
        {
            Type et = t.GetElementType();
            string atstr = GetTypeStr(et);

            if (et == typeof(bool))
            {
                sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetArrayBool(L, 3);\r\n", o, name);
            }
            else if (et.IsPrimitive)
            {
                sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetArrayNumber<{2}>(L, 3);\r\n", o, name, atstr);
            }
            else if (et == typeof(string))
            {
                sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetArrayString(L, 3);\r\n", o, name);
            }
            else
            {
                if (et == typeof(UnityEngine.Object))
                {
                    ambig |= ObjAmbig.U3dObj;
                }

                sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetArrayObject<{2}>(L, 3);\r\n", o, name, atstr);
            }

            return;
        }

        if (t == typeof(bool))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetBoolean(L, 3);\r\n", o, name);
        }
        else if (t == typeof(string))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetString(L, 3);\r\n", o, name);
        }
        else if (t.IsPrimitive)
        {
            sb.AppendFormat("\t\t{0}.{1} = ({2})LuaScriptMgr.GetNumber(L, 3);\r\n", o, name, _C(t.ToString()));
        }
        else if (t == typeof(LuaFunction))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetLuaFunction(L, 3);\r\n", o, name);
        }
        else if (t == typeof(LuaTable))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetLuaTable(L, 3);\r\n", o, name);
        }
        else if (t == typeof(object))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetVarObject(L, 3);\r\n", o, name);
        }
        else if (t == typeof(Vector3))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetVector3(L, 3);\r\n", o, name);
        }
        else if (t == typeof(Quaternion))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetQuaternion(L, 3);\r\n", o, name);
        }
        else if (t == typeof(Vector2))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetVector2(L, 3);\r\n", o, name);
        }
        else if (t == typeof(Vector4))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetVector4(L, 3);\r\n", o, name);
        }
        else if (t == typeof(Color))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetColor(L, 3);\r\n", o, name);
        }
        else if (t == typeof(Ray))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetRay(L, 3);\r\n", o, name);
        }
        else if (t == typeof(Bounds))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetBounds(L, 3);\r\n", o, name);
        }
        else if (t == typeof(LuaStringBuffer))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetStringBuffer(L, 3);\r\n", o, name);
        }
        else if (typeof(UnityEngine.TrackedReference).IsAssignableFrom(t))
        {
            sb.AppendFormat("\t\t{0}.{1} = ({2})LuaScriptMgr.GetTrackedObject(L, 3, typeof(2));\r\n", o, name, GetTypeStr(t));
        }
        else if (typeof(UnityEngine.Object).IsAssignableFrom(t))
        {
            sb.AppendFormat("\t\t{0}.{1} = ({2})LuaScriptMgr.GetUnityObject(L, 3, typeof({2}));\r\n", o, name, GetTypeStr(t));
        }
        else if (typeof(System.Delegate).IsAssignableFrom(t))
        {
            sb.AppendLine("\t\tLuaTypes funcType = LuaDLL.lua_type(L, 3);\r\n");
            sb.AppendLine("\t\tif (funcType != LuaTypes.LUA_TFUNCTION)");
            sb.AppendLine("\t\t{");
            sb.AppendFormat("\t\t\t{0}.{1} = ({2})LuaScriptMgr.GetNetObject(L, 3, typeof({2}));\r\n", o, name, GetTypeStr(t));
            sb.AppendLine("\t\t}\r\n\t\telse");
            sb.AppendLine("\t\t{");
            sb.AppendLine("\t\t\tLuaFunction func = LuaScriptMgr.ToLuaFunction(L, 3);");
            sb.AppendFormat("\t\t\t{0}.{1} = ", o, name);
            GenDelegateBody(t, "\t\t\t", true);
            sb.AppendLine("\t\t}");
        }
        else if (typeof(object).IsAssignableFrom(t) || t.IsEnum)
        {
            sb.AppendFormat("\t\t{0}.{1} = ({2})LuaScriptMgr.GetNetObject(L, 3, typeof({2}));\r\n", o, name, GetTypeStr(t));
        }
        else if (t == typeof(Type))
        {
            sb.AppendFormat("\t\t{0}.{1} = LuaScriptMgr.GetTypeObject(L, 3);\r\n", o, name);
        }
        else
        {
            Debugger.LogError("not defined type {0}", t);
        }
    }
示例#7
0
 public static void Clear()
 {
     className = null;
     type = null;
     isStaticClass = false;
     baseClassName = null;
     usingList.Clear();
     op = MetaOp.None;
     sb = new StringBuilder();
     methods = null;
     fields = null;
     props = null;
     propList.Clear();
     ambig = ObjAmbig.NetObj;
     wrapClassName = "";
     libClassName = "";
 }