Example #1
0
 void LoadType(IntPtr isolate, IntPtr info, IntPtr self, int paramLen)
 {
     try
     {
         Type type  = null;
         var  value = PuertsDLL.GetArgumentValue(info, 0);
         if (PuertsDLL.GetJsValueType(isolate, value, false) == JsValueType.String)
         {
             string classFullName = PuertsDLL.GetStringFromValue(isolate, value, false);
             var    maybeType     = TypeRegister.GetType(classFullName);
             if (paramLen == 1)
             {
                 type = maybeType;
             }
             else if (maybeType != null &&
                      maybeType.IsGenericTypeDefinition &&
                      maybeType.GetGenericArguments().Length == (paramLen - 1)) //泛型
             {
                 var genericArguments = new Type[paramLen - 1];
                 for (int i = 1; i < paramLen; i++)
                 {
                     value = PuertsDLL.GetArgumentValue(info, i);
                     if (PuertsDLL.GetJsValueType(isolate, value, false) != JsValueType.Function)
                     {
                         return;
                     }
                     var argTypeId = PuertsDLL.GetTypeIdFromValue(isolate, value, false);
                     if (argTypeId == -1)
                     {
                         return;
                     }
                     genericArguments[i - 1] = TypeRegister.GetType(argTypeId);
                 }
                 type = maybeType.MakeGenericType(genericArguments);
                 //UnityEngine.Debug.Log(type);
             }
         }
         if (type == null)
         {
             return;
         }
         int typeId = TypeRegister.GetTypeId(isolate, type);
         PuertsDLL.ReturnClass(isolate, info, typeId);
     }
     catch (Exception e)
     {
         PuertsDLL.ThrowException(isolate, "loadClass throw c# exception:" + e.Message + ",stack:" + e.StackTrace);
     }
 }
Example #2
0
        void LoadType(IntPtr isolate, IntPtr info, IntPtr self, int paramLen)
        {
            try
            {
                Type type = GetTypeFromJs(isolate, info, self, paramLen);

                if (type != null)
                {
                    int typeId = TypeRegister.GetTypeId(isolate, type);
                    PuertsDLL.ReturnClass(isolate, info, typeId);
                }
            }
            catch (Exception e)
            {
                PuertsDLL.ThrowException(isolate, "loadClass throw c# exception:" + e.Message + ",stack:" + e.StackTrace);
            }
        }