예제 #1
0
    public static Tuple <StkId, StkId> CallFunction(this LuaState lua, StkId func)
    {
        if (func.V.TtIsFunction())
        {
            var clone = StkId.Clone(func);
            lua.PushStkId(clone);
            if (!lua.D_PreCall(clone, 2))
            {
                lua.V_Execute();
            }

            var value = lua.Last();
            if (value.V.TtIsNil())
            {
                // Debug.Log("Iterator elements are over");
                return(null);
            }
            lua.Pop(1);
            var key = lua.Last();
            lua.Pop(1);

            return(new Tuple <StkId, StkId>(key, value));
        }
        Debug.LogWarning("Iterator must be a function");
        return(null);
    }