public static int ClrFuncExtend(IntPtr l)
 {
     l.pushvalue(1);
     LuaExtend.MakeLuaExtend(l, -1);
     return(1);
 }
        public static int ClrMetaIndex(IntPtr l)
        {
            // ... = tab key
            var oldtop = l.gettop();

            switch (0)
            {
            default:
                if (oldtop < 2)
                {
                    break;
                }
                if (!l.istable(1))
                {
                    break;
                }
                string key = l.GetString(2);
                if (key == null)
                {
                    key = "";
                }
                l.PushString("___path"); // ... "___path"
                l.rawget(1);             // ... path
                string path = l.GetString(-1);
                if (path == null)
                {
                    path = "";
                }
                string full = path + key;
                l.pop(1);     // ...

                Type        ftype  = null;
                List <Type> gtypes = new List <Type>(2);
#if NETFX_CORE
                foreach (var asm in _SearchAssemblies)
#else
                foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
#endif
                {
                    if (ftype == null)
                    {
                        try
                        {
#if NETFX_CORE
                            ftype = asm.GetType(full);
#else
                            ftype = asm.GetType(full, false);
#endif
                        }
                        catch { }
                    }
                    for (int i = 0; i < _MaxGenericParamCount; ++i)
                    {
                        try
                        {
#if NETFX_CORE
                            var gtype = asm.GetType(full + "`" + i.ToString());
#else
                            var gtype = asm.GetType(full + "`" + i.ToString(), false);
#endif
                            if (gtype != null)
                            {
                                gtypes.Add(gtype);
                            }
                        }
                        catch { }
                    }
                }

                if (ftype == null && gtypes.Count <= 0)
                {
                    l.newtable();                  // ... ntab
                    l.pushvalue(2);                // ... ntab key
                    l.pushvalue(-2);               // ... ntab key ntab
                    l.settable(1);                 // ... ntab
                    l.PushString(full + ".");      // ... ntab npath
                    l.SetField(-2, "___path");     // ... ntab
                    l.PushClrHierarchyMetatable(); // ... ntab meta
                    l.setmetatable(-2);            // ... ntab
                }
                else
                {
                    var typehub = LuaTypeHub.GetTypeHub(ftype);
                    foreach (var gtype in gtypes)
                    {
                        typehub.RegGenericTypeDefinition(gtype);
                    }
                    l.PushLuaType(typehub);     // ... type
                    if (l.IsExtended())
                    {
                        LuaExtend.MakeLuaExtend(l, -1);
                    }
                    l.pushvalue(2);    // ... type key
                    l.pushvalue(-2);   // ... type key type
                    l.settable(1);     // ... type
                }
                break;
            }

            return(l.gettop() - oldtop);
        }