public static bool Equals(Value a, Value b) { if (a.RefVal == b.RefVal) { return(a.RefVal != NumTypeTag || a.NumVal == b.NumVal); } var asStrA = a.RefVal as byte[]; if (asStrA != null) { return(LString.InternalEquals(asStrA, b.RefVal as byte[])); } return(false); }
public int IndexOf(LString str, int index, int count) { if (str.IsNil) { throw new ArgumentNullException("str"); } if (index < 0 || count < 0 || index > Length - count) { throw new ArgumentOutOfRangeException("index"); } var data = InternalData; var strData = str.InternalData; if (strData.Length == BufferDataOffset) { //the empty string is always found at the beginning of the search return(index); } count -= strData.Length - BufferDataOffset; for (int i = index + BufferDataOffset; count-- >= 0; i++) { for (int ii = i, j = BufferDataOffset; j < strData.Length; ii++, j++) { if (data[ii] != strData[j]) { goto notFound; } } return(i - BufferDataOffset); notFound: ; } return(-1); }
public override string ToString() { if (RefVal == null) { return("(nil)"); } if (RefVal == TrueTag) { return("true"); } if (RefVal == FalseTag) { return("false"); } if (RefVal == NumTypeTag) { return(NumVal.ToString()); } var asStr = RefVal as byte[]; if (asStr != null) { return(LString.InternalFromData(asStr).ToString()); } var val = RefVal; var asWrapper = val as UserDataWrapper; if (asWrapper != null) { val = asWrapper.Value; } return(val.ToString()); }
public bool Equals(Value value) { if (Val == value.RefVal) { return(true); } if (value.RefVal == Value.NumTypeTag) { var asNum = Val as NumBox; return(asNum != null && asNum.Value == value.NumVal); } var asStr = Val as byte[]; if (asStr != null) { return(LString.InternalEquals(asStr, value.RefVal as byte[])); } return(false); }
/// <summary> /// Finds the key's location in the table (returns 0 if not found). /// Note that the value at that key may be nil. /// </summary> internal int FindValue(LString key) { if (key.InternalData == null) { throw new ArgumentNullException("key"); } int i = GetMainPosition(key); while (i != -1) { var node = nodes[i]; if (node.Key.Equals(key)) { return(-(i + 1)); } i = node.Next; } return(0); }
/// <summary> /// Gets or sets a value in the table. /// This is a raw operation, it does /// not invoke metatable methods. /// </summary> public Value this[LString key] { get { Value ret; int loc = FindValue(key); ReadValue(loc, out ret); return(ret); } set { int loc = FindValue(key); if (loc == 0) { loc = InsertNewKey(new CompactValue(key)); } WriteValue(loc, ref value); } }
public override int GetHashCode() { if (Val == null || Val == Value.FalseTag) { return(0); } if (Val == Value.TrueTag) { return(1); } var asNum = Val as NumBox; if (asNum != null) { return(Value.GetHashCode(asNum.Value)); } var asStr = Val as byte[]; if (asStr != null) { return(LString.InternalGetHashCode(asStr)); } var val = Val; var asWrapper = val as Value.UserDataWrapper; if (asWrapper != null) { val = asWrapper.Value; } return(Value.GetHashCode(val)); }
public static int CheckOpt( Value value, LString defaultArg, LString[] opts ) { if( opts == null ) throw new ArgumentNullException( "opts" ); if( value.IsNil ) { if( defaultArg.IsNil ) throw new ArgumentNullException( "A required argument was nil." ); value = defaultArg; } if( value.ValueType != LValueType.String ) throw new ArgumentException( "A string argument was expected." ); for( int i = 0; i < opts.Length; i++ ) { if( value == opts[i] ) return i; } throw new ArgumentException( "Invalid option." ); }
public static bool Equals(CompactValue a, CompactValue b) { if (a.Val == b.Val) { return(true); } var asNumA = a.Val as NumBox; if (asNumA != null) { var asNumB = b.Val as NumBox; return(asNumB != null && asNumA.Value == asNumB.Value); } var asStrA = a.Val as byte[]; if (asStrA != null) { return(LString.InternalEquals(asStrA, b.Val as byte[])); } return(false); }
public LoadState(Stream byteCode, LString name) { this.byteCode = byteCode; this.Name = name; }
internal static LString InternalFinishBuffer( byte[] buffer ) { Debug.Assert( buffer != null ); var ret = new LString { InternalData = buffer }; ret.UpdateHashCode(); return ret; }
public int IndexOf( LString str ) { return IndexOf( str, 0, Length ); }
public bool Equals(LString str) { var asStr = RefVal as byte[]; return(LString.InternalEquals(asStr, str.InternalData)); }
public void Append( LString str ) { if( str.Length != 0 ) Append( str.InternalData, LString.BufferDataOffset, str.Length ); }
private Value GetMetamethod( ref Value val, LString tmName ) { var mt = GetMetatable( ref val ); return mt != null ? mt[tmName] : Value.Nil; }
public static int CheckOpt( Value value, LString[] opts ) { return CheckOpt( value, (int?)null, opts ); }
public CompactValue(LString value) { Val = value.InternalData; }
public Value(LString value) { RefVal = value.InternalData; NumVal = 0; }
public LoadState( Stream byteCode, LString name ) { this.byteCode = byteCode; this.Name = name; }
public bool ContainsKey(LString key) { return(!IsLocNilOrEmpty(FindValue(key))); }
public int IndexOf(LString str) { return(IndexOf(str, 0, Length)); }
private int GetMainPosition(LString key) { int hash = key.GetHashCode(); return((hash & 0x7FFFFFFF) % nodes.Length); }
public bool Equals(LString value) { Debug.Assert(value.InternalData != null); return(LString.InternalEquals(value.InternalData, Val as byte[])); }
private bool ValToStr( ref Value val ) { if( val.RefVal is byte[] ) return true; if( val.RefVal != Value.NumTypeTag ) return false; int len = Helpers.NumToStr( fmtBuf, 0, val.NumVal, 14 ); val = new LString( fmtBuf, 0, len ); return true; }
public int IndexOf( LString str, int index ) { if( index < 0 ) throw new ArgumentOutOfRangeException( "index" ); return IndexOf( str, index, Length - index ); }
/// <summary> /// Compares this string to another for equality. /// </summary> public bool Equals( LString other ) { return InternalEquals( InternalData, other.InternalData ); }
public void Set(LString value) { RefVal = value.InternalData; }
/// <summary> /// Compares this string to another for equality. /// </summary> public bool Equals(LString other) { return(InternalEquals(InternalData, other.InternalData)); }
public int IndexOf( LString str, int index, int count ) { if( str.IsNil ) throw new ArgumentNullException( "str" ); if( index < 0 || count < 0 || index > Length - count ) throw new ArgumentOutOfRangeException( "index" ); var data = InternalData; var strData = str.InternalData; if( strData.Length == BufferDataOffset ) //the empty string is always found at the beginning of the search return index; count -= strData.Length - BufferDataOffset; for( int i = index + BufferDataOffset; count-- >= 0; i++ ) { for( int ii = i, j = BufferDataOffset; j < strData.Length; ii++, j++ ) { if( data[ii] != strData[j] ) goto notFound; } return i - BufferDataOffset; notFound: ; } return -1; }