예제 #1
0
        public static void createTypeMetatable(IntPtr l, LuaCSFunction con, Type self, Type parent)
        {
            checkMethodValid(con);

            // set parent
            if (parent != null && parent != typeof(object) && parent != typeof(ValueType))
            {
                LuaDLL.lua_pushstring(l, "__parent");
                LuaDLL.luaL_getmetatable(l, ObjectCache.getAQName(parent));
                LuaDLL.lua_rawset(l, -3);

                LuaDLL.lua_pushstring(l, "__parent");
                LuaDLL.luaL_getmetatable(l, parent.FullName);
                LuaDLL.lua_rawset(l, -4);
            }
            else
            {
                LuaDLL.lua_pushstring(l, "__parent");
                LuaDLL.luaL_getmetatable(l, "__luabaseobject");
                LuaDLL.lua_rawset(l, -3);
            }

            completeInstanceMeta(l, self);
            completeTypeMeta(l, con, self);

            LuaDLL.lua_pop(l, 1);             // pop type Table
        }
예제 #2
0
        public static void createTypeMetatable(IntPtr l, LuaCSFunction con, Type self, Type parent)
        {
            // set parent
            if (parent != null && parent != typeof(object))
            {
                LuaDLL.lua_pushstring(l, "__parent");
                LuaDLL.luaL_getmetatable(l, parent.AssemblyQualifiedName);
                LuaDLL.lua_rawset(l, -3);

                LuaDLL.lua_pushstring(l, "__parent");
                LuaDLL.luaL_getmetatable(l, parent.FullName);
                LuaDLL.lua_rawset(l, -4);
            }
            else
            {
                LuaDLL.lua_pushstring(l, "__parent");
                LuaDLL.luaL_getmetatable(l, "__luabaseobject");
                LuaDLL.lua_rawset(l, -3);
            }

            completeInstanceMeta(l, self);
            completeTypeMeta(l, con, self);

            LuaDLL.lua_pop(l, 1);             // pop type Table
        }
예제 #3
0
        internal void push(IntPtr l, object o, bool checkReflect)
        {
            int index = allocID(l, o);

            if (index < 0)
            {
                return;
            }

            bool gco = isGcObject(o);

#if SLUA_CHECK_REFLECTION
            int isReflect = LuaDLL.luaS_pushobject(l, index, getAQName(o), gco, udCacheRef);
            if (isReflect != 0 && checkReflect && !(o is LuaClassObject))
            {
                Logger.LogWarning(string.Format("{0} not exported, using reflection instead", o.ToString()));
            }
#elif SLUA_TRY_PUSHBASE
            Type t = o.GetType();
            while (t != typeof(Object))
            {
                LuaDLL.luaL_getmetatable(l, getAQName(t));
                if (!LuaDLL.lua_isnil(l, -1))
                {
                    LuaDLL.lua_pop(l, 1);
                    LuaDLL.luaS_pushobject(l, index, getAQName(t), gco, udCacheRef);
                    break;
                }
                LuaDLL.lua_pop(l, 1);
                t = t.BaseType;
            }
#else
            LuaDLL.luaS_pushobject(l, index, getAQName(o), gco, udCacheRef);
#endif
        }
예제 #4
0
        internal static string getAQName(Type t, IntPtr l)
        {
            string name;

            if (aqnameMap.TryGetValue(t, out name))
            {
                return(name);
            }
            name = t.AssemblyQualifiedName;
#if ENABLE_USE_INHERIT_INTERFACE
            if (l != IntPtr.Zero)
            {
                Type rt = t;
                while (null != rt)
                {
                    string tn = rt.AssemblyQualifiedName;
                    LuaDLL.luaL_getmetatable(l, tn);
                    bool r = LuaDLL.lua_isnil(l, -1);
                    LuaDLL.lua_pop(l, 1);
                    if (r)
                    {
                        Type[] ts   = rt.GetInterfaces();
                        var    temp = rt;
                        rt = null;
                        if (null != ts && ts.Length > 0)
                        {
                            foreach (Type tt in ts)
                            {
                                if (null == tt.Namespace || !tt.Namespace.StartsWith("System") && !tt.Namespace.StartsWith("UnityEngine"))
                                {
                                    rt = tt;
                                    break;
                                }
                            }
                        }
                        else if (null != temp.BaseType && (null == temp.BaseType.Namespace || !temp.BaseType.Namespace.StartsWith("System")))
                        {
                            rt = temp.BaseType;
                        }
                    }
                    else
                    {
                        name = tn;
                        break;
                    }
                }
            }
#endif
            aqnameMap[t] = name;
            return(name);
        }
예제 #5
0
파일: Helper.cs 프로젝트: moto2002/Luna
        static public int As(IntPtr l)
        {
            if (!isTypeTable(l, 2))
            {
                LuaDLL.luaL_error(l, "No matched type of param 2");
                return(0);
            }
            string meta = LuaDLL.lua_tostring(l, -1);

            LuaDLL.luaL_getmetatable(l, meta);
            LuaDLL.lua_setmetatable(l, 1);
            LuaDLL.lua_pushvalue(l, 1);
            return(1);
        }
예제 #6
0
 static public int As(IntPtr l)
 {
     try {
         if (!isTypeTable(l, 2))
         {
             return(error(l, "No matched type of param 2"));
         }
         string meta = LuaDLL.lua_tostring(l, -1);
         LuaDLL.luaL_getmetatable(l, meta);
         LuaDLL.lua_setmetatable(l, 1);
         pushValue(l, true);
         LuaDLL.lua_pushvalue(l, 1);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #7
0
        public static void createTypeMetatable(IntPtr l, LuaCSFunction con, Type self, Type parent)
        {
            checkMethodValid(con);

            // set parent
            bool parentSet = false;

            LuaDLL.lua_pushstring(l, "__parent");
            while (parent != null && parent != typeof(object) && parent != typeof(ValueType))
            {
                LuaDLL.luaL_getmetatable(l, ObjectCache.getAQName(parent));
                // if parentType is not exported to lua
                if (LuaDLL.lua_isnil(l, -1))
                {
                    LuaDLL.lua_pop(l, 1);
                    parent = parent.BaseType;
                }
                else
                {
                    LuaDLL.lua_rawset(l, -3);

                    LuaDLL.lua_pushstring(l, "__parent");
                    LuaDLL.luaL_getmetatable(l, parent.FullName);
                    LuaDLL.lua_rawset(l, -4);

                    parentSet = true;
                    break;
                }
            }

            if (!parentSet)
            {
                LuaDLL.luaL_getmetatable(l, "__luabaseobject");
                LuaDLL.lua_rawset(l, -3);
            }

            completeInstanceMeta(l, self);
            completeTypeMeta(l, con, self);

            LuaDLL.lua_pop(l, 1);             // pop type Table
        }
예제 #8
0
        internal void push(IntPtr l, object o)
        {
            if (o == null)
            {
                LuaDLL.lua_pushnil(l);
                return;
            }
            int index = -1;

            bool gco   = isGcObject(o);
            bool found = gco && objMap.TryGetValue(o, out index);

            if (found)
            {
                if (getUDCache(l, index))
                {
                    return;
                }
            }


            index = add(o);
            LuaDLL.luaS_newuserdata(l, index);
            if (gco)
            {
                cacheUD(l, index);
            }


            LuaDLL.luaL_getmetatable(l, getAQName(o));
            if (LuaDLL.lua_isnil(l, -1))
            {
                LuaDLL.lua_pop(l, 1);
                LuaDLL.luaL_getmetatable(l, "LuaVarObject");
            }

            LuaDLL.lua_setmetatable(l, -2);
        }