コード例 #1
0
        private static void SetNullObject(int nullObjectRef, List <string> list)
        {
            IntPtr L = LuaProfiler.mainL;

            if (L == IntPtr.Zero)
            {
                return;
            }
            list.Clear();
            int oldTop = LuaDLL.lua_gettop(L);

            LuaDLL.lua_getref(L, nullObjectRef);
            if (LuaDLL.lua_type(L, -1) != LuaTypes.LUA_TTABLE)
            {
                LuaDLL.lua_pop(L, 1);
                return;
            }
            int t = oldTop + 1;

            LuaDLL.lua_pushnil(L);  /* 第一个 key */
            while (LuaDLL.lua_next(L, t) != 0)
            {
                /* 用一下 'key' (在索引 -2 处) 和 'value' (在索引 -1 处) */
                list.Add(LuaHook.GetRefString(L, -2));
                /* 移除 'value' ;保留 'key' 做下一次迭代 */
                LuaDLL.lua_pop(L, 1);
            }
            LuaDLL.lua_settop(L, oldTop);
        }
コード例 #2
0
        private static void SetTable(int refIndex, Dictionary <LuaTypes, HashSet <string> > dict, Dictionary <string, List <string> > detailDict)
        {
            IntPtr L = LuaProfiler.mainL;

            if (L == IntPtr.Zero)
            {
                return;
            }
            dict.Clear();
            int oldTop = LuaDLL.lua_gettop(L);

            LuaDLL.lua_getref(L, refIndex);
            if (LuaDLL.lua_type(L, -1) != LuaTypes.LUA_TTABLE)
            {
                LuaDLL.lua_pop(L, 1);
                return;
            }
            int t = oldTop + 1;

            LuaDLL.lua_pushnil(L);  /* 第一个 key */
            while (LuaDLL.lua_next(L, t) != 0)
            {
                /* 用一下 'key' (在索引 -2 处) 和 'value' (在索引 -1 处) */
                int key_t = LuaDLL.lua_gettop(L);
                LuaDLL.lua_pushnil(L);  /* 第一个 key */
                string        firstKey   = null;
                List <string> detailList = new List <string>();
                while (LuaDLL.lua_next(L, key_t) != 0)
                {
                    string key = LuaHook.GetRefString(L, -1);
                    if (string.IsNullOrEmpty(firstKey))
                    {
                        firstKey = key;
                    }
                    detailList.Add(key);
                    LuaDLL.lua_pop(L, 1);
                }
                LuaDLL.lua_settop(L, key_t);
                if (!string.IsNullOrEmpty(firstKey))
                {
                    HashSet <string> list;
                    LuaTypes         luaType = (LuaTypes)LuaDLL.lua_type(L, -2);
                    if (!dict.TryGetValue(luaType, out list))
                    {
                        list = new HashSet <string>();
                        dict.Add(luaType, list);
                    }
                    if (!list.Contains(firstKey))
                    {
                        list.Add(firstKey);
                    }
                    detailDict[firstKey] = detailList;
                }

                /* 移除 'value' ;保留 'key' 做下一次迭代 */
                LuaDLL.lua_pop(L, 1);
            }
            LuaDLL.lua_settop(L, oldTop);
        }