Esempio n. 1
0
        public static void GetField(this IntPtr l, int index, LuaString key)
        {
            var top = l.gettop();

            if (index < 0 && -index <= top)
            {
                index = top + 1 + index;
            }

            key.PushString(l);
            l.gettable(index);
        }
Esempio n. 2
0
        public static void PushString(this IntPtr l, string str)
        {
#if DEBUG_LUA_PERFORMANCE
            PushOrGetStringTimingWatch.Restart();
            try
            {
#endif
            l.pushstring(str);
            return;            // test result shows it is faster to NOT use the cache.

#pragma warning disable CS0162 // 检测到无法访问的代码
            LuaString predefined = LuaString.GetString(str);
            if (predefined != null)
            {
                predefined.PushString(l);
                return;
            }

            var cache = LuaStateAttachmentManager.GetOrCreateAttachmentManager(l).StrCache;
            cache.L = l;

            var info = cache.PutIntoCache(str);
            if (info == null)
            {
                l.pushstring(str); // str
            }
            else
            {
                if (!PushString(l, info.Id))
                {
                    // this should not happen
                    l.pop(3);          // X
                    l.pushstring(str); // str
                }
            }
#pragma warning restore CS0162 // 检测到无法访问的代码
#if DEBUG_LUA_PERFORMANCE
        }

        finally
        {
            PushOrGetStringTimingWatch.Stop();
            long delta = PushOrGetStringTimingWatch.ElapsedTicks;
            var  cnt   = System.Threading.Interlocked.Increment(ref PushOrGetStringCallCount);
            var  time  = System.Threading.Interlocked.Add(ref PushOrGetStringCallTotalTime, delta);
            UnityEngine.Debug.Log(((double)time) / (double)System.Diagnostics.Stopwatch.Frequency * 1000.0 / cnt);
        }
#endif
        }
Esempio n. 3
0
 public static void PushString(this IntPtr l, LuaString str)
 {
     str.PushString(l);
 }