Cleanup and improvements
This commit is contained in:
parent
cb1273b92e
commit
c1ed9b1eb6
|
@ -27,7 +27,7 @@ namespace PorygonSharp
|
||||||
Print(message);
|
Print(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "SetDefaultPrintFunc", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "SetDefaultPrintFunc", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern double InternalSetPrintFunc(IntPtr ptr);
|
private static extern double InternalSetPrintFunc(IntPtr ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -56,13 +56,13 @@ namespace PorygonSharp.DiagnosticHandling
|
||||||
return GetFullDiagnostic(_handle, item.GetHandle());
|
return GetFullDiagnostic(_handle, item.GetHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "GetDiagnosticsCount", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "GetDiagnosticsCount", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern int GetDiagnosticsCount(IntPtr ptr);
|
private static extern int GetDiagnosticsCount(IntPtr ptr);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "GetDiagnosticAt", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "GetDiagnosticAt", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr GetDiagnosticAt(IntPtr ptr, int position);
|
private static extern IntPtr GetDiagnosticAt(IntPtr ptr, int position);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "GetFullDiagnostic", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "GetFullDiagnostic", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern string GetFullDiagnostic(IntPtr diagnosticsHolder, IntPtr diagnostic);
|
private static extern string GetFullDiagnostic(IntPtr diagnosticsHolder, IntPtr diagnostic);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -65,6 +65,8 @@ namespace PorygonSharp.EvalValues
|
||||||
|
|
||||||
public object GetObjectValue()
|
public object GetObjectValue()
|
||||||
{
|
{
|
||||||
|
if (_handle == IntPtr.Zero)
|
||||||
|
return null;
|
||||||
switch (GetTypeClass())
|
switch (GetTypeClass())
|
||||||
{
|
{
|
||||||
case TypeClass.Nil:
|
case TypeClass.Nil:
|
||||||
|
@ -87,22 +89,22 @@ namespace PorygonSharp.EvalValues
|
||||||
return _handle;
|
return _handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "GetEvalValueTypeClass", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "GetEvalValueTypeClass", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern int GetTypeClass(IntPtr ptr);
|
private static extern int GetTypeClass(IntPtr ptr);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "GetEvalValueType", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "GetEvalValueType", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr GetScriptType(IntPtr ptr);
|
private static extern IntPtr GetScriptType(IntPtr ptr);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "EvaluateEvalValueInteger", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "EvaluateEvalValueInteger", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern long EvaluateInteger(IntPtr ptr);
|
private static extern long EvaluateInteger(IntPtr ptr);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "EvaluateEvalValueFloat", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "EvaluateEvalValueFloat", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern double EvaluateFloat(IntPtr ptr);
|
private static extern double EvaluateFloat(IntPtr ptr);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "EvaluateEvalValueBool", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "EvaluateEvalValueBool", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern bool EvaluateBool(IntPtr ptr);
|
private static extern bool EvaluateBool(IntPtr ptr);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "GetEvalValueStringLength",CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "GetEvalValueStringLength",CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern int GetStringLength(IntPtr ptr);
|
private static extern int GetStringLength(IntPtr ptr);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "EvaluateEvalValueString",CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "EvaluateEvalValueString",CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern int EvaluateString(IntPtr ptr, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] byte[] buffer, int capacity);
|
private static extern int EvaluateString(IntPtr ptr, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] byte[] buffer, int capacity);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "EvaluateUserDataObj",CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "EvaluateUserDataObj",CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr EvaluateUserDataObj(IntPtr ptr);
|
private static extern IntPtr EvaluateUserDataObj(IntPtr ptr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,23 +66,23 @@ namespace PorygonSharp.EvalValues
|
||||||
return new EvalValue(ptr);
|
return new EvalValue(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateNilEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateNilEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IntPtr CreateNilEvalValue();
|
internal static extern IntPtr CreateNilEvalValue();
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateIntegerEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateIntegerEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IntPtr CreateIntegerEvalValue(long l);
|
internal static extern IntPtr CreateIntegerEvalValue(long l);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateFloatEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateFloatEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateFloatEvalValue(double d);
|
private static extern IntPtr CreateFloatEvalValue(double d);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateBoolEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateBoolEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateBoolEvalValue(bool b);
|
private static extern IntPtr CreateBoolEvalValue(bool b);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateStringEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateStringEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateStringEvalValue(string s);
|
private static extern IntPtr CreateStringEvalValue(string s);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateUserDataEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateUserDataEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateUserDataEvalValue(uint typeHash, IntPtr obj);
|
private static extern IntPtr CreateUserDataEvalValue(uint typeHash, IntPtr obj);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateFunctionEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateFunctionEvalValue",CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateFunctionEvalValue(IntPtr func, IntPtr parent);
|
private static extern IntPtr CreateFunctionEvalValue(IntPtr func, IntPtr parent);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateCollectionValue", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateCollectionValue", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateCollectionValue(IntPtr type, IntPtr parent, IntPtr getter, IntPtr setter,
|
private static extern IntPtr CreateCollectionValue(IntPtr type, IntPtr parent, IntPtr getter, IntPtr setter,
|
||||||
IntPtr iterator);
|
IntPtr iterator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace PorygonSharp.EvalValues
|
||||||
return CreateCollectionRangeIterator(0, list.Count);
|
return CreateCollectionRangeIterator(0, list.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateCollectionRangeIterator", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateCollectionRangeIterator", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateCollectionRangeIterator(int start, int end);
|
private static extern IntPtr CreateCollectionRangeIterator(int start, int end);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
using PorygonSharp.EvalValues;
|
using PorygonSharp.EvalValues;
|
||||||
|
|
||||||
namespace PorygonSharp
|
namespace PorygonSharp
|
||||||
|
@ -10,7 +11,9 @@ namespace PorygonSharp
|
||||||
private struct EvaluateResultInternal
|
private struct EvaluateResultInternal
|
||||||
{
|
{
|
||||||
public readonly IntPtr Value;
|
public readonly IntPtr Value;
|
||||||
public readonly bool Result;
|
public readonly byte Result;
|
||||||
|
public readonly IntPtr ErrorMessage;
|
||||||
|
public readonly long ErrorSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IntPtr _ptr;
|
private readonly IntPtr _ptr;
|
||||||
|
@ -28,12 +31,15 @@ namespace PorygonSharp
|
||||||
|
|
||||||
public bool IsSuccess()
|
public bool IsSuccess()
|
||||||
{
|
{
|
||||||
return !_internal.Result;
|
return _internal.Result == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetError()
|
public string GetError()
|
||||||
{
|
{
|
||||||
return GetErrorMessage(_ptr);
|
var nameArr = new byte[_internal.ErrorSize];
|
||||||
|
for (var i = 0; i < _internal.ErrorSize; i++)
|
||||||
|
nameArr[i] = Marshal.ReadByte(_internal.ErrorMessage, i);
|
||||||
|
return $"Error length: {_internal.ErrorSize}" + Encoding.UTF8.GetString(nameArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
@ -41,7 +47,7 @@ namespace PorygonSharp
|
||||||
Marshal.FreeHGlobal(_ptr);
|
Marshal.FreeHGlobal(_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "GetResultError", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "GetResultError", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern string GetErrorMessage(IntPtr ptr);
|
private static extern string GetErrorMessage(IntPtr ptr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,23 +127,23 @@ namespace PorygonSharp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateScript", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateScript", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr Create([MarshalAs(UnmanagedType.LPWStr)]string s, IntPtr options);
|
private static extern IntPtr Create([MarshalAs(UnmanagedType.LPWStr)]string s, IntPtr options);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "EvaluateScript", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "EvaluateScript", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr Evaluate(IntPtr script);
|
private static extern IntPtr Evaluate(IntPtr script);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "HasVariable", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "HasVariable", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern bool HasVariable(IntPtr script, [MarshalAs(UnmanagedType.LPWStr)]string key);
|
private static extern bool HasVariable(IntPtr script, [MarshalAs(UnmanagedType.LPWStr)]string key);
|
||||||
[DllImport("libPorygonLang", EntryPoint = "GetVariable", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "GetVariable", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr GetVariable(IntPtr script, [MarshalAs(UnmanagedType.LPWStr)]string key);
|
private static extern IntPtr GetVariable(IntPtr script, [MarshalAs(UnmanagedType.LPWStr)]string key);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "HasFunction", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "HasFunction", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern bool HasFunction(IntPtr script, [MarshalAs(UnmanagedType.LPWStr)]string key);
|
private static extern bool HasFunction(IntPtr script, [MarshalAs(UnmanagedType.LPWStr)]string key);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CallFunction", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CallFunction", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CallFunction(IntPtr script, [MarshalAs(UnmanagedType.LPWStr)]string key,
|
private static extern IntPtr CallFunction(IntPtr script, [MarshalAs(UnmanagedType.LPWStr)]string key,
|
||||||
IntPtr[] parameters, int parameterCount);
|
IntPtr[] parameters, int parameterCount);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CloneScript", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CloneScript", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CloneScript(IntPtr script);
|
private static extern IntPtr CloneScript(IntPtr script);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,16 +51,16 @@ namespace PorygonSharp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateOptions", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateOptions", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr Create();
|
private static extern IntPtr Create();
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "SetOptionPrintFunc", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "SetOptionPrintFunc", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern void SetOptionPrintFunc(IntPtr opt, IntPtr func);
|
private static extern void SetOptionPrintFunc(IntPtr opt, IntPtr func);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "SetOptionModuleExistsFunc", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "SetOptionModuleExistsFunc", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern void SetOptionModuleExistsFunc(IntPtr opt, IntPtr func);
|
private static extern void SetOptionModuleExistsFunc(IntPtr opt, IntPtr func);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "SetOptionResolveModuleFunc", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "SetOptionResolveModuleFunc", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern void SetOptionResolveModuleFunc(IntPtr opt, IntPtr func);
|
private static extern void SetOptionResolveModuleFunc(IntPtr opt, IntPtr func);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,19 +115,19 @@ namespace PorygonSharp.ScriptType
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateScriptType", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateScriptType", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateScriptType(TypeClass t);
|
private static extern IntPtr CreateScriptType(TypeClass t);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateNumericScriptType", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateNumericScriptType", CallingConvention = CallingConvention.Cdecl)]
|
||||||
internal static extern IntPtr CreateNumericScriptType(bool isAware, bool isFloat);
|
internal static extern IntPtr CreateNumericScriptType(bool isAware, bool isFloat);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateStringScriptType", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateStringScriptType", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateStringScriptType(bool knownAtBind, uint hash);
|
private static extern IntPtr CreateStringScriptType(bool knownAtBind, uint hash);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateUserDataFunctionScriptType", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateUserDataFunctionScriptType", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateUserDataFunctionScriptType(IntPtr returnType, IntPtr[] parameters, int parameterCount);
|
private static extern IntPtr CreateUserDataFunctionScriptType(IntPtr returnType, IntPtr[] parameters, int parameterCount);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateCollectionType", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateCollectionType", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateCollectionType(IntPtr keyType, IntPtr valueType);
|
private static extern IntPtr CreateCollectionType(IntPtr keyType, IntPtr valueType);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,7 +18,7 @@ namespace PorygonSharp
|
||||||
RegisterStaticVariable(hash, scriptType.Value, value.GetPointer());
|
RegisterStaticVariable(hash, scriptType.Value, value.GetPointer());
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "RegisterStaticVariable", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "RegisterStaticVariable", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern void RegisterStaticVariable(uint hashId, IntPtr scriptType, IntPtr value);
|
private static extern void RegisterStaticVariable(uint hashId, IntPtr scriptType, IntPtr value);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -71,8 +71,16 @@ namespace PorygonSharp.UserData
|
||||||
{
|
{
|
||||||
var eval = new EvalValue(parameters[i]);
|
var eval = new EvalValue(parameters[i]);
|
||||||
var val = eval.GetObjectValue();
|
var val = eval.GetObjectValue();
|
||||||
var convertedType = Convert.ChangeType(val, parameterTypes[i]);
|
var desiredType = parameterTypes[i];
|
||||||
evaluatedParameters[i] = convertedType;
|
if (val is IConvertible)
|
||||||
|
{
|
||||||
|
var convertedType = Convert.ChangeType(val, desiredType);
|
||||||
|
evaluatedParameters[i] = convertedType;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
evaluatedParameters[i] = val;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var parentObj = GCHandle.FromIntPtr(parent).Target;
|
var parentObj = GCHandle.FromIntPtr(parent).Target;
|
||||||
|
|
|
@ -90,7 +90,7 @@ namespace PorygonSharp.UserData
|
||||||
var fieldName = valueName.ScriptHash();
|
var fieldName = valueName.ScriptHash();
|
||||||
var t = ScriptType.ScriptType.CreateNumericScriptType(true, false);
|
var t = ScriptType.ScriptType.CreateNumericScriptType(true, false);
|
||||||
RegisterUserDataField(hash, fieldName,
|
RegisterUserDataField(hash, fieldName,
|
||||||
CreateUserDataField(t, Marshal.GetFunctionPointerForDelegate(getter), IntPtr.Zero));
|
CreateUserDataField(t, fieldData.GetGetterPointer(), IntPtr.Zero));
|
||||||
ReverseLookup[hash].Fields[fieldName] = fieldData;
|
ReverseLookup[hash].Fields[fieldName] = fieldData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,13 +101,17 @@ namespace PorygonSharp.UserData
|
||||||
var scriptType = ScriptType.ScriptType.GetScriptType(field.FieldType);
|
var scriptType = ScriptType.ScriptType.GetScriptType(field.FieldType);
|
||||||
if (!scriptType.HasValue)
|
if (!scriptType.HasValue)
|
||||||
return;
|
return;
|
||||||
|
if (!ReverseLookup.TryGetValue(typeHash, out var userData))
|
||||||
|
return;
|
||||||
|
var fieldName = field.Name.ScriptHash();
|
||||||
|
if (userData.Fields.ContainsKey(fieldName))
|
||||||
|
return;
|
||||||
var fieldData = new UserDataField(field);
|
var fieldData = new UserDataField(field);
|
||||||
var userDataField = CreateUserDataField(scriptType.Value, fieldData.GetGetterPointer(),
|
var userDataField = CreateUserDataField(scriptType.Value, fieldData.GetGetterPointer(),
|
||||||
fieldData.GetSetterPointer());
|
fieldData.GetSetterPointer());
|
||||||
|
|
||||||
var fieldName = field.Name.ScriptHash();
|
|
||||||
RegisterUserDataField(typeHash, fieldName, userDataField);
|
RegisterUserDataField(typeHash, fieldName, userDataField);
|
||||||
ReverseLookup[typeHash].Fields[fieldName] = fieldData;
|
userData.Fields.Add(fieldName, fieldData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RegisterProperty(PropertyInfo property, uint typeHash)
|
private static void RegisterProperty(PropertyInfo property, uint typeHash)
|
||||||
|
@ -115,13 +119,17 @@ namespace PorygonSharp.UserData
|
||||||
var scriptType = ScriptType.ScriptType.GetScriptType(property.PropertyType);
|
var scriptType = ScriptType.ScriptType.GetScriptType(property.PropertyType);
|
||||||
if (!scriptType.HasValue)
|
if (!scriptType.HasValue)
|
||||||
return;
|
return;
|
||||||
|
if (!ReverseLookup.TryGetValue(typeHash, out var userData))
|
||||||
|
return;
|
||||||
|
var fieldName = property.Name.ScriptHash();
|
||||||
|
if (userData.Fields.ContainsKey(fieldName))
|
||||||
|
return;
|
||||||
var fieldData = new UserDataField(property);
|
var fieldData = new UserDataField(property);
|
||||||
var userDataField = CreateUserDataField(scriptType.Value, fieldData.GetGetterPointer(),
|
var userDataField = CreateUserDataField(scriptType.Value, fieldData.GetGetterPointer(),
|
||||||
fieldData.GetSetterPointer());
|
fieldData.GetSetterPointer());
|
||||||
|
|
||||||
var fieldName = property.Name.ScriptHash();
|
|
||||||
RegisterUserDataField(typeHash, fieldName, userDataField);
|
RegisterUserDataField(typeHash, fieldName, userDataField);
|
||||||
ReverseLookup[typeHash].Fields[fieldName] = fieldData;
|
userData.Fields.Add(fieldName, fieldData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RegisterFunction(MethodInfo method, uint typeHash)
|
private static void RegisterFunction(MethodInfo method, uint typeHash)
|
||||||
|
@ -130,12 +138,16 @@ namespace PorygonSharp.UserData
|
||||||
var type = ScriptType.ScriptType.GetFunctionScriptType(method);
|
var type = ScriptType.ScriptType.GetFunctionScriptType(method);
|
||||||
if (type == IntPtr.Zero || !type.HasValue)
|
if (type == IntPtr.Zero || !type.HasValue)
|
||||||
return;
|
return;
|
||||||
|
if (!ReverseLookup.TryGetValue(typeHash, out var userData))
|
||||||
|
return;
|
||||||
|
var fieldName = method.Name.ScriptHash();
|
||||||
|
if (userData.Fields.ContainsKey(fieldName))
|
||||||
|
return;
|
||||||
var fieldData = new UserDataField(method);
|
var fieldData = new UserDataField(method);
|
||||||
var userDataField = CreateUserDataField(type.Value, fieldData.GetGetterPointer(), IntPtr.Zero);
|
var userDataField = CreateUserDataField(type.Value, fieldData.GetGetterPointer(), IntPtr.Zero);
|
||||||
|
|
||||||
var fieldName = method.Name.ScriptHash();
|
|
||||||
RegisterUserDataField(typeHash, fieldName, userDataField);
|
RegisterUserDataField(typeHash, fieldName, userDataField);
|
||||||
ReverseLookup[typeHash].Fields[fieldName] = fieldData;
|
userData.Fields.Add(fieldName, fieldData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static uint GetTypeId(Type t)
|
public static uint GetTypeId(Type t)
|
||||||
|
@ -173,19 +185,19 @@ namespace PorygonSharp.UserData
|
||||||
return CreateUserDataType(hash);
|
return CreateUserDataType(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "RegisterUserDataType", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "RegisterUserDataType", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern void RegisterUserDataType(uint hashId);
|
private static extern void RegisterUserDataType(uint hashId);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "RegisterUserDataField", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "RegisterUserDataField", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern void RegisterUserDataField(uint hashId, uint fieldId, IntPtr field);
|
private static extern void RegisterUserDataField(uint hashId, uint fieldId, IntPtr field);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateUserDataField", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateUserDataField", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateUserDataField(IntPtr type, IntPtr getter, IntPtr setter);
|
private static extern IntPtr CreateUserDataField(IntPtr type, IntPtr getter, IntPtr setter);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "GetUserDataFieldCount", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "GetUserDataFieldCount", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern int GetUserDataFieldCount(uint hashId);
|
private static extern int GetUserDataFieldCount(uint hashId);
|
||||||
|
|
||||||
[DllImport("libPorygonLang", EntryPoint = "CreateUserDataType", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("PorygonLang", EntryPoint = "CreateUserDataType", CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr CreateUserDataType(uint hashId);
|
private static extern IntPtr CreateUserDataType(uint hashId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue