/*public bool GetNextConvertible<T>(out object obj) * { * if (size == 0) * { * obj = null; * return false; * } * * var mValue = values[position++]; * size--; * if (mValue.type == MValueConst.Type.LIST || mValue.type == MValueConst.Type.DICT) * { * MValueAdapters.FromMValue(ref mValue, typeof(T), out obj); * return true; * } * * * obj = null; * return false; * }*/ /*public bool GetNext(out MValue.Function value) * { * if (size == 0) * { * value = default; * return false; * } * * var mValue = values[position++]; * size--; * if (mValue.type != MValueConst.Type.FUNCTION) * { * value = default; * return false; * } * * value = mValue.GetFunction(); * return true; * }*/ public bool GetNext(out MValueConst[] valuesList) { if (size == 0) { valuesList = default; return(false); } var mValue = values[position++]; size--; if (mValue.type != MValueConst.Type.List) { valuesList = default; return(false); } var listSize = AltNative.MValueNative.MValueConst_GetListSize(mValue.nativePointer); var valueArrayRef = new IntPtr[listSize]; valuesList = new MValueConst[listSize]; AltNative.MValueNative.MValueConst_GetList(mValue.nativePointer, valueArrayRef); for (ulong i = 0; i < listSize; i++) { valuesList[i] = new MValueConst(valueArrayRef[i]); } return(true); }
public Dictionary <string, MValueConst> GetDictionary() { var size = AltNative.MValueNative.MValueConst_GetDictSize(nativePointer); if (size == 0) { return(new Dictionary <string, MValueConst>()); } var keyPointers = new IntPtr[size]; var mValuePointers = new IntPtr[size]; AltNative.MValueNative.MValueConst_GetDict(nativePointer, keyPointers, mValuePointers); var dictionary = new Dictionary <string, MValueConst>(); for (ulong i = 0; i < size; i++) { var keyPointer = keyPointers[i]; var mValue = new MValueConst(mValuePointers[i]); dictionary[Marshal.PtrToStringUTF8(keyPointer)] = mValue; AltNative.FreeCharArray(keyPointer); mValue.Dispose(); } return(dictionary); }
public Dictionary <string, MValueConst> GetDictionary() { unsafe { var size = core.Library.Shared.MValueConst_GetDictSize(nativePointer); if (size == 0) { return(new Dictionary <string, MValueConst>()); } var keyPointers = new IntPtr[size]; var mValuePointers = new IntPtr[size]; core.Library.Shared.MValueConst_GetDict(nativePointer, keyPointers, mValuePointers); var dictionary = new Dictionary <string, MValueConst>(); for (ulong i = 0; i < size; i++) { var keyPointer = keyPointers[i]; var mValue = new MValueConst(core, mValuePointers[i]); dictionary[Marshal.PtrToStringUTF8(keyPointer)] = mValue; core.Library.Shared.FreeCharArray(keyPointer); } return(dictionary); } }
public void Peek(out MValueConst mValue) { if (size == 0) { mValue = MValueConst.Nil; return; } mValue = values[position]; }
/// <summary> /// Consumes and returns next MValue in the array /// </summary> /// <returns></returns> public void GetNext(out MValueConst mValue) { if (size == 0) { mValue = MValueConst.Nil; return; } size--; mValue = values[position++]; }
public static MValueConst[] CreateFrom(IntPtr[] pointers) { int length = pointers.Length; var mValues = new MValueConst[length]; for (var i = 0; i < length; i++) { mValues[i] = new MValueConst(pointers[i]); } return(mValues); }
public void ToMValue(out MValueConst mValue) { var size = (ulong)Values.Count; var mValues = new MValueConst[size]; core.CreateMValues(mValues, Values.ToArray()); core.CreateMValueList(out mValue, mValues, size); for (ulong i = 0; i < size; i++) { mValues[i].Dispose(); } }
public static bool ToMValue(object obj, Type type, out MValueConst mValue) { if (Adapters.TryGetValue(type, out var adapter)) { var writer = new MValueWriter2(); adapter.ToMValue(obj, writer); writer.ToMValue(out mValue); return(true); } mValue = default; return(false); }
public void ToMValue(out MValueConst mValue) { var size = (ulong)Values.Count; var mValues = new MValueConst[size]; Alt.Server.CreateMValues(mValues, Values.ToArray()); var keys = Names.ToArray(); Alt.Server.CreateMValueDict(out mValue, keys, mValues, size); for (ulong i = 0; i < size; i++) { mValues[i].Dispose(); } }
public void CallFunction(MValueConst[] args, out MValueConst result) { var length = (ulong)args.Length; var argsPointers = new IntPtr[length]; for (ulong i = 0; i < length; i++) { argsPointers[i] = args[i].nativePointer; } result = new MValueConst( AltNative.MValueNative.MValueConst_CallFunction(Alt.Server.NativePointer, nativePointer, argsPointers, length)); }
//TODO: function support public bool ToMValue(out MValueConst mValue) { if (root != null) { root.ToMValue(out mValue); return(true); } else { mValue = MValueConst.Nil; } return(false); }
public void CallFunction(MValueConst[] args, out MValueConst result) { unsafe { var length = (ulong)args.Length; var argsPointers = new IntPtr[length]; for (ulong i = 0; i < length; i++) { argsPointers[i] = args[i].nativePointer; } result = new MValueConst(core, core.Library.Shared.MValueConst_CallFunction(core.NativePointer, nativePointer, argsPointers, length)); } }
public void GetNext(out MValueConst mValue) { mValueArrayBuffer.GetNext(out mValue); }
public void Peek(out MValueConst mValue) { mValue = this.mValue; }
public void GetNext(out MValueConst mValue) { mValue = this.mValue; }
public void Peek(out MValueConst mValueConst) { mValueArrayBuffer.Peek(out mValueConst); }
public static bool ToMValue(object obj, Type type, out MValueConst mValue) { Alt.LogWarning("MValueAdapters.ToMValue is deprecated, use Alt.ToMValue instead"); return(Alt.Core.ToMValue(obj, type, out mValue)); }
public object ToObject() { switch (type) { case Type.None: return(None); case Type.Nil: return(null); case Type.Bool: return(GetBool()); case Type.Int: return(GetInt()); case Type.Uint: return(GetUint()); case Type.Double: return(GetDouble()); case Type.String: return(GetString()); case Type.List: var listSize = AltNative.MValueNative.MValueConst_GetListSize(nativePointer); if (listSize == 0) { return new MValueConst[] { } } ; var mValueListPointers = new IntPtr[listSize]; AltNative.MValueNative.MValueConst_GetList(nativePointer, mValueListPointers); var arrayValues = new object[listSize]; for (ulong i = 0; i < listSize; i++) { var mValue = new MValueConst(mValueListPointers[i]); arrayValues[i] = mValue.ToObject(); mValue.Dispose(); } return(arrayValues); case Type.Dict: var size = AltNative.MValueNative.MValueConst_GetDictSize(nativePointer); if (size == 0) { return(new Dictionary <string, MValueConst>()); } var keyPointers = new IntPtr[size]; var mValuePointers = new IntPtr[size]; if (!AltNative.MValueNative.MValueConst_GetDict(nativePointer, keyPointers, mValuePointers)) { return(null); } var dictionary = new Dictionary <string, object>(); for (ulong i = 0; i < size; i++) { var keyPointer = keyPointers[i]; var mValue = new MValueConst(mValuePointers[i]); dictionary[Marshal.PtrToStringUTF8(keyPointer)] = mValue.ToObject(); AltNative.FreeCharArray(keyPointer); mValue.Dispose(); } return(dictionary); case Type.Entity: var entityType = BaseObjectType.Undefined; var entityPointer = GetEntityPointer(ref entityType); if (entityPointer == IntPtr.Zero) { return(null); } if (Alt.Module.BaseBaseObjectPool.Get(entityPointer, entityType, out var entity)) { return(entity); } return(null); case Type.Function: return(null); case Type.Vector3: var position = Position.Zero; GetVector3(ref position); return(position); case Type.Rgba: var rgba = Rgba.Zero; GetRgba(ref rgba); return(rgba); case Type.ByteArray: return(GetByteArray()); default: return(null); } }