Exemple #1
0
        public static int ClrFuncPanic(IntPtr l)
        {
            var    top     = l.gettop();
            var    error   = l.GetLua(-1);
            string message = error == null ? "" : error.ToString();

            message = "Lua error at " + top + ": " + message;
            LuaHub.LogError(l, message);
            throw new LuaAtPanicException(message);
        }
        public static int ClrFuncNext(IntPtr l)
        {
            var list = l.GetLua <IList>(1);

            if (list != null)
            {
                var    key    = l.GetLua(2);
                object oindex = null;
                if (key != null)
                {
                    oindex = LuaHub.ConvertTypeRaw(key, typeof(int));
                }
                if (key == null || oindex != null)
                {
                    int index = 0;
                    if (oindex != null)
                    {
                        index = (int)oindex + 1;
                    }
                    if (index >= 0 && index < list.Count)
                    {
                        l.pushnumber(index);
                        l.PushLua(list[index]);
                        return(2);
                    }
                }
                return(0);
            }
            var detor = l.GetLua <IDictionaryEnumerator>(1);

            if (detor != null)
            {
                var key = l.GetLua(2);
                if (key == null)
                {
                    detor.Reset();
                }
                if (detor.MoveNext())
                {
                    l.PushLua(detor.Entry.Key);
                    l.PushLua(detor.Entry.Value);
                    return(2);
                }
                return(0);
            }
            return(0);
        }