Exemplo n.º 1
0
        private void InnerSetTable(LuaValue t, LuaValue k, LuaValue v, bool raw)
        {
            if (t.IsTable())
            {
                var table = t.GetTableValue();
                if (raw || !table.Get(k).IsNil() || !table.HasMetaField("__newindex"))
                {
                    table.Put(k, v);
                    return;
                }
            }

            if (!raw)
            {
                var mf = LuaValue.GetMetaField(t, "__newindex", this);
                if (mf != null)
                {
                    if (mf.IsTable())
                    {
                        InnerSetTable(mf, k, v, false);
                    }
                    else if (mf.IsFunction())
                    {
                        _stack.Push(mf);
                        _stack.Push(t);
                        _stack.Push(k);
                        _stack.Push(v);
                        Call(3, 0);
                        return;
                    }
                }
            }

            Debug.Panic("not a table!");
        }
Exemplo n.º 2
0
        public void Call(int nArgs, int nResults)
        {
            var val = _stack[-(nArgs + 1)];
            var ok  = val.IsFunction();
            var c   = val.GetClosureValue();

            if (!ok)
            {
                var mf = LuaValue.GetMetaField(val, "__call", this);
                if (mf != null)
                {
                    ok = mf.IsFunction();
                    c  = mf.GetClosureValue();

                    if (ok)
                    {
                        _stack.Push(val);
                        Insert(-(nArgs + 2));
                        nArgs += 1;
                    }
                }
            }

            if (ok)
            {
                if (c.Proto != null)
                {
                    CallLuaClosure(nArgs, nResults, c);
                }
                else
                {
                    CallCSClosure(nArgs, nResults, c);
                }
            }
            else
            {
                Debug.Panic("not function!");
            }
        }
Exemplo n.º 3
0
        private ELuaType InnerGetTable(LuaValue t, LuaValue k, bool raw)
        {
            if (t.IsTable())
            {
                var table = t.GetTableValue();
                var v     = table.Get(k);

                if (raw || !v.IsNil() || !table.HasMetaField("__index"))
                {
                    _stack.Push(v);
                    return(v.Type);
                }
            }

            if (!raw)
            {
                var mf = LuaValue.GetMetaField(t, "__index", this);
                if (mf != null)
                {
                    if (mf.IsTable())
                    {
                        return(InnerGetTable(mf, k, false));
                    }

                    if (mf.IsFunction())
                    {
                        _stack.Push(mf);
                        _stack.Push(t);
                        _stack.Push(k);
                        Call(2, 1);
                        var v = _stack.Get(-1);
                        return(v.Type);
                    }
                }
            }

            Debug.Panic("index error!");
            return(ELuaType.None);
        }