Example #1
0
        public void DebugGet( LuaObject key, out LuaObject outKey,
			out LuaObject outValue )
        {
            Node node;
            if( DictPart.TryGetValue( key, out node ) ) {
                outKey	 = node.Key;
                outValue = node.Value;
            }
            else {
                outKey 		= new LuaNil();
                outValue	= new LuaNil();
            }
        }
Example #2
0
 private void CallTM( LuaObject f, LuaObject p1, LuaObject p2, StkId p3, bool hasres )
 {
     var func = Top;
     Top.ValueInc = f;	// push function
     Top.ValueInc = p1;	// push 1st argument
     Top.ValueInc = p2;	// push 2nd argument
     if( !hasres ) 		// no result? p3 is 3rd argument
         Top.ValueInc = p3.Value;
     D_Call( func, (hasres ? 1 : 0), CI.IsLua );
     if( hasres )		// if has result, move it ot its place
     {
         var below = Top - 1;
         p3.Value = below.Value;
         Top -= 1;
     }
 }
Example #3
0
        public void Set( LuaObject key, LuaObject val )
        {
            if( val.IsNil ) {
                _Remove( key );
            }
            else {
                _Set( key, val );
            }

            // invalidate no-tag-method cache
            NoTagMethodFlags = 0u;
        }
Example #4
0
 internal string ObjTypeName( LuaObject o )
 {
     return API.TypeName( o.LuaType );
 }
Example #5
0
		public static int AddK( FuncState fs, LuaObject key, LuaObject v )
		{
			int idx;
			if( fs.H.TryGetValue( key, out idx ) )
				return idx;

			idx = fs.Proto.K.Count;
			fs.H.Add( key, idx );
			fs.Proto.K.Add( v );
			// Debug.Log("--------- ADD K ------- " + fs.Proto.K.Count + " line:" + fs.Lexer.LineNumber + " key:" + key);
			return idx;
		}
Example #6
0
 public override string SetUpvalue( int n, LuaObject val )
 {
     if( !(1 <= n && n <= Upvals.Count) )
         return null;
     else
     {
         Upvals[n-1] = val;
         return "";
     }
 }
Example #7
0
        private void _UpdateLengthOnRemove( LuaObject key )
        {
            var n = key as LuaNumber;
            if( n == null )
                return;

            int i = (int)n.Value;
            if( 1 <= i && i <= CachedLength ) {
                CachedLength = i - 1;
                CachedLengthDirty = false;
            }
        }
Example #8
0
        private void _Set( LuaObject key, LuaObject val )
        {
            var vnode = new Node(key, val);
            Node old;
            if( DictPart.TryGetValue( key, out old ) ) {
                if( Head == old ) Head = vnode;
                vnode.Prev = old.Prev;
                vnode.Next = old.Next;
                if( old.Prev != null ) old.Prev.Next = vnode;
                if( old.Next != null ) old.Next.Prev = vnode;
            }
            else {
                vnode.Next = Head;
                if( Head != null ) Head.Prev = vnode;
                Head = vnode;

                _UpdateLengthOnAppend( key );
            }

            DictPart[ key ] = vnode;
        }
Example #9
0
        private LuaNumber V_ToNumber( LuaObject obj )
        {
            var n = obj as LuaNumber;
            if( n != null )
                return n;

            var s = obj as LuaString;
            if( s != null )
            {
                double val;
                if( O_Str2Decimal(s.Value, out val) )
                    return new LuaNumber( val );
            }

            return null;
        }
Example #10
0
        private void V_SetTable( LuaObject t, LuaObject key, StkId val )
        {
            // // Debug.Log( "V_SetTable: " + t );
            // var tbl = t as LuaTable;
            // if( tbl == null )
            // {
            // 	throw new Exception( "t is not indexable" );
            // }
            // tbl.Set( key, val.Value );

            for( int loop=0; loop<MAXTAGLOOP; ++loop )
            {
                LuaObject tmObj;
                var tbl = t as LuaTable;
                if( tbl != null )
                {
                    var oldval = tbl.Get( key );
                    if( !oldval.IsNil )
                    {
                        tbl.Set( key, val.Value );
                        return;
                    }

                    // check meta method
                    tmObj = FastTM( tbl.MetaTable, TMS.TM_NEWINDEX );
                    if( tmObj == null )
                    {
                        tbl.Set( key, val.Value );
                        return;
                    }

                    // else will try the tag method
                }
                else
                {
                    tmObj = T_GetTMByObj( t, TMS.TM_NEWINDEX );
                    if( tmObj.IsNil )
                        G_SimpleTypeError( t, "index" );
                }

                if( tmObj.IsFunction )
                {
                    CallTM( tmObj, t, key, val, false );
                    return;
                }

                t = tmObj;
            }
            G_RunError( "loop in settable" );
        }
Example #11
0
 private bool V_RawEqualObj( LuaObject t1, LuaObject t2 )
 {
     return (t1.LuaType == t2.LuaType) && V_EqualObject( t1, t2, true );
 }
Example #12
0
 public abstract string SetUpvalue( int n, LuaObject val );
Example #13
0
 public abstract string GetUpvalue( int n, out LuaObject val );
Example #14
0
 public override string SetUpvalue( int n, LuaObject val )
 {
     if( !(1 <= n && n <= Upvals.Count) )
         return null;
     else
     {
         Upvals[n-1].V.Value = val;
         string name = Proto.Upvalues[n-1].Name;
         return (name == null) ? "" : name;
     }
 }
Example #15
0
 public override string GetUpvalue( int n, out LuaObject val )
 {
     if( !(1 <= n && n <= Upvals.Count) )
     {
         val = null;
         return null;
     }
     else
     {
         val = Upvals[n-1].V.Value;
         string name = Proto.Upvalues[n-1].Name;
         return (name == null) ? "" : name;
     }
 }
Example #16
0
 public void SetInt( int key, LuaObject val )
 {
     Set( new LuaNumber(key), val );
 }
Example #17
0
        private void _Remove( LuaObject key )
        {
            Node old;
            if( DictPart.TryGetValue( key, out old ) ) {
                if( Head == old ) Head = old.Next;
                if( old.Prev != null ) old.Prev.Next = old.Next;
                if( old.Next != null ) old.Next.Prev = old.Prev;
                DictPart.Remove( key );

                _UpdateLengthOnRemove(key);
            }
        }
Example #18
0
 private bool V_EqualObject( LuaObject t1, LuaObject t2, bool rawEq )
 {
     Utl.Assert( t1.LuaType == t2.LuaType );
     LuaObject tm = null;
     switch( t1.LuaType )
     {
         case LuaType.LUA_TNIL:
             return true;
         case LuaType.LUA_TNUMBER:
         case LuaType.LUA_TBOOLEAN:
         case LuaType.LUA_TSTRING:
             return t1.Equals( t2 );
         case LuaType.LUA_TUSERDATA:
         {
             LuaUserData ud1 = t1 as LuaUserData;
             LuaUserData ud2 = t2 as LuaUserData;
             if( ud1.Value == ud2.Value )
                 return true;
             if( rawEq )
                 return false;
             tm = GetEqualTM( ud1.MetaTable, ud2.MetaTable, TMS.TM_EQ );
             break;
         }
         case LuaType.LUA_TTABLE:
         {
             LuaTable tbl1 = t1 as LuaTable;
             LuaTable tbl2 = t2 as LuaTable;
             if( System.Object.ReferenceEquals( tbl1, tbl2 ) )
                 return true;
             if( rawEq )
                 return false;
             tm = GetEqualTM( tbl1.MetaTable, tbl2.MetaTable, TMS.TM_EQ );
             break;
         }
         default:
             return System.Object.ReferenceEquals( t1, t2 );
     }
     if( tm == null ) // no TM?
         return false;
     CallTM( tm, t1, t2, Top, true ); // call TM
     return !Top.Value.IsFalse;
 }
Example #19
0
        private void _UpdateLengthOnAppend( LuaObject key )
        {
            var n = key as LuaNumber;
            if( n == null )
                return;

            int i = (int)n.Value;
            if( i == CachedLength + 1 ) {
                CachedLength = i;
                CachedLengthDirty = true;
            }
        }
Example #20
0
 private bool EqualObj( LuaObject t1, LuaObject t2, bool rawEq )
 {
     return (t1.LuaType == t2.LuaType) && V_EqualObject( t1, t2, rawEq );
 }
Example #21
0
 public Node( LuaObject key, LuaObject value )
 {
     Key = key; Value = value;
 }
Example #22
0
        private void V_GetTable( LuaObject t, LuaObject key, StkId val )
        {
            for( int loop=0; loop<MAXTAGLOOP; ++loop )
            {
                LuaObject tmObj;
                var tbl = t as LuaTable;
                if( tbl != null )
                {
                    var res = tbl.Get( key );
                    if( !res.IsNil )
                    {
                        val.Value = res;
                        return;
                    }

                    tmObj = FastTM( tbl.MetaTable, TMS.TM_INDEX );
                    if( tmObj == null )
                    {
                        val.Value = res;
                        return;
                    }

                    // else will try the tag method
                }
                else
                {
                    tmObj = T_GetTMByObj( t, TMS.TM_INDEX );
                    if( tmObj.IsNil )
                        G_SimpleTypeError( t, "index" );
                }

                if( tmObj.IsFunction )
                {
                    CallTM( tmObj, t, key, val, true );
                    return;
                }

                t = tmObj;
            }
            G_RunError( "loop in gettable" );
        }
Example #23
0
        public LuaObject Get( LuaObject key )
        {
            Node node;
            if( DictPart.TryGetValue( key, out node ) )
            {
                return node.Value;
            }

            return new LuaNil();
        }
Example #24
0
 public override string GetUpvalue( int n, out LuaObject val )
 {
     if( !(1 <= n && n <= Upvals.Count) )
     {
         val = null;
         return null;
     }
     else
     {
         val = Upvals[n-1];
         return "";
     }
 }