Exemplo n.º 1
0
 public static int ImportType(RealStatePtr L)
 {
     try
     {
         ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
         string           className  = LuaAPI.lua_tostring(L, 1);
         Type             type       = translator.FindType(className);
         if (type != null)
         {
             if (translator.GetTypeId(L, type) >= 0)
             {
                 LuaAPI.lua_pushboolean(L, true);
             }
             else
             {
                 return(LuaAPI.luaL_error(L, "can not load type " + type));
             }
         }
         else
         {
             LuaAPI.lua_pushnil(L);
         }
         return(1);
     }
     catch (System.Exception e)
     {
         return(LuaAPI.luaL_error(L, "c# exception in xlua.import_type:" + e));
     }
 }
Exemplo n.º 2
0
        public static int ImportGenericType(RealStatePtr L)
        {
            try
            {
                int top = LuaAPI.lua_gettop(L);
                if (top < 2)
                {
                    return(LuaAPI.luaL_error(L, "import generic type need at lease 2 arguments"));
                }
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                string           className  = LuaAPI.lua_tostring(L, 1);
                if (className.EndsWith("<>"))
                {
                    className = className.Substring(0, className.Length - 2);
                }
                Type genericDef = translator.FindType(className + "`" + (top - 1));
                if (genericDef == null || !genericDef.IsGenericTypeDefinition())
                {
                    LuaAPI.lua_pushnil(L);
                }
                else
                {
                    Type[] typeArguments = new Type[top - 1];
                    for (int i = 2; i <= top; i++)
                    {
                        typeArguments[i - 2] = getType(L, translator, i);
                        if (typeArguments[i - 2] == null)
                        {
                            return(LuaAPI.luaL_error(L, "param need a type"));
                        }
                    }
                    Type genericInc = genericDef.MakeGenericType(typeArguments);
                    translator.GetTypeId(L, genericInc);
                    translator.PushAny(L, genericInc);
                }

                return(1);
            }
            catch (System.Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in xlua.import_type:" + e));
            }
        }
Exemplo n.º 3
0
 public static int XLuaPrivateAccessible(RealStatePtr L)
 {
     try
     {
         ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
         Type             type       = getType(L, translator, 1);;
         if (type == null)
         {
             return(LuaAPI.luaL_error(L, "xlua.private_accessible, can not find c# type"));
         }
         translator.GetTypeId(L, type);//解决从未访问过一个类型,调用xlua.private_accessible会报错的问题
         Utils.MakePrivateAccessible(L, type);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaAPI.luaL_error(L, "c# exception in xlua.private_accessible: " + e));
     }
 }
Exemplo n.º 4
0
 public static int MetaFuncIndex(RealStatePtr L)
 {
     try
     {
         ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
         Type             type       = translator.FastGetCSObj(L, 2) as Type;
         if (type == null)
         {
             return(LuaAPI.luaL_error(L, "#2 param need a System.Type!"));
         }
         //UnityEngine.Debug.Log("============================load type by __index:" + type);
         //translator.TryDelayWrapLoader(L, type);
         translator.GetTypeId(L, type);
         LuaAPI.lua_pushvalue(L, 2);
         LuaAPI.lua_rawget(L, 1);
         return(1);
     }
     catch (System.Exception e)
     {
         return(LuaAPI.luaL_error(L, "c# exception in MetaFuncIndex:" + e));
     }
 }