├── .gitignore
├── LICENSE
├── README.md
├── WrenSharp.Core.Shared
├── IWrenErrorOutput.cs
├── IWrenForeign.cs
├── IWrenModuleProvider.cs
├── IWrenModuleResolver.cs
├── IWrenSource.cs
├── IWrenVMWithForeign.cs
├── IWrenWriteOutput.cs
├── Internal
│ ├── ForeignLookup.cs
│ ├── InternalWrenHandle.cs
│ ├── StringBuilderCache.cs
│ ├── Utf8StringBuilder.cs
│ └── WrenInternal.cs
├── Memory
│ ├── HGlobalAllocator.cs
│ └── IAllocator.cs
├── Reflection
│ ├── WrenAttribute.cs
│ ├── WrenCallHandleAttribute.cs
│ ├── WrenEnumAttribute.cs
│ ├── WrenIgnoreAttribute.cs
│ ├── WrenInitializeAttribute.cs
│ ├── WrenOrderedAttribute.cs
│ ├── WrenPropertyAttribute.cs
│ ├── WrenReflection.cs
│ └── WrenVariableHandleAttribute.cs
├── Sources
│ ├── WrenFileSource.cs
│ ├── WrenStringBuilderSource.cs
│ └── WrenStringSource.cs
├── WrenCall.cs
├── WrenCallContext.cs
├── WrenCallHandle.cs
├── WrenError.cs
├── WrenExceptions.cs
├── WrenFn.cs
├── WrenHandle.cs
├── WrenList.Ext.cs
├── WrenList.cs
├── WrenMap.Ext.cs
├── WrenMap.cs
├── WrenSharedData.cs
├── WrenSharedDataHandle.cs
├── WrenSharp.Core.Shared.projitems
├── WrenSharp.Core.Shared.shproj
├── WrenSharpConfiguration.cs
├── WrenSlot.Ext.cs
├── WrenSlot.cs
├── WrenSlots.Ext.cs
├── WrenSlots.cs
├── WrenUnsafeExtensions.cs
├── WrenUtils.cs
├── WrenVM.ApiSlots.cs
├── WrenVM.ApiUserData.cs
├── WrenVM.ApiVariables.cs
├── WrenVM.Ext.cs
├── WrenVM.cs
└── WrenVMConfiguration.cs
├── WrenSharp.Core.Templates
├── WrenList.cs
├── WrenList.tt
├── WrenMap.cs
├── WrenMap.tt
└── WrenSharp.Core.Templates.csproj
├── WrenSharp.Lib.NetStandard
├── Unsafe
│ └── WrenMethod.cs
├── Wren.cs
├── WrenSharp.Lib.NetStandard.csproj
├── wren.dll
├── wren.exp
└── wren.lib
├── WrenSharp.Lib.Shared
├── StringBuilderCache.cs
├── Unsafe
│ ├── UnsafeUtils.cs
│ ├── WrenCallContextUnsafeExtensions.cs
│ ├── WrenClass.cs
│ ├── WrenForeign.cs
│ ├── WrenInstance.cs
│ ├── WrenInternalTypes.cs
│ ├── WrenNativeHandle.cs
│ ├── WrenNativeList.cs
│ ├── WrenNativeMap.cs
│ ├── WrenObjType.cs
│ ├── WrenObject.cs
│ ├── WrenObjectType.cs
│ ├── WrenString.cs
│ └── WrenValue.cs
├── Wren.cs
├── WrenErrorType.cs
├── WrenInterpretResult.cs
├── WrenNativeTypes.cs
├── WrenSharp.Lib.Shared.projitems
├── WrenSharp.Lib.Shared.shproj
└── WrenType.cs
├── WrenSharp.Lib.Unity
├── Unsafe
│ └── WrenMethod.cs
├── Wren.cs
├── WrenSharp.Lib.Unity.csproj
├── wren_unity.dll
└── wren_unity.exp
├── WrenSharp.Tests
├── SharedDataTests.cs
├── Usings.cs
├── WrenSharp.Tests.csproj
└── WrenSharpVMTests.cs
├── WrenSharp.Unity.Project
├── .gitignore
├── .vsconfig
├── Assets
│ ├── FiraCode-Medium.ttf
│ ├── Scenes
│ │ └── WrenREPL.unity
│ └── WrenREPL.cs
├── Packages
│ ├── com.deadreckoned.wrensharp
│ │ ├── Assemblies.meta
│ │ ├── Assemblies
│ │ │ ├── WrenSharp.Unity.dll
│ │ │ ├── WrenSharp.Unity.dll.meta
│ │ │ ├── WrenSharp.Unity.xml
│ │ │ └── WrenSharp.Unity.xml.meta
│ │ ├── Plugins.meta
│ │ ├── Plugins
│ │ │ ├── Wren.meta
│ │ │ └── Wren
│ │ │ │ ├── Internal.meta
│ │ │ │ ├── Internal
│ │ │ │ ├── netstandard2.1.meta
│ │ │ │ └── netstandard2.1
│ │ │ │ │ ├── WrenSharp.Lib.Unity.dll
│ │ │ │ │ └── WrenSharp.Lib.Unity.dll.meta
│ │ │ │ ├── netstandard2.1.meta
│ │ │ │ ├── netstandard2.1
│ │ │ │ ├── WrenSharp.Lib.Unity.dll
│ │ │ │ └── WrenSharp.Lib.Unity.dll.meta
│ │ │ │ ├── wren_unity.dll
│ │ │ │ └── wren_unity.dll.meta
│ │ ├── package.json
│ │ └── package.json.meta
│ ├── manifest.json
│ └── packages-lock.json
└── ProjectSettings
│ ├── AudioManager.asset
│ ├── ClusterInputManager.asset
│ ├── DynamicsManager.asset
│ ├── EditorBuildSettings.asset
│ ├── EditorSettings.asset
│ ├── GraphicsSettings.asset
│ ├── InputManager.asset
│ ├── MemorySettings.asset
│ ├── NavMeshAreas.asset
│ ├── PackageManagerSettings.asset
│ ├── Physics2DSettings.asset
│ ├── PresetManager.asset
│ ├── ProjectSettings.asset
│ ├── ProjectVersion.txt
│ ├── QualitySettings.asset
│ ├── SceneTemplateSettings.json
│ ├── TagManager.asset
│ ├── TimeManager.asset
│ ├── UnityConnectSettings.asset
│ ├── VFXManager.asset
│ ├── VersionControlSettings.asset
│ └── XRSettings.asset
├── WrenSharp.Unity
├── .gitignore
├── AssemblyInfo.cs
├── Package
├── Sources
│ └── WrenTextAssetSource.cs
├── UnityWrenDebugOutput.cs
├── UnityWrenForeign.cs
├── UnityWrenVM.cs
├── WrenSharp.Unity.csproj
└── WrenVMConfiguration.cs
├── WrenSharp.sln
└── WrenSharp
├── AssemblyInfo.cs
├── WrenConsoleOutput.cs
├── WrenForeign.cs
├── WrenSharp.csproj
├── WrenSharpVM.cs
└── WrenVMConfiguration.cs
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Steve Woolcock
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/IWrenErrorOutput.cs:
--------------------------------------------------------------------------------
1 | namespace WrenSharp
2 | {
3 | ///
4 | /// An interface for implementing Wren error callbacks.
5 | ///
6 | public interface IWrenErrorOutput
7 | {
8 | void OutputError(WrenVM vm, WrenErrorType errorType, string module, int lineNumber, string message);
9 | }
10 |
11 | ///
12 | /// A wrapper class for delegates that match the
13 | /// signature.
14 | ///
15 | public class WrenDelegateErrorOutput : IWrenErrorOutput
16 | {
17 | public delegate void Callback(WrenVM vm, WrenErrorType errorType, string module, int lineNumber, string message);
18 |
19 | private Callback m_Callback;
20 |
21 | public WrenDelegateErrorOutput(Callback callback)
22 | {
23 | m_Callback = callback;
24 | }
25 |
26 | void IWrenErrorOutput.OutputError(WrenVM vm, WrenErrorType errorType, string module, int lineNumber, string message)
27 | {
28 | m_Callback(vm, errorType, module, lineNumber, message);
29 | }
30 |
31 | public static explicit operator WrenDelegateErrorOutput(Callback callback) => new WrenDelegateErrorOutput(callback);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/IWrenModuleProvider.cs:
--------------------------------------------------------------------------------
1 | namespace WrenSharp
2 | {
3 | ///
4 | /// An interface for implementing module importing functionality for a .
5 | ///
6 | public interface IWrenModuleProvider
7 | {
8 | ///
9 | /// Provides an instance that contains the Wren source for the given module.
10 | ///
11 | /// The VM context of the request.
12 | /// The name of the module to retrieve.
13 | /// An instance.
14 | IWrenSource GetModuleSource(WrenVM vm, string module);
15 |
16 | ///
17 | /// The callback to execute when a module has been loaded by a VM. The of the module
18 | /// is provided so that any unmanaged resources that it may have acquired to load the module can freed.
19 | ///
20 | /// The VM the module was loaded into.
21 | /// The name of the module that was loaded.
22 | /// The instance that was loaded.
23 | void OnModuleLoadComplete(WrenVM vm, string module, IWrenSource source);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/IWrenModuleResolver.cs:
--------------------------------------------------------------------------------
1 | namespace WrenSharp
2 | {
3 | ///
4 | /// An interface for implementing module name resolution for a .
5 | /// This allows for mapping of one module name to another for the purposes of path resolution, aliasing, etc.
6 | ///
7 | public interface IWrenModuleResolver
8 | {
9 | ///
10 | /// Returns the resolved name of the module , which is being imported
11 | /// within by the module .
12 | ///
13 | ///
14 | ///
15 | ///
16 | /// The resolved name of the module.
17 | string ResolveModule(WrenVM vm, string importer, string name);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/IWrenSource.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WrenSharp
4 | {
5 | ///
6 | /// An interface representing a Wren source provider. instances
7 | /// can be passed into the Wren VM to be interpreted, and are also returned by
8 | /// instances when module source is requested.
9 | ///
10 | public interface IWrenSource : IDisposable
11 | {
12 | ///
13 | /// Get a pointer to the bytes containing the Wren script source that can be passed
14 | /// to the native Wren VM.
15 | ///
16 | /// The number of bytes in the source.
17 | /// A pointer to the source bytes.
18 | IntPtr GetSourceBytes(out int byteCount);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/IWrenVMWithForeign.cs:
--------------------------------------------------------------------------------
1 | namespace WrenSharp
2 | {
3 | ///
4 | /// An interface describing the contact that must be implemented by types
5 | /// that provide access to instances.
6 | ///
7 | public interface IWrenVMWithForeign
8 | {
9 | ///
10 | /// Gets an object for building foreign classes and methods.
11 | ///
12 | /// The Wren module name.
13 | /// The Wren class name.
14 | /// The instance for the supplied class.
15 | IWrenForeign Foreign(string moduleName, string className);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/IWrenWriteOutput.cs:
--------------------------------------------------------------------------------
1 | namespace WrenSharp
2 | {
3 | ///
4 | /// An interface for implementing Wren write callbacks.
5 | ///
6 | public interface IWrenWriteOutput
7 | {
8 | void OutputWrite(WrenVM vm, string text);
9 | }
10 |
11 | public class WrenDelegateWriteOutput : IWrenWriteOutput
12 | {
13 | public delegate void Callback(WrenVM vm, string text);
14 |
15 | private Callback m_Callback;
16 |
17 | public WrenDelegateWriteOutput(Callback callback)
18 | {
19 | m_Callback = callback;
20 | }
21 |
22 | void IWrenWriteOutput.OutputWrite(WrenVM vm, string text)
23 | {
24 | m_Callback(vm, text);
25 | }
26 |
27 | public static explicit operator WrenDelegateWriteOutput(Callback callback) => new WrenDelegateWriteOutput(callback);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Internal/ForeignLookup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace WrenSharp.Native
5 | {
6 | internal class ForeignLookup
7 | {
8 | private class Module
9 | {
10 | public Dictionary Classes = new Dictionary();
11 | }
12 |
13 | private readonly Dictionary Modules = new Dictionary();
14 |
15 | public void AddClass(string moduleName, string className, TForeign foreign)
16 | {
17 | if (!Modules.TryGetValue(moduleName, out Module module))
18 | {
19 | module = new Module();
20 | Modules[moduleName] = module;
21 | }
22 |
23 | module.Classes[className] = foreign;
24 | }
25 |
26 | public TForeign GetClass(string moduleName, string className)
27 | {
28 | if (!Modules.TryGetValue(moduleName, out Module module))
29 | return default;
30 |
31 | module.Classes.TryGetValue(className, out TForeign foreign);
32 | return foreign;
33 | }
34 |
35 | public void ForEachClass(Action action)
36 | {
37 | foreach (var module in Modules.Values)
38 | {
39 | foreach (var cls in module.Classes.Values)
40 | {
41 | action(cls);
42 | }
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Internal/InternalWrenHandle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 |
4 | namespace WrenSharp.Native
5 | {
6 | internal sealed class WrenHandleInternal
7 | {
8 | public readonly WrenVM VM;
9 | public int Version;
10 | public IntPtr Ptr;
11 |
12 | public WrenHandleInternal(WrenVM vm)
13 | {
14 | VM = vm;
15 | }
16 |
17 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
18 | public bool IsValid() => Ptr != IntPtr.Zero;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Internal/StringBuilderCache.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 |
4 | namespace WrenSharp.Internal
5 | {
6 | ///
7 | /// From .NET: https://github.com/dotnet/runtime/blob/main/src/libraries/Common/src/System/Text/StringBuilderCache.cs
8 | ///
9 | internal static class StringBuilderCache
10 | {
11 | internal const int MaxBuilderSize = 360;
12 | private const int DefaultCapacity = 16;
13 |
14 | [ThreadStatic]
15 | private static StringBuilder _cachedInstance;
16 |
17 | public static StringBuilder Acquire(int capacity = DefaultCapacity)
18 | {
19 | if (capacity <= MaxBuilderSize)
20 | {
21 | StringBuilder sb = _cachedInstance;
22 | if (sb != null)
23 | {
24 | if (capacity <= sb.Capacity)
25 | {
26 | _cachedInstance = null;
27 | sb.Clear();
28 | return sb;
29 | }
30 | }
31 | }
32 |
33 | return new StringBuilder(capacity);
34 | }
35 |
36 | public static void Release(StringBuilder sb)
37 | {
38 | if (sb.Capacity <= MaxBuilderSize)
39 | {
40 | _cachedInstance = sb;
41 | }
42 | }
43 |
44 | public static string GetStringAndRelease(StringBuilder sb)
45 | {
46 | string result = sb.ToString();
47 | Release(sb);
48 | return result;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Internal/WrenInternal.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using System.Text;
4 | using WrenSharp.Memory;
5 |
6 | namespace WrenSharp.Native
7 | {
8 | internal static class WrenInternal
9 | {
10 | public unsafe static string WrenStringBytesToString(byte* bytes, int byteCount)
11 | {
12 | // FIXME: Wren is not returning UTF8 code points from the slot API, even though it accepts them.
13 | // So just using ASCII encoding for now, as that's all we can do without modifying the Wren source.
14 | var encoding = Encoding.ASCII;
15 | return encoding.GetString(bytes, byteCount);
16 | }
17 |
18 | public unsafe static ReadOnlySpan GetSlotStringBytes(IntPtr vm, int slot)
19 | {
20 | int length;
21 | var ptr = (byte*)Wren.GetSlotBytes(vm, slot, (IntPtr)(&length));
22 | return new ReadOnlySpan(ptr, length);
23 | }
24 |
25 | public unsafe static string GetSlotString(IntPtr vm, int slot)
26 | {
27 | int length;
28 | var bytes = (byte*)Wren.GetSlotBytes(vm, slot, (IntPtr)(&length));
29 | return WrenStringBytesToString(bytes, length);
30 | }
31 |
32 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
33 | public unsafe static void SetSlotString(IntPtr vm, int slot, ReadOnlySpan bytes)
34 | {
35 | fixed (byte* bytePtr = bytes)
36 | {
37 | Wren.SetSlotBytes(vm, slot, (IntPtr)bytePtr, (ulong)bytes.Length);
38 | }
39 | }
40 |
41 | public unsafe static void EncodeTextBufferFromStringBuilder(
42 | StringBuilder stringBuilder, Encoding encoding, IAllocator allocator,
43 | ref byte* buffer, ref int bufferSize,
44 | out int charCount, out int byteCount)
45 | {
46 | charCount = stringBuilder.Length;
47 |
48 | // We don't know how big the buffer needs to be until the chars are encoded,
49 | // so need to allocate the maximum number of bytes required to store a string
50 | // of n length in the specified encoding + 1 for the null terminator
51 | int requiredBufferSize = encoding.GetMaxByteCount(charCount) + 1;
52 |
53 | // Free existing buffer if it isn't large enough to hold the maximum possible encoded size
54 | if (requiredBufferSize > bufferSize && buffer != null)
55 | {
56 | allocator.Free((IntPtr)buffer);
57 | buffer = null;
58 | }
59 |
60 | // Allocate a new buffer if required
61 | if (buffer == null)
62 | {
63 | buffer = (byte*)allocator.Allocate(requiredBufferSize);
64 | bufferSize = requiredBufferSize;
65 |
66 | if (buffer == null)
67 | {
68 | // Buffer couldn't be allocated
69 | bufferSize = 0;
70 | byteCount = 0;
71 | return;
72 | }
73 | }
74 |
75 | var charSpan = new Span((char*)buffer, charCount);
76 | var byteSpan = new Span(buffer, bufferSize);
77 |
78 | // Copy chars from the builder into the buffer
79 | stringBuilder.CopyTo(0, charSpan, charCount);
80 |
81 | // Encode chars in buffer
82 | // Note that this is reading and writing to the same buffer, this should be ok since
83 | // C# chars are two bytes wide, so the read cursor will always be ahead of the write cursor.
84 | byteCount = encoding.GetBytes(charSpan, byteSpan);
85 |
86 | // Add the null terminator
87 | buffer[byteCount++] = (byte)'\0';
88 | }
89 |
90 | public unsafe static void EncodeTextBufferFromString(
91 | ReadOnlySpan str, Encoding encoding, IAllocator allocator,
92 | ref byte* buffer, ref int bufferSize,
93 | out int charCount, out int byteCount)
94 | {
95 | charCount = str.Length;
96 |
97 | // We don't know how big the buffer needs to be until the chars are encoded,
98 | // so need to allocate the maximum number of bytes required to store a string
99 | // of n length in the specified encoding + 1 for the null terminator
100 | int requiredBufferSize = encoding.GetMaxByteCount(charCount) + 1;
101 |
102 | // Free existing buffer if it isn't large enough to hold the maximum possible encoded size
103 | if (requiredBufferSize > bufferSize && buffer != null)
104 | {
105 | allocator.Free((IntPtr)buffer);
106 | buffer = null;
107 | }
108 |
109 | // Allocate a new buffer if required
110 | if (buffer == null)
111 | {
112 | buffer = (byte*)allocator.Allocate(requiredBufferSize);
113 | bufferSize = requiredBufferSize;
114 |
115 | if (buffer == null)
116 | {
117 | // Buffer couldn't be allocated
118 | bufferSize = 0;
119 | byteCount = 0;
120 | return;
121 | }
122 | }
123 |
124 | byteCount = encoding.GetBytes(str, new Span(buffer, bufferSize));
125 |
126 | // Add the null terminator
127 | buffer[byteCount++] = (byte)'\0';
128 | }
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Memory/HGlobalAllocator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace WrenSharp.Memory
5 | {
6 | ///
7 | /// A simple memory allocator that wraps the and
8 | /// methods.
9 | ///
10 | public class HGlobalAllocator : IAllocator
11 | {
12 | #region Static
13 |
14 | private static readonly Lazy _default = new Lazy(isThreadSafe: true);
15 |
16 | ///
17 | /// The single default instance of .
18 | ///
19 | public static HGlobalAllocator Default => _default.Value;
20 |
21 | #endregion
22 |
23 | ///
24 | /// Allocates a contiguous block of memory that is guaranted to be at least bytes wide.
25 | /// This method wraps .
26 | ///
27 | /// The minimum number of bytes to allocate.
28 | /// An to the allocated block of memory.
29 | public IntPtr Allocate(int size) => Marshal.AllocHGlobal(size);
30 |
31 | ///
32 | /// Frees a previously allocated block of memory.
33 | /// This method wraps .
34 | ///
35 | /// A pointer to the block of memory to free.
36 | public void Free(IntPtr ptr) => Marshal.FreeHGlobal(ptr);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Memory/IAllocator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WrenSharp.Memory
4 | {
5 | ///
6 | /// An interface for memory allocators used by some WrenSharp wrappers for working with unmanaged memory.
7 | ///
8 | public interface IAllocator
9 | {
10 | ///
11 | /// Allocates a contiguous block of memory that is guaranted to be at least bytes wide.
12 | ///
13 | /// The minimum number of bytes to allocate.
14 | /// An to the allocated block of memory.
15 | IntPtr Allocate(int size);
16 |
17 | ///
18 | /// Frees a previously allocated block of memory.
19 | ///
20 | /// A pointer to the block of memory to free.
21 | void Free(IntPtr ptr);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Reflection/WrenAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WrenSharp.Reflection
4 | {
5 | ///
6 | /// Abstract base class for all Wren reflection API attributes.
7 | ///
8 | public abstract class WrenAttribute : Attribute
9 | {
10 |
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Reflection/WrenCallHandleAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WrenSharp.Reflection
4 | {
5 | ///
6 | /// Fields marked with this attribute are automatically allocated a
7 | /// matching the supplied signature when invoked via the reflection API.
8 | /// See for more information on Wren call signatures.
9 | ///
10 | [AttributeUsage(AttributeTargets.Field)]
11 | public class WrenCallHandleAttribute : WrenAttribute
12 | {
13 | ///
14 | /// The signature of the call handle.
15 | ///
16 | public string Signature { get; }
17 |
18 | public WrenCallHandleAttribute(string signature)
19 | {
20 | Signature = signature;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Reflection/WrenEnumAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WrenSharp.Reflection
4 | {
5 | ///
6 | /// Enum types annotated with this attribute are converted to static Wren classes when invoked
7 | /// via the reflection API.
8 | ///
9 | [AttributeUsage(AttributeTargets.Enum)]
10 | public class WrenEnumAttribute : WrenAttribute
11 | {
12 | ///
13 | /// The name of the module to declare the class in.
14 | ///
15 | public string Module { get; }
16 |
17 | ///
18 | /// The name of the Wren class. If null, the name of the enum type is used.
19 | ///
20 | public string ClassName { get; }
21 |
22 | public WrenEnumAttribute(string module) : this(module, null)
23 | {
24 |
25 | }
26 |
27 | public WrenEnumAttribute(string module, string className)
28 | {
29 | Module = module;
30 | ClassName = className;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Reflection/WrenIgnoreAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WrenSharp.Reflection
4 | {
5 | ///
6 | /// Fields or properties marked with this attribute are ignored by the reflection API.
7 | ///
8 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
9 | public class WrenIgnoreAttribute : WrenAttribute
10 | {
11 |
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Reflection/WrenInitializeAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WrenSharp.Reflection
4 | {
5 | ///
6 | /// Declares a method that should be invoked via WrenSharp reflection API initialization methods.
7 | /// Methods marked with this attribute must have the signature:
8 | ///
9 | /// [static] void MethodName(WrenVm vm)
10 | ///
11 | ///
12 | [AttributeUsage(AttributeTargets.Method)]
13 | public class WrenInitializeMethodAttribute : WrenOrderedAttribute
14 | {
15 | public WrenInitializeMethodAttribute() { }
16 | public WrenInitializeMethodAttribute(int order) : base(order) { }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Reflection/WrenOrderedAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WrenSharp.Reflection
4 | {
5 | ///
6 | /// Abstract base class for attributes that require ordering.
7 | ///
8 | public abstract class WrenOrderedAttribute : WrenAttribute
9 | {
10 | ///
11 | /// The order value of the attribute.
12 | ///
13 | public int Order { get; set; }
14 |
15 | public WrenOrderedAttribute() : this(0) { }
16 |
17 | public WrenOrderedAttribute(int order)
18 | {
19 | Order = order;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Reflection/WrenPropertyAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WrenSharp.Reflection
4 | {
5 | ///
6 | /// Marks a field or property for inclusion by the reflection API, where inclusion is opt-in.
7 | /// Also allows for setting an explicit name for the member when interpreted to a Wren type.
8 | ///
9 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
10 | public class WrenPropertyAttribute : WrenAttribute
11 | {
12 | ///
13 | /// The name of the property. If null, the name of the member the attribute is annotating is used.
14 | ///
15 | public string Name { get; }
16 |
17 | public WrenPropertyAttribute() { }
18 |
19 | public WrenPropertyAttribute(string name)
20 | {
21 | Name = name;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Reflection/WrenVariableHandleAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WrenSharp.Reflection
4 | {
5 | ///
6 | /// Fields marked with this attribute are automatically allocated a
7 | /// pointing to a variable declared within a resolved module, when invoked via the reflection API.
8 | ///
9 | [AttributeUsage(AttributeTargets.Field)]
10 | public class WrenVariableHandleAttribute : WrenAttribute
11 | {
12 | ///
13 | /// The name of the module the variable resides in. The module must be loaded and resolved
14 | /// for the handle to be successfully created.
15 | ///
16 | public string Module { get; }
17 |
18 | ///
19 | /// The name of the variable within the module to create a handle to.
20 | ///
21 | public string Variable { get; }
22 |
23 | public WrenVariableHandleAttribute(string module, string variable)
24 | {
25 | Module = module;
26 | Variable = variable;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Sources/WrenFileSource.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using WrenSharp.Memory;
4 |
5 | namespace WrenSharp
6 | {
7 | ///
8 | /// A Wren script source that reads the contents of file from the filesystem.
9 | ///
10 | public unsafe class WrenFileSource : IWrenSource
11 | {
12 | private readonly string m_Path;
13 | private readonly IAllocator m_Allocator;
14 |
15 | private byte* m_Buffer;
16 | private int m_BufferSize;
17 | private bool m_Disposed;
18 |
19 | ///
20 | /// Creates a new instance.
21 | ///
22 | /// The path to the source script to load.
23 | ///
24 | ///
25 | public WrenFileSource(string path, IAllocator allocator = default)
26 | {
27 | if (string.IsNullOrEmpty(path))
28 | throw new ArgumentNullException(nameof(path), "Path must be non-empty string.");
29 |
30 | m_Path = path;
31 | m_Allocator = allocator ?? HGlobalAllocator.Default;
32 | }
33 |
34 | ///
35 | /// Returns a pointer to an unmanaged buffer containing the contents of the source file.
36 | ///
37 | /// The number of bytes in the source.
38 | /// A pointer to the source bytes.
39 | public IntPtr GetSourceBytes(out int byteCount)
40 | {
41 | if (m_Buffer == null)
42 | {
43 | using var fileStream = File.OpenRead(m_Path);
44 |
45 | if (fileStream.Length > int.MaxValue)
46 | throw new InvalidOperationException($"File {m_Path} is too large ({fileStream.Length} bytes)");
47 |
48 | m_BufferSize = (int)fileStream.Length;
49 | m_Buffer = (byte*)m_Allocator.Allocate(m_BufferSize);
50 |
51 | using var memStream = new UnmanagedMemoryStream(m_Buffer, 0, m_BufferSize, FileAccess.Write);
52 | fileStream.CopyTo(memStream);
53 | }
54 |
55 | byteCount = m_BufferSize;
56 | return (IntPtr)m_Buffer;
57 | }
58 |
59 | ///
60 | /// Releases the in-memory buffer containing the contents of the file, if the file has previously
61 | /// been loaded. Otherwise, calling this method does nothing.
62 | ///
63 | public void ReleaseBuffer()
64 | {
65 | if (m_Buffer != null)
66 | {
67 | m_Allocator.Free((IntPtr)m_Buffer);
68 | m_Buffer = null;
69 | m_BufferSize = 0;
70 | }
71 | }
72 |
73 | #region IDisposable
74 |
75 | ~WrenFileSource()
76 | {
77 | Dispose(disposing: false);
78 | }
79 |
80 | public void Dispose()
81 | {
82 | Dispose(disposing: true);
83 | GC.SuppressFinalize(this);
84 | }
85 |
86 | protected virtual void Dispose(bool disposing)
87 | {
88 | if (!m_Disposed)
89 | {
90 | if (disposing)
91 | {
92 | // Dispose managed state
93 | }
94 |
95 | // Dispose unmanaged state
96 | ReleaseBuffer();
97 |
98 | m_Disposed = true;
99 | }
100 | }
101 |
102 | #endregion
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Sources/WrenStringBuilderSource.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using WrenSharp.Native;
4 | using WrenSharp.Memory;
5 |
6 | namespace WrenSharp
7 | {
8 | ///
9 | /// A Wren script source that wraps a . The contents of the source is copied
10 | /// to an unmanaged buffer, which is passed directly to the native Wren VM when the source is interpreted.
11 | ///
12 | /// This method is signficantly faster than passing a directly to the native
13 | /// WrenVM via P/Invoke.
14 | ///
15 | public unsafe class WrenStringBuilderSource : IWrenSource
16 | {
17 | private readonly StringBuilder m_StringBuilder;
18 | private readonly Encoding m_Encoding;
19 | private readonly IAllocator m_Allocator;
20 |
21 | private byte* m_BufferPtr;
22 | private int m_BufferSize;
23 | private int m_ByteCount;
24 | private int m_CharCount;
25 | private bool m_SourceDirty;
26 | private bool m_Disposed;
27 |
28 | #region Properties
29 |
30 | ///
31 | /// The containing the Wren script.
32 | ///
33 | public StringBuilder StringBuilder => m_StringBuilder;
34 |
35 | #endregion
36 |
37 | ///
38 | /// Creates a new , wrapping a .
39 | ///
40 | /// The containing the Wren source.
41 | /// The Encoding of the string. If this parameter is null, UTF8 encoding is used.
42 | /// The memory allocator to use when an unmanaged buffer is required.
43 | /// If null, the default allocator () is used.
44 | /// Thrown if is null.
45 | public WrenStringBuilderSource(StringBuilder stringBuilder, Encoding encoding = null, IAllocator allocator = null)
46 | {
47 | m_StringBuilder = stringBuilder ?? throw new ArgumentNullException(nameof(stringBuilder));
48 | m_Encoding = encoding ?? Encoding.UTF8;
49 | m_Allocator = allocator ?? HGlobalAllocator.Default;
50 | }
51 |
52 | ///
53 | /// Sets an internal flag to indicate the contents of the source has changed.
54 | /// The next time is called, the contents will be re-written to
55 | /// the internal buffer before it is returned.
56 | ///
57 | public void MarkSourceChanged()
58 | {
59 | m_SourceDirty = true;
60 | }
61 |
62 | #region IModuleSource
63 |
64 | ///
65 | /// Get a pointer to the bytes containing the Wren script source that can be passed
66 | /// to the native Wren VM.
67 | ///
68 | /// The number of bytes in the source.
69 | /// A pointer to the source bytes.
70 | public IntPtr GetSourceBytes(out int byteCount)
71 | {
72 | if (m_SourceDirty || m_StringBuilder.Length != m_CharCount)
73 | {
74 | WrenInternal.EncodeTextBufferFromStringBuilder(
75 | m_StringBuilder, m_Encoding, m_Allocator,
76 | ref m_BufferPtr, ref m_BufferSize,
77 | out m_CharCount, out m_ByteCount);
78 |
79 | m_SourceDirty = false;
80 | }
81 |
82 | byteCount = m_ByteCount;
83 | return (IntPtr)m_BufferPtr;
84 | }
85 |
86 | #endregion
87 |
88 | #region IDisposable
89 |
90 | ~WrenStringBuilderSource()
91 | {
92 | Dispose(disposing: false);
93 | }
94 |
95 | public void Dispose()
96 | {
97 | Dispose(disposing: true);
98 | GC.SuppressFinalize(this);
99 | }
100 |
101 | protected virtual void Dispose(bool disposing)
102 | {
103 | if (!m_Disposed)
104 | {
105 | if (disposing)
106 | {
107 | // Dispose managed state
108 | }
109 |
110 | // Dispose unmanaged state
111 | if (m_BufferPtr != null)
112 | {
113 | m_Allocator.Free((IntPtr)m_BufferPtr);
114 | m_BufferPtr = default;
115 | }
116 |
117 | m_Disposed = true;
118 | }
119 | }
120 |
121 | #endregion
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/Sources/WrenStringSource.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using WrenSharp.Native;
4 | using WrenSharp.Memory;
5 |
6 | namespace WrenSharp
7 | {
8 | ///
9 | /// A Wren script source that wraps a string. The source is copied to an unmanaged buffer, which is passed
10 | /// directly to the native Wren VM when the source is interpreted.
11 | ///
12 | public unsafe class WrenStringSource : IWrenSource
13 | {
14 | private readonly string m_Source;
15 | private readonly Encoding m_Encoding;
16 | private readonly IAllocator m_Allocator;
17 |
18 | private byte* m_BufferPtr;
19 | private int m_BufferSize;
20 | private bool m_Disposed;
21 |
22 | #region Properties
23 |
24 | ///
25 | /// The string containing the Wren script.
26 | ///
27 | public string Source => m_Source;
28 |
29 | #endregion
30 |
31 | ///
32 | /// Creates a new , wrapping a string.
33 | ///
34 | /// The string of Wren source.
35 | /// The Encoding of the string. If this parameter is null, UTF8 encoding is used.
36 | /// The memory allocator to use when an unmanaged buffer is required.
37 | /// If null, the default allocator () is used.
38 | /// Thrown if is null.
39 | public WrenStringSource(string source, Encoding encoding = null, IAllocator allocator = null)
40 | {
41 | m_Source = source ?? throw new ArgumentNullException(nameof(source));
42 | m_Encoding = encoding ?? Encoding.UTF8;
43 | m_Allocator = allocator ?? HGlobalAllocator.Default;
44 | }
45 |
46 | #region IModuleSource
47 |
48 | ///
49 | /// Get a pointer to the bytes containing the Wren script source that can be passed
50 | /// to the native Wren VM.
51 | ///
52 | /// The number of bytes in the source.
53 | /// A pointer to the source bytes.
54 | public IntPtr GetSourceBytes(out int byteCount)
55 | {
56 | if (m_BufferPtr == null)
57 | {
58 | WrenInternal.EncodeTextBufferFromString(
59 | m_Source, m_Encoding, m_Allocator,
60 | ref m_BufferPtr, ref m_BufferSize,
61 | out _, out byteCount);
62 | }
63 | else
64 | {
65 | byteCount = m_BufferSize;
66 | }
67 |
68 | return (IntPtr)m_BufferPtr;
69 | }
70 |
71 | #endregion
72 |
73 | #region IDisposable
74 |
75 | ~WrenStringSource()
76 | {
77 | Dispose(disposing: false);
78 | }
79 |
80 | public void Dispose()
81 | {
82 | Dispose(disposing: true);
83 | GC.SuppressFinalize(this);
84 | }
85 |
86 | protected virtual void Dispose(bool disposing)
87 | {
88 | if (!m_Disposed)
89 | {
90 | if (disposing)
91 | {
92 | // Dispose managed state (managed objects)
93 | }
94 |
95 | // Dispose unmanaged state
96 | if (m_BufferPtr == null)
97 | {
98 | m_Allocator.Free((IntPtr)m_BufferPtr);
99 | m_BufferPtr = null;
100 | }
101 |
102 | m_Disposed = true;
103 | }
104 | }
105 |
106 | #endregion
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenCallHandle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using WrenSharp.Native;
4 |
5 | namespace WrenSharp
6 | {
7 | ///
8 | /// A handle representing a callable Wren method. Use to call
9 | /// Wren functions from managed code.
10 | ///
11 | /// Handles must be released to free the memory allocated for them.
12 | /// implements , and can be disposed by calling
13 | /// or . instances
14 | /// will automatically release all handles allocated when disposed.
15 | ///
16 | ///
17 | ///
18 | public readonly struct WrenCallHandle : IDisposable, IEquatable
19 | {
20 | internal readonly WrenHandleInternal m_Handle;
21 | internal readonly IntPtr m_Ptr;
22 | internal readonly int m_Version;
23 | internal readonly byte m_ParamCount;
24 |
25 | #region Properties
26 |
27 | ///
28 | /// Indicates if the handle is valid. A handle is valid if it has been created and not released.
29 | /// Once a handle is released, all values pointing to it will become invalid.
30 | ///
31 | public bool IsValid
32 | {
33 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
34 | get => m_Handle != null && m_Handle.IsValid() && m_Version == m_Handle.Version && m_Ptr == m_Handle.Ptr;
35 | }
36 |
37 | ///
38 | /// The number of parameters the method call requires.
39 | ///
40 | public int ParamCount => m_ParamCount;
41 |
42 | ///
43 | /// The handle's native pointer.
44 | ///
45 | public IntPtr NativePointer
46 | {
47 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
48 | get => IsValid ? m_Ptr : IntPtr.Zero;
49 | }
50 |
51 | #endregion
52 |
53 | internal WrenCallHandle(WrenHandleInternal handle, byte paramCount)
54 | {
55 | m_Handle = handle;
56 | m_Ptr = handle.Ptr;
57 | m_Version = handle.Version;
58 | m_ParamCount = paramCount;
59 | }
60 |
61 | ///
62 | /// Releases the handle. Once released, the handle can no longer be used.
63 | ///
64 | public void Dispose() => m_Handle.VM?.ReleaseHandle(in this);
65 |
66 | #region Object
67 |
68 | ///
69 | public bool Equals(WrenCallHandle other)
70 | {
71 | return
72 | other.m_Ptr == m_Ptr &&
73 | other.m_Version == m_Version &&
74 | other.m_ParamCount == m_ParamCount &&
75 | other.m_Handle == m_Handle;
76 | }
77 |
78 | ///
79 | public override bool Equals(object obj) => obj is WrenCallHandle callHandle && Equals(callHandle);
80 |
81 | ///
82 | public override int GetHashCode() => HashCode.Combine(m_Ptr, m_Version, m_ParamCount, m_Handle);
83 |
84 | ///
85 | public override string ToString() => IsValid ? m_Ptr.ToString() : string.Empty;
86 |
87 | #endregion
88 |
89 | #region Operator Overloads
90 |
91 | ///
92 | public static bool operator ==(WrenCallHandle left, WrenCallHandle right) => left.Equals(right);
93 |
94 | ///
95 | public static bool operator !=(WrenCallHandle left, WrenCallHandle right) => !(left == right);
96 |
97 | ///
98 | /// Converts a into a .
99 | ///
100 | /// The call handle
101 | public static implicit operator WrenHandle(WrenCallHandle callHandle) => new WrenHandle(callHandle.m_Handle);
102 |
103 | #endregion
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenError.cs:
--------------------------------------------------------------------------------
1 | namespace WrenSharp
2 | {
3 | ///
4 | /// Represents an error generated by the Wren runtime.
5 | ///
6 | public class WrenError
7 | {
8 | ///
9 | /// The error type that was generated.
10 | ///
11 | public WrenErrorType ErrorType { get; }
12 |
13 | ///
14 | /// The module name the error occurred within.
15 | ///
16 | public string Module { get; }
17 |
18 | ///
19 | /// The line number in the script the error occurred at.
20 | ///
21 | public int Line { get; }
22 |
23 | ///
24 | /// The error message generated by Wren.
25 | ///
26 | public string Message { get; }
27 |
28 | internal WrenError(WrenErrorType errorType, string module, int line, string message)
29 | {
30 | ErrorType = errorType;
31 | Module = module;
32 | Line = line;
33 | Message = message;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenExceptions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 |
4 | namespace WrenSharp
5 | {
6 | ///
7 | /// Represents errors that occur during WrenSharp execution.
8 | ///
9 | public class WrenException : Exception
10 | {
11 | ///
12 | /// The VM the exeception occured in.
13 | ///
14 | public WrenVM VM { get; }
15 |
16 | ///
17 | /// The errors in the VM's error log when the exception was thrown.
18 | ///
19 | public WrenError[] Errors { get; }
20 |
21 | public WrenException(WrenVM vm) : this(vm, null, null) { }
22 | public WrenException(WrenVM vm, string message) : this(vm, message, null) { }
23 | public WrenException(WrenVM vm, string message, Exception innerException) : base(GetMessageOrDefault(vm, message), innerException)
24 | {
25 | VM = vm;
26 | Errors = (VM.Errors.Count > 0) ? VM.Errors.ToArray() : null;
27 | }
28 |
29 | private static string GetMessageOrDefault(WrenVM vm, string message)
30 | {
31 | if (message == null && vm.Errors.Count > 0)
32 | {
33 | WrenError error = vm.Errors[0];
34 | return $"{error.ErrorType}: {error.Message}";
35 | }
36 |
37 | return message;
38 | }
39 | }
40 |
41 | ///
42 | /// Represents errors that occur during intialization of a Wren VM.
43 | ///
44 | public class WrenInitializationException : WrenException
45 | {
46 | public WrenInitializationException(WrenVM vm, string message) : base(vm, message) { }
47 | public WrenInitializationException(WrenVM vm, string message, Exception innerException) : base(vm, message, innerException) { }
48 | }
49 |
50 | ///
51 | /// Represents errors that occur during a WrenSharp call.
52 | ///
53 | public class WrenInterpretException : WrenException
54 | {
55 | ///
56 | /// The result of the call or interpret run.
57 | ///
58 | public WrenInterpretResult Result { get; }
59 |
60 | public WrenInterpretException(WrenVM vm, WrenInterpretResult result) : this(vm, result, null) { }
61 | public WrenInterpretException(WrenVM vm, WrenInterpretResult result, string message) : base(vm, message)
62 | {
63 | Result = result;
64 | }
65 | }
66 |
67 | ///
68 | /// Represents errors that occur relating to invalid Wren handles.
69 | ///
70 | public class WrenInvalidHandleException : WrenException
71 | {
72 | public WrenInvalidHandleException(WrenVM vm) : base(vm, null, null) { }
73 | public WrenInvalidHandleException(WrenVM vm, string message) : base(vm, message, null) { }
74 | }
75 |
76 | ///
77 | /// Represents errors that occur relating to Wren types.
78 | ///
79 | public class WrenTypeException : WrenException
80 | {
81 | public WrenTypeException(WrenVM vm) : base(vm, null, null) { }
82 | public WrenTypeException(WrenVM vm, string message) : base(vm, message, null) { }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenFn.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 |
4 | namespace WrenSharp
5 | {
6 | ///
7 | /// Represents a dynamic Wren function created via .
8 | ///
9 | public readonly struct WrenFn : IDisposable, IEquatable
10 | {
11 | #region Properties
12 |
13 | ///
14 | /// The the function was created with.
15 | ///
16 | public WrenVM VM { get; }
17 |
18 | ///
19 | /// The name of the module the function was created within.
20 | ///
21 | public string Module { get; }
22 |
23 | ///
24 | /// The for the Wren Fn instance.
25 | ///
26 | public WrenHandle Handle { get; }
27 |
28 | ///
29 | /// The parameter count of the function.
30 | ///
31 | public byte ParamCount { get; }
32 |
33 | ///
34 | /// Returns true if the function handle is valid.
35 | ///
36 | public bool IsValid
37 | {
38 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
39 | get => Handle.IsValid;
40 | }
41 |
42 | #endregion
43 |
44 | internal WrenFn(WrenVM vm, string module, WrenHandle handle, byte paramCount)
45 | {
46 | VM = vm;
47 | Module = module;
48 | Handle = handle;
49 | ParamCount = paramCount;
50 | }
51 |
52 | ///
53 | public void Dispose()
54 | {
55 | Handle.Dispose();
56 | }
57 |
58 | ///
59 | /// Iniitlaizes a for the function.
60 | ///
61 | /// A value for the function.
62 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
63 | public WrenCall CreateCall() => VM?.CreateFunctionCall(Handle, ParamCount) ?? default;
64 |
65 | #if WRENSHARP_EXT
66 | ///
67 | /// Iniitlaizes a for the function.
68 | ///
69 | /// If true, a new Wren Fiber is created to execute the call.
70 | /// A value for the function.
71 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
72 | public WrenCall CreateCall(bool createNewFibre) => VM?.CreateFunctionCall(Handle, ParamCount, createNewFibre) ?? default;
73 | #endif
74 |
75 | #region Object
76 |
77 | ///
78 | public bool Equals(WrenFn other)
79 | {
80 | return other.ParamCount == ParamCount && other.Handle == Handle && other.VM == VM && other.Module == Module;
81 | }
82 |
83 | ///
84 | public override bool Equals(object obj) => obj is WrenFn fn && Equals(fn);
85 |
86 | ///
87 | public override int GetHashCode() => HashCode.Combine(ParamCount, Handle, VM, Module);
88 |
89 | ///
90 | public override string ToString() => Handle.ToString();
91 |
92 | #endregion
93 |
94 | #region Operators
95 |
96 | ///
97 | public static bool operator ==(WrenFn left, WrenFn right) => left.Equals(right);
98 |
99 | ///
100 | public static bool operator !=(WrenFn left, WrenFn right) => !(left == right);
101 |
102 | #endregion
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenHandle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using WrenSharp.Native;
4 |
5 | namespace WrenSharp
6 | {
7 | ///
8 | /// A handle wrapping a Wren value. When a handle is allocated, Wren guarantees the object
9 | /// will not be removed by the garbage collector. Handles can be passed into various WrenSharp
10 | /// API methods to make calls, store values, etc.
11 | ///
12 | /// Handles must be released to free the memory allocated for them.
13 | /// implements , and can be disposed by calling
14 | /// or . instances
15 | /// will automatically release all handles allocated when disposed.
16 | ///
17 | public readonly struct WrenHandle : IDisposable, IEquatable
18 | {
19 | internal readonly WrenHandleInternal m_Handle;
20 | internal readonly IntPtr m_Ptr;
21 | internal readonly int m_Version;
22 |
23 | #region Properties
24 |
25 | ///
26 | /// Indicates if the handle is valid. A handle is valid if it has been created and not released.
27 | /// Once a handle is released, all values pointing to it will become invalid.
28 | ///
29 | public bool IsValid
30 | {
31 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
32 | get => m_Handle?.IsValid() == true && m_Version == m_Handle.Version && m_Ptr == m_Handle.Ptr;
33 | }
34 |
35 | ///
36 | /// The handle's native pointer.
37 | ///
38 | public IntPtr NativePointer
39 | {
40 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
41 | get => IsValid ? m_Ptr : IntPtr.Zero;
42 | }
43 |
44 | #endregion
45 |
46 | internal WrenHandle(WrenHandleInternal handle)
47 | {
48 | m_Handle = handle;
49 | m_Ptr = m_Handle.Ptr;
50 | m_Version = m_Handle.Version;
51 | }
52 |
53 | ///
54 | /// Releases the handle. Once released, the handle can no longer be used.
55 | ///
56 | public void Dispose() => m_Handle?.VM.ReleaseHandle(in this);
57 |
58 | #region Object
59 |
60 | ///
61 | public bool Equals(WrenHandle other) => other.m_Ptr == m_Ptr && other.m_Version == m_Version && other.m_Handle == m_Handle;
62 |
63 | ///
64 | public override bool Equals(object other) => other is WrenHandle && Equals(other);
65 |
66 | ///
67 | public override int GetHashCode() => HashCode.Combine(m_Ptr, m_Version, m_Handle);
68 |
69 | ///
70 | public override string ToString()
71 | {
72 | if (!IsValid)
73 | return string.Empty;
74 |
75 | return IntPtr.Size == 4 ? $"0x{m_Ptr:X8}" : $"0x{m_Ptr:X16}";
76 | }
77 |
78 | #endregion
79 |
80 | #region Operator Overloads
81 |
82 | ///
83 | public static bool operator ==(WrenHandle left, WrenHandle right) => left.Equals(right);
84 |
85 | ///
86 | public static bool operator !=(WrenHandle left, WrenHandle right) => !(left == right);
87 |
88 | #endregion
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenList.Ext.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 | using WrenSharp.Native;
4 | using WrenSharp.Unsafe;
5 |
6 | namespace WrenSharp
7 | {
8 | public readonly partial struct WrenList
9 | {
10 | #region Properties
11 |
12 | public unsafe WrenNativeList AsNativeList => Wren.GetSlotPtr(m_Vm.m_Ptr, m_ListSlot)->AsList;
13 |
14 | #endregion
15 |
16 | ///
17 | /// Removes the value stored in from the list and places the removed value in slot[].
18 | /// If is not supplied, the default value, , is used.
19 | ///
20 | /// The index to insert the value at.
21 | /// The slot to place the removed value in. Defaults to .
22 | public WrenSlot Remove(int index, int? removedValueSlot = default)
23 | {
24 | int slot = removedValueSlot.GetValueOrDefault(m_DefaultElementSlot);
25 | Wren.ListRemove(m_Vm.m_Ptr, m_ListSlot, index, slot);
26 | return new WrenSlot(m_Vm, slot);
27 | }
28 |
29 | #region Unsafe
30 |
31 | public void Add(Unsafe.WrenValue value, int? elementSlot = default)
32 | {
33 | int slot = elementSlot.GetValueOrDefault(m_DefaultElementSlot);
34 | Wren.SetSlot(m_Vm.m_Ptr, slot, value);
35 | Wren.InsertInList(m_Vm.m_Ptr, m_ListSlot, -1, slot);
36 | }
37 |
38 | public void Insert(Unsafe.WrenValue value, int index, int? elementSlot = default)
39 | {
40 | int slot = elementSlot.GetValueOrDefault(m_DefaultElementSlot);
41 | Wren.SetSlot(m_Vm.m_Ptr, slot, value);
42 | Wren.InsertInList(m_Vm.m_Ptr, m_ListSlot, index, slot);
43 | }
44 |
45 | public bool Remove(Unsafe.WrenValue value, int? removedValueSlot = default)
46 | {
47 | int slot = removedValueSlot.GetValueOrDefault(m_DefaultElementSlot);
48 | Wren.SetSlot(m_Vm.m_Ptr, m_DefaultElementSlot, value);
49 | int index = Wren.GetListIndexOf(m_Vm.m_Ptr, m_ListSlot, m_DefaultElementSlot);
50 | if (index > -1)
51 | {
52 | Wren.ListRemove(m_Vm.m_Ptr, m_ListSlot, index, slot);
53 | return true;
54 | }
55 |
56 | return false;
57 | }
58 |
59 | public bool Remove(Unsafe.WrenValue value, ref WrenSlot removedValueSlot)
60 | {
61 | Wren.SetSlot(m_Vm.m_Ptr, m_DefaultElementSlot, value);
62 | int index = Wren.GetListIndexOf(m_Vm.m_Ptr, m_ListSlot, m_DefaultElementSlot);
63 | if (index > -1)
64 | {
65 | Wren.ListRemove(m_Vm.m_Ptr, m_ListSlot, index, removedValueSlot);
66 | return true;
67 | }
68 |
69 | return false;
70 | }
71 |
72 | public unsafe ref Unsafe.WrenValue GetUnsafe(int index, int? elementSlot = default) => ref *GetUnsafePtr(index, elementSlot);
73 |
74 | public unsafe Unsafe.WrenValue* GetUnsafePtr(int index, int? elementSlot = default)
75 | {
76 | int slot = elementSlot.GetValueOrDefault(m_DefaultElementSlot);
77 | Wren.GetListElement(m_Vm.m_Ptr, m_ListSlot, index, slot);
78 | return Wren.GetSlotPtr(m_Vm.m_Ptr, slot);
79 | }
80 |
81 | #endregion
82 | }
83 | }
84 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenMap.Ext.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using WrenSharp.Native;
3 | using WrenSharp.Unsafe;
4 |
5 | namespace WrenSharp
6 | {
7 | public readonly partial struct WrenMap
8 | {
9 | #region Properties
10 |
11 | public unsafe WrenNativeMap AsNativeMap => Wren.GetSlotPtr(m_Vm.m_Ptr, m_MapSlot)->AsMap;
12 |
13 | #endregion
14 |
15 | public unsafe ref Unsafe.WrenValue GetValueUnsafe(int keySlot, int? valueSlot = default) => ref *GetValueUnsafePtr(keySlot, valueSlot);
16 |
17 | public unsafe Unsafe.WrenValue* GetValueUnsafePtr(int keySlot, int? valueSlot = default)
18 | {
19 | int slot = valueSlot.GetValueOrDefault(m_DefaultValueSlot);
20 | Wren.GetMapValue(m_Vm.m_Ptr, m_MapSlot, keySlot, slot);
21 | return Wren.GetSlotPtr(m_Vm.m_Ptr, slot);
22 | }
23 | }
24 | }
25 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenMap.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using WrenSharp.Native;
4 |
5 | namespace WrenSharp
6 | {
7 | public readonly partial struct WrenMap
8 | {
9 | private readonly WrenVM m_Vm;
10 | private readonly int m_MapSlot;
11 | private readonly int m_DefaultKeySlot;
12 | private readonly int m_DefaultValueSlot;
13 |
14 | #region Properties
15 |
16 | ///
17 | /// The slot the map resides in.
18 | ///
19 | public int MapSlot => m_MapSlot;
20 |
21 | ///
22 | /// The default slot the Wren API will read keys from if an override is not supplied.
23 | ///
24 | public int DefaultKeySlot => m_DefaultKeySlot;
25 |
26 | ///
27 | /// The default slot the Wren API will read or write values to if an override is not supplied.
28 | ///
29 | public int DefaultValueSlot => m_DefaultValueSlot;
30 |
31 | ///
32 | /// The count of entries in the map.
33 | ///
34 | public int Count => Wren.GetMapCount(m_Vm.m_Ptr, m_MapSlot);
35 |
36 | ///
37 | /// The the map resides within.
38 | ///
39 | public WrenVM VM => m_Vm;
40 |
41 | #endregion
42 |
43 | ///
44 | /// Initializes a and ensures there are enough Wren API slots allocated to read and write to the map.
45 | ///
46 | /// The the map resides in.
47 | /// The API slot the map resides in.
48 | /// The API slot to store keys in. If null, uses + 1.
49 | /// The API slot to read and write from. If null, uses + 1.
50 | /// Thrown if the value in is not a .
51 | public WrenMap(WrenVM vm, int mapSlot, int? keySlot = default, int? valueSlot = default)
52 | {
53 | var slotType = Wren.GetSlotType(vm.m_Ptr, mapSlot);
54 | if (slotType != WrenType.Map)
55 | throw new WrenTypeException(vm, $"Value is not a Map ({slotType})");
56 |
57 | m_Vm = vm;
58 | m_MapSlot = mapSlot;
59 | m_DefaultKeySlot = keySlot.GetValueOrDefault(m_MapSlot + 1);
60 | m_DefaultValueSlot = valueSlot.GetValueOrDefault(m_DefaultKeySlot + 1);
61 |
62 | int requiredSlotCount = Math.Max(m_MapSlot, Math.Max(m_DefaultKeySlot, m_DefaultValueSlot)) + 1;
63 | vm.EnsureSlotCount(requiredSlotCount);
64 | }
65 |
66 | ///
67 | /// Clears all values in the map by invoking its clear() method.
68 | ///
69 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
70 | public void Clear() => m_Vm.MapClear(m_MapSlot);
71 |
72 | ///
73 | /// Indicates if the map contains a "null" key.
74 | ///
75 | /// True if the map contains a "null" key, otherwise false.
76 | public bool ContainsKeyNull()
77 | {
78 | Wren.SetSlotNull(m_Vm.m_Ptr, m_DefaultKeySlot);
79 | return Wren.GetMapContainsKey(m_Vm.m_Ptr, m_MapSlot, m_DefaultKeySlot) != 0;
80 | }
81 |
82 | ///
83 | /// Indicates if the map contains an entry with a key represented by the value in .
84 | ///
85 | /// The slot to read the value to compare from.
86 | /// True if the key is found, otherwise false.
87 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
88 | public bool ContainsKey(int keySlot) => Wren.GetMapContainsKey(m_Vm.m_Ptr, m_MapSlot, keySlot) != 0;
89 |
90 | ///
91 | /// Sets a key/value pair in the map using the values in and .
92 | ///
93 | /// The slot containing the key.
94 | /// The slot containing the value.
95 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
96 | public void SetValue(int keySlot, int valueSlot) => Wren.SetMapValue(m_Vm.m_Ptr, m_MapSlot, keySlot, valueSlot);
97 |
98 | public WrenSlot GetValue(int keySlot, int? valueSlot = default)
99 | {
100 | int slot = valueSlot.GetValueOrDefault(m_DefaultValueSlot);
101 | Wren.GetMapValue(m_Vm.m_Ptr, m_MapSlot, keySlot, slot);
102 | return new WrenSlot(m_Vm, slot);
103 | }
104 |
105 | public WrenSlot Remove(int keySlot, int? removedValueSlot = default)
106 | {
107 | int valueSlot = removedValueSlot.GetValueOrDefault(m_DefaultValueSlot);
108 | Wren.RemoveMapValue(m_Vm.m_Ptr, m_MapSlot, keySlot, valueSlot);
109 | return new WrenSlot(m_Vm, valueSlot);
110 | }
111 | }
112 | }
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenSharedDataHandle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace WrenSharp
5 | {
6 | ///
7 | /// A handle that points to an entry in a . This is a blittable value that is compatible
8 | /// with Wren foreign objects. It is useful for linking a Wren foreign instance to a managed object instance for cross
9 | /// comunication between native Wren and C#.
10 | ///
11 | [StructLayout(LayoutKind.Sequential)]
12 | public readonly struct WrenSharedDataHandle : IEquatable
13 | {
14 | #region Static
15 |
16 | ///
17 | /// An representing an invalid address.
18 | ///
19 | public static WrenSharedDataHandle Invalid => new WrenSharedDataHandle(0);
20 |
21 | #endregion
22 |
23 | private readonly int m_Value;
24 |
25 | #region Properties
26 |
27 | ///
28 | /// Indicates if the handle represents a valid address.
29 | ///
30 | public bool IsValid => m_Value > 0;
31 |
32 | #endregion
33 |
34 | internal WrenSharedDataHandle(int value)
35 | {
36 | m_Value = value;
37 | }
38 |
39 | #region Object
40 |
41 | ///
42 | public bool Equals(WrenSharedDataHandle other) => other.m_Value == m_Value;
43 |
44 | ///
45 | public override bool Equals(object obj) => (obj is WrenSharedDataHandle handle) && Equals(handle);
46 |
47 | ///
48 | public override int GetHashCode() => m_Value;
49 |
50 | ///
51 | public override string ToString() => $"0x{m_Value:X8}";
52 |
53 | #endregion
54 |
55 | ///
56 | public static bool operator ==(WrenSharedDataHandle left, WrenSharedDataHandle right) => left.Equals(right);
57 |
58 | ///
59 | public static bool operator !=(WrenSharedDataHandle left, WrenSharedDataHandle right) => !(left == right);
60 |
61 | ///
62 | public static implicit operator int(WrenSharedDataHandle handle) => handle.m_Value;
63 |
64 | ///
65 | public static implicit operator WrenSharedDataHandle(int handle) => new WrenSharedDataHandle(handle);
66 | }
67 | }
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenSharp.Core.Shared.projitems:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 | true
6 | 5a618bd1-02df-4a0b-9076-6fb43a7bcd26
7 |
8 |
9 | WrenSharpCoreShared
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenSharp.Core.Shared.shproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 5a618bd1-02df-4a0b-9076-6fb43a7bcd26
5 | 14.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenSharpConfiguration.cs:
--------------------------------------------------------------------------------
1 | using WrenSharp.Memory;
2 | using WrenSharp.Native;
3 |
4 | namespace WrenSharp
5 | {
6 | ///
7 | /// Configuration data for a managed instance.
8 | ///
9 | public struct WrenSharpConfiguration
10 | {
11 | ///
12 | /// The delegate to use to initialize the native Wren VM. Leave this value null
13 | /// to use the default initializer (. Supplying a custom
14 | /// initializer allows for greater control over the routine used to create the VM (for example, using a native plugin
15 | /// to initialize the VM with a custom native reallocator function).
16 | ///
17 | public WrenVMInitializer Initializer;
18 |
19 | ///
20 | /// The delegate to execute when the VM is disposed.
21 | ///
22 | public WrenVMDestructor Destructor;
23 |
24 | ///
25 | /// The allocator to use for unmanaged memory. Some WrenSharp features use unmanaged memory for performance reasons.
26 | /// The native Wren VM does not use this. If null, the default allocator () is used.
27 | ///
28 | public IAllocator Allocator;
29 |
30 | ///
31 | /// The initial capacity of the internal pool for the VM.
32 | /// The specified number of handles will be pre-allocated during intialization.
33 | /// If zero, no handles will be allocated during initialization.
34 | ///
35 | public int HandlePoolCapacityInitial;
36 |
37 | ///
38 | /// The maximum capacity of the internal pool for the VM.
39 | /// The VM will never store more than this number of handles in the pool. If the number of handles
40 | /// allocated exceeds this value, the excess managed handle wrappers will not be added to the pool
41 | /// and left for the garbage collector to dispose.
42 | /// If zero, no maximum limit is enforced.
43 | ///
44 | public int HandlePoolCapacityMax;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenSlot.Ext.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 | using System.Runtime.CompilerServices;
4 | using WrenSharp.Native;
5 |
6 | namespace WrenSharp
7 | {
8 | public readonly partial struct WrenSlot
9 | {
10 | #region Properties
11 |
12 | ///
13 | /// A pointer to the in the API slot.
14 | ///
15 | public unsafe Unsafe.WrenValue* ValuePtr => Wren.GetSlotPtr(m_Vm.m_Ptr, m_Index);
16 |
17 | ///
18 | /// The in the API slot.
19 | ///
20 | public unsafe ref Unsafe.WrenValue Value => ref *Wren.GetSlotPtr(m_Vm.m_Ptr, m_Index);
21 |
22 | #endregion
23 |
24 | ///
25 | /// Indicates if the values in this slot is equal to the value in slot[].
26 | ///
27 | /// The slot to compare to.
28 | /// True if the values are the same, otherwise false.
29 | public unsafe bool ValueEquals(int otherSlot)
30 | {
31 | return *Wren.GetSlotPtr(m_Vm.m_Ptr, m_Index) == *Wren.GetSlotPtr(m_Vm.m_Ptr, otherSlot);
32 | }
33 | }
34 | }
35 | #endif
36 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenSlots.Ext.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 | using System.Runtime.CompilerServices;
4 | using WrenSharp.Native;
5 | using WrenSharp.Unsafe;
6 |
7 | namespace WrenSharp
8 | {
9 | public partial class WrenSlots
10 | {
11 | ///
12 | /// Returns a direct view to the native Wren API slot memory for fast access by avoiding subsequent
13 | /// calls into the Wren API to retrieve value information. This method calls the Wren API to retrieve
14 | /// the current total number of slots and a pointer to the first slot, therefore the returned
15 | /// should be cached in a local variable, or any performance gains are lost.
16 | ///
17 | /// The returned span beings at slot[0] and ends at slot[Count]. Call
18 | /// first to ensure the span contains at least the required number of slots.
19 | ///
20 | public unsafe Span Span
21 | {
22 | get
23 | {
24 | int slotCount = Wren.GetSlotCount(m_Vm.m_Ptr);
25 | WrenValue* slotPtr = Wren.GetSlotPtr(m_Vm.m_Ptr, 0);
26 | return new Span(slotPtr, slotCount);
27 | }
28 | }
29 |
30 | ///
31 | /// Copies the value in slot[] to slot[].
32 | /// If is equal to , this method does nothing.
33 | /// This method does not ensure that or are valid
34 | /// before attempting the copy.
35 | ///
36 | /// The slot containing the value to copy.
37 | /// The slot to copy the value into.
38 | /// A reference to this .
39 | public unsafe WrenSlots Copy(int slotFrom, int slotTo)
40 | {
41 | if (slotFrom == slotTo)
42 | return this;
43 |
44 | *Wren.GetSlotPtr(m_Vm.m_Ptr, slotTo) = *Wren.GetSlotPtr(m_Vm.m_Ptr, slotFrom);
45 | return this;
46 | }
47 |
48 | ///
49 | /// Returns a direct view to the native Wren API slot memory for fast access by avoiding subsequent
50 | /// calls into the Wren API to retrieve value information. This method ensures that
51 | /// slots will exist, there is no need to call before invoking this method.
52 | /// The returned should be cached in a local variable, or any performance gains are lost.
53 | ///
54 | /// The returned span beings at slot[0] and ends at slot[].
55 | ///
56 | /// The number of slots to span.
57 | /// A span around the native slot values.
58 | public unsafe Span AsSpan(int count)
59 | {
60 | Wren.EnsureSlots(m_Vm.m_Ptr, count);
61 | WrenValue* slotPtr = Wren.GetSlotPtr(m_Vm.m_Ptr, 0);
62 | return new Span(slotPtr, count);
63 | }
64 |
65 | ///
66 | /// Returns a direct view to the native Wren API slot memory for fast access by avoiding subsequent
67 | /// calls into the Wren API to retrieve value information. This method ensures that required number of
68 | /// slots will exist, there is no need to call before invoking this method.
69 | /// The returned should be cached in a local variable, or any performance gains are lost.
70 | ///
71 | /// The returned span beings at slot[] and ends at slot[ + ].
72 | ///
73 | /// The slot to being the span at.
74 | /// The number of slots to span.
75 | /// A span around the native slot values.
76 | public unsafe Span AsSpan(int startSlot, int count)
77 | {
78 | Wren.EnsureSlots(m_Vm.m_Ptr, startSlot + count);
79 | WrenValue* slotPtr = Wren.GetSlotPtr(m_Vm.m_Ptr, 0);
80 | return new Span(slotPtr + startSlot, count);
81 | }
82 |
83 | ///
84 | /// Indicates if the values in slot[] and slot[] hold the same values.
85 | ///
86 | /// The first slot to compare.
87 | /// The second slot to compare.
88 | /// True if the values are the same, otherwise false.
89 | public unsafe bool ValuesEqual(int slot1, int slot2) => *Wren.GetSlotPtr(m_Vm.m_Ptr, slot1) == *Wren.GetSlotPtr(m_Vm.m_Ptr, slot2);
90 | }
91 | }
92 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenSlots.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using WrenSharp.Native;
4 |
5 | namespace WrenSharp
6 | {
7 | ///
8 | /// Exposes an API for manipulating Wren API slots.
9 | ///
10 | public partial class WrenSlots
11 | {
12 | private readonly WrenVM m_Vm;
13 |
14 | #region Properties
15 |
16 | ///
17 | /// Returns the number of allocated API slots for the current Wren fiber.
18 | ///
19 | public int Count
20 | {
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | get => Wren.GetSlotCount(m_Vm.m_Ptr);
23 | }
24 |
25 | ///
26 | /// Gets a value for slot[].
27 | ///
28 | /// The index of the slot.
29 | /// A value.
30 | /// Thrown if is less than zero or greater or equal to .
31 | public WrenSlot this[int index]
32 | {
33 | get
34 | {
35 | if (index < 0 || index >= Count)
36 | throw new ArgumentOutOfRangeException(nameof(index));
37 |
38 | return new WrenSlot(m_Vm, index);
39 | }
40 | }
41 |
42 | #endregion
43 |
44 | internal WrenSlots(WrenVM vm)
45 | {
46 | m_Vm = vm;
47 | }
48 |
49 | ///
50 | /// Ensures the current Wren fiber has at least API slots available.
51 | ///
52 | /// The capacity of API slots to ensure.
53 | /// A reference to this .
54 | public WrenSlots EnsureCapacity(int capacity)
55 | {
56 | Wren.EnsureSlots(m_Vm.m_Ptr, capacity);
57 | return this;
58 | }
59 |
60 | #if !WRENSHARP_EXT
61 | ///
62 | /// Copies the value in slot[] to slot[].
63 | /// If is equal to , this method does nothing.
64 | /// This method does not ensure that or are valid
65 | /// before attempting the copy.
66 | ///
67 | /// The slot containing the value to copy.
68 | /// The slot to copy the value into.
69 | /// A reference to this .
70 | public unsafe WrenSlots Copy(int slotFrom, int slotTo)
71 | {
72 | if (slotFrom == slotTo)
73 | return this;
74 |
75 | IntPtr handle = Wren.GetSlotHandle(m_Vm.m_Ptr, slotFrom);
76 | Wren.SetSlotHandle(m_Vm.m_Ptr, slotTo, handle);
77 | Wren.ReleaseHandle(m_Vm.m_Ptr, handle);
78 | return this;
79 | }
80 | #endif
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenUnsafeExtensions.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System.Runtime.CompilerServices;
3 | using WrenSharp.Native;
4 |
5 | namespace WrenSharp.Unsafe
6 | {
7 | ///
8 | /// Unsafe extension methods.
9 | ///
10 | public unsafe static class WrenUnsafeExtensions
11 | {
12 | #region WrenCall
13 |
14 | ///
15 | /// Sets the value of argument to a .
16 | ///
17 | /// The .
18 | /// The argument index.
19 | /// The value to set.
20 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
21 | public static void SetArg(this ref WrenCall call, int arg, in WrenValue value)
22 | {
23 | Wren.SetSlot(call.m_Vm.m_Ptr, WrenCall.ArgSlot(arg), value);
24 | }
25 |
26 | ///
27 | /// Calls the Wren method and assigns the return value type to .
28 | ///
29 | /// The .
30 | /// The return value of the call.
31 | /// Determines if a is thrown if the call fails.
32 | /// A .
33 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
34 | public static WrenInterpretResult Call(this ref WrenCall call, out WrenValue returnValue, bool throwOnFailure = false)
35 | {
36 | WrenInterpretResult result = call.Call(throwOnFailure);
37 | returnValue = result == WrenInterpretResult.Success ? *Wren.GetSlotPtr(call.m_Vm.m_Ptr, 0) : default;
38 | return result;
39 | }
40 |
41 | ///
42 | /// Calls the Wren method and assigns the return value type to .
43 | ///
44 | /// The .
45 | /// The return value of the call.
46 | /// Determines if a is thrown if the call fails.
47 | /// A .
48 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
49 | public static WrenInterpretResult Call(this ref WrenCall call, out WrenValue* returnValue, bool throwOnFailure = false)
50 | {
51 | WrenInterpretResult result = call.Call(throwOnFailure);
52 | returnValue = result == WrenInterpretResult.Success ? Wren.GetSlotPtr(call.m_Vm.m_Ptr, 0) : default;
53 | return result;
54 | }
55 |
56 | #endregion
57 |
58 | #region WrenCallContext
59 |
60 | ///
61 | /// Gets the at argument slot .
62 | ///
63 | /// The .
64 | /// The argument slot.
65 | /// A .
66 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
67 | public static WrenValue GetArg(this ref WrenCallContext callContext, int arg)
68 | {
69 | return *Wren.GetSlotPtr(callContext.m_Vm.m_Ptr, callContext.ArgSlot(arg));
70 | }
71 |
72 | ///
73 | /// Gets a pointer to the at argument slot .
74 | ///
75 | /// The .
76 | /// The argument slot.
77 | /// A pointer to a .
78 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
79 | public static WrenValue* GetArgPtr(this ref WrenCallContext callContext, int arg)
80 | {
81 | return Wren.GetSlotPtr(callContext.m_Vm.m_Ptr, callContext.ArgSlot(arg));
82 | }
83 |
84 | ///
85 | /// Sets as the return value for the method call.
86 | ///
87 | /// The .
88 | /// The value to return.
89 | public static void Return(this ref WrenCallContext callContext, in WrenValue value)
90 | {
91 | Wren.SetSlot(callContext.m_Vm.m_Ptr, 0, value);
92 | }
93 |
94 | #endregion
95 | }
96 | }
97 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenVM.ApiVariables.cs:
--------------------------------------------------------------------------------
1 | using WrenSharp.Native;
2 |
3 | namespace WrenSharp
4 | {
5 | public partial class WrenVM
6 | {
7 | ///
8 | /// Stores the value of from resolved module into .
9 | /// This method ensures that enough slots are allocated to hold the current value of the variable.
10 | ///
11 | /// The module name the variable resides in.
12 | /// The name of the variable to load into .
13 | /// The slot index to load the variable into.
14 | public WrenVM LoadVariable(string module, string variableName, int slot)
15 | {
16 | Wren.EnsureSlots(m_Ptr, slot + 1);
17 | Wren.GetVariable(m_Ptr, module, variableName, slot);
18 | return this;
19 | }
20 |
21 | ///
22 | /// Attempts to store the value of from the resolved module into .
23 | /// Returns true if the variable exists and was able to be loaded. This method ensures that enough slots are allocated to hold the current
24 | /// value of the variable.
25 | ///
26 | /// The module name the variable resides in.
27 | /// The name of the variable to load into .
28 | /// The slot index to load the variable into.
29 | /// True if the variable exists and was placed into , otherwise false.
30 | public bool TryLoadVariable(string module, string variableName, int slot)
31 | {
32 | if (Wren.HasVariable(m_Ptr, module, variableName) != 0)
33 | {
34 | LoadVariable(module, variableName, slot);
35 | return true;
36 | }
37 |
38 | return false;
39 | }
40 |
41 | ///
42 | /// Stores the value of from resolved module into .
43 | /// This method does not ensure enough slots are available to hold the value of the variable. For a safer method of
44 | /// retrieving the value of a variable, use .
45 | ///
46 | /// The slot index to load the variable into.
47 | /// The module name the variable resides in.
48 | /// The name of the variable to load into .
49 | /// A reference to this .
50 | public WrenVM GetVariable(string module, string variableName, int slot)
51 | {
52 | Wren.GetVariable(m_Ptr, module, variableName, slot);
53 | return this;
54 | }
55 |
56 | ///
57 | /// Attempts to store the value of from resolved module into .
58 | /// Returns true if the variable exists. This method does not ensure enough slots are available to hold the value of the variable.
59 | /// For a safer method of retrieving the value of a variable, use .
60 | ///
61 | /// The slot index to load the variable into.
62 | /// The module name the variable resides in.
63 | /// The name of the variable to load into .
64 | /// True if the variable exists, otherwise false.
65 | public bool TryGetVariable(string module, string variableName, int slot)
66 | {
67 | if (Wren.HasVariable(m_Ptr, module, variableName) != 0)
68 | {
69 | Wren.GetVariable(m_Ptr, module, variableName, slot);
70 | return true;
71 | }
72 |
73 | return false;
74 | }
75 |
76 | ///
77 | /// Returns true if exists within the resolved module .
78 | ///
79 | /// The module name to search in.
80 | /// The variable name to find.
81 | /// True if the variable is found in the module, otherwise false.
82 | public bool HasVariable(string module, string variableName)
83 | {
84 | return Wren.HasVariable(m_Ptr, module, variableName) != 0;
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Shared/WrenVM.Ext.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System.Runtime.CompilerServices;
3 | using WrenSharp.Native;
4 |
5 | namespace WrenSharp
6 | {
7 | public unsafe partial class WrenVM
8 | {
9 | #region Properties
10 |
11 | ///
12 | /// Gets the number of bytes known to be allocated for alive objects in the VM.
13 | ///
14 | public ulong BytesAllocated => Wren.BytesAllocated(m_Ptr);
15 |
16 | ///
17 | /// Gets or sets the enabled state of the Wren garbage collected. Use
18 | /// to trigger manual garbage collections.
19 | ///
20 | public bool GCEnabled
21 | {
22 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
23 | get => Wren.GetGCEnabled(m_Ptr);
24 |
25 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
26 | set => Wren.SetGCEnabled(m_Ptr, value);
27 | }
28 |
29 | #endregion
30 |
31 | ///
32 | /// Sets the enabled state of the Wren garbage collector.
33 | ///
34 | /// The enabled state to set.
35 | public void SetGCEnabled(bool gcEnabled) => Wren.SetGCEnabled(m_Ptr, gcEnabled);
36 |
37 | ///
38 | /// Gets the enabled state of the Wren garbage collector.
39 | ///
40 | /// True if the Wren garbage collector is enabled, otherwise false.
41 | public bool GetGCEnabled() => Wren.GetGCEnabled(m_Ptr);
42 | }
43 | }
44 | #endif
45 |
--------------------------------------------------------------------------------
/WrenSharp.Core.Templates/WrenList.tt:
--------------------------------------------------------------------------------
1 | <#@ template debug="false" hostspecific="false" language="C#" #>
2 | <#@ output extension=".cs" #>
3 | using WrenSharp.Native;
4 | using System;
5 |
6 | namespace WrenSharp
7 | {
8 | public readonly partial struct WrenList
9 | {
10 | <#
11 | string[] typeNames = new string[] { "string", "double", "bool", "in WrenHandle" };
12 | string[] typeTitleCase = new string[] { "String", "Double", "Bool", "Handle" };
13 |
14 | for (int i = 0; i < typeNames.Length; i++)
15 | {
16 | string valueType = typeNames[i];
17 |
18 | if (valueType != "in WrenHandle")
19 | {
20 | #>
21 | public <#=valueType#> Get<#=typeTitleCase[i]#>(int index, int? elementSlot = default)
22 | {
23 | int slot = elementSlot.GetValueOrDefault(m_DefaultElementSlot);
24 | Wren.GetListElement(m_Vm.m_Ptr, m_ListSlot, index, slot);
25 | return m_Vm.GetSlot<#=typeTitleCase[i]#>(slot);
26 | }
27 |
28 | <#
29 | }
30 | #>
31 |
32 | public bool Contains(<#=valueType#> value, int? elementSlot = default)
33 | {
34 | return IndexOf(value, elementSlot) >= 0;
35 | }
36 |
37 | public void Add(<#=valueType#> value, int? elementSlot = default)
38 | {
39 | int slot = elementSlot.GetValueOrDefault(m_DefaultElementSlot);
40 | m_Vm.SetSlot(slot, value);
41 | Wren.InsertInList(m_Vm.m_Ptr, m_ListSlot, -1, slot);
42 | }
43 |
44 | public void Insert(int index, <#=valueType#> value, int? elementSlot = default)
45 | {
46 | int slot = elementSlot.GetValueOrDefault(m_DefaultElementSlot);
47 | m_Vm.SetSlot(slot, value);
48 | Wren.InsertInList(m_Vm.m_Ptr, m_ListSlot, index, slot);
49 | }
50 |
51 | public void Set(int index, <#=valueType#> value, int? elementSlot = default)
52 | {
53 | int slot = elementSlot.GetValueOrDefault(m_DefaultElementSlot);
54 | m_Vm.SetSlot(slot, value);
55 | Wren.SetListElement(m_Vm.m_Ptr, m_ListSlot, index, slot);
56 | }
57 |
58 | #if WRENSHARP_EXT
59 | public int IndexOf(<#=valueType#> value, int? elementSlot = default)
60 | {
61 | int slot = elementSlot.GetValueOrDefault(m_DefaultElementSlot);
62 | m_Vm.SetSlot(slot, value);
63 | return Wren.GetListIndexOf(m_Vm.m_Ptr, m_ListSlot, slot);
64 | }
65 | #else
66 | public int IndexOf(<#=valueType#> value, int? elementSlot = default)
67 | {
68 | int slot = elementSlot.GetValueOrDefault(m_DefaultElementSlot);
69 | m_Vm.SetSlot(m_DefaultElementSlot, value);
70 |
71 | int count = Wren.GetListCount(m_Vm.m_Ptr, m_ListSlot);
72 | for (int i = 0; i < count; i++)
73 | {
74 | Wren.GetListElement(m_Vm.m_Ptr, m_ListSlot, i, slot);
75 | <#
76 | if (valueType == "in WrenHandle")
77 | {
78 | #>
79 | if (m_Vm.GetSlot<#=typeTitleCase[i]#>(slot) == value.m_Ptr)
80 | {
81 | return i;
82 | }
83 | <#
84 | }
85 | else
86 | {
87 | #>
88 | if (m_Vm.GetSlot<#=typeTitleCase[i]#>(slot) == value)
89 | {
90 | return i;
91 | }
92 | <#
93 | }
94 | #>
95 |
96 | }
97 |
98 | return -1;
99 | }
100 | #endif
101 |
102 | <#
103 | }
104 | #>
105 | }
106 | }
--------------------------------------------------------------------------------
/WrenSharp.Core.Templates/WrenSharp.Core.Templates.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.1
5 | enable
6 | True
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | WrenList.cs
16 | TextTemplatingFileGenerator
17 |
18 |
19 | TextTemplatingFileGenerator
20 | WrenMap.cs
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | WrenList.tt
31 | True
32 | True
33 |
34 |
35 | True
36 | True
37 | WrenMap.tt
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.NetStandard/Unsafe/WrenMethod.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace WrenSharp.Unsafe
6 | {
7 | internal unsafe partial struct WrenInternalMethod
8 | {
9 | [FieldOffset(8)]
10 | private readonly IntPtr m_Foreign;
11 |
12 | [FieldOffset(16)]
13 | private readonly IntPtr m_Closure;
14 | }
15 | }
16 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.NetStandard/Wren.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace WrenSharp.Native
5 | {
6 | public partial class Wren
7 | {
8 | public const string NativeLibrary = "wren";
9 | }
10 |
11 | public partial class WrenNativeFn
12 | {
13 | // Foriegn
14 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
15 | public delegate ForeignMethod BindForeignMethod(IntPtr vm, string module, string className, byte isStatic, string signature);
16 |
17 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
18 | public delegate void ForeignMethod(IntPtr vm);
19 |
20 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
21 | public delegate void Finalizer(IntPtr data);
22 | }
23 |
24 | ///
25 | /// Represents the native WrenForeignClassMethods struct that provides allocate and finalize
26 | /// function pointers for a Wren foreign class instantiation.
27 | /// C type: struct WrenForeignClassMethods
28 | ///
29 | [StructLayout(LayoutKind.Sequential, Size = 16)]
30 | public struct WrenForeignClassMethods
31 | {
32 | // This struct is passed directly into Wren native functions,
33 | // so the layout must match the native C WrenConfiguration type.
34 |
35 | public WrenNativeFn.ForeignMethod Allocate;
36 | public WrenNativeFn.Finalizer Finalize;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.NetStandard/WrenSharp.Lib.NetStandard.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.1
5 | True
6 | Debug;Release
7 | $(MSBuildProjectName)
8 | WrenSharp.Internal
9 |
10 |
11 |
12 | $(DefineConstants);WRENSHARP_EXT
13 |
14 |
15 |
16 | $(DefineConstants);WRENSHARP_EXT
17 |
18 |
19 |
20 |
21 | Always
22 |
23 |
24 | Always
25 |
26 |
27 | Always
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.NetStandard/wren.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevewoolcock/WrenSharp/6b44a219a1dfb0bca559480532e97645e879ff8b/WrenSharp.Lib.NetStandard/wren.dll
--------------------------------------------------------------------------------
/WrenSharp.Lib.NetStandard/wren.exp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevewoolcock/WrenSharp/6b44a219a1dfb0bca559480532e97645e879ff8b/WrenSharp.Lib.NetStandard/wren.exp
--------------------------------------------------------------------------------
/WrenSharp.Lib.NetStandard/wren.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevewoolcock/WrenSharp/6b44a219a1dfb0bca559480532e97645e879ff8b/WrenSharp.Lib.NetStandard/wren.lib
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/StringBuilderCache.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 |
4 | namespace WrenSharp.Internal
5 | {
6 | ///
7 | /// From .NET: https://github.com/dotnet/runtime/blob/main/src/libraries/Common/src/System/Text/StringBuilderCache.cs
8 | ///
9 | internal static class StringBuilderCache
10 | {
11 | internal const int MaxBuilderSize = 360;
12 | private const int DefaultCapacity = 16;
13 |
14 | [ThreadStatic]
15 | private static StringBuilder _cachedInstance;
16 |
17 | public static StringBuilder Acquire(int capacity = DefaultCapacity)
18 | {
19 | if (capacity <= MaxBuilderSize)
20 | {
21 | StringBuilder sb = _cachedInstance;
22 | if (sb != null)
23 | {
24 | if (capacity <= sb.Capacity)
25 | {
26 | _cachedInstance = null;
27 | sb.Clear();
28 | return sb;
29 | }
30 | }
31 | }
32 |
33 | return new StringBuilder(capacity);
34 | }
35 |
36 | public static void Release(StringBuilder sb)
37 | {
38 | if (sb.Capacity <= MaxBuilderSize)
39 | {
40 | _cachedInstance = sb;
41 | }
42 | }
43 |
44 | public static string GetStringAndRelease(StringBuilder sb)
45 | {
46 | string result = sb.ToString();
47 | Release(sb);
48 | return result;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/UnsafeUtils.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | namespace WrenSharp.Unsafe
4 | {
5 | internal class UnsafeUtils
6 | {
7 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
8 | public unsafe static int Memcmp(void* str1, void* str2, int count)
9 | {
10 | byte* s1 = (byte*)str1;
11 | byte* s2 = (byte*)str2;
12 | while (count-- > 0)
13 | {
14 | if (*s1++ != *s2++)
15 | return s1[-1] < s2[-1] ? -1 : 1;
16 | }
17 |
18 | return 0;
19 | }
20 |
21 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
22 | public unsafe static bool Memeq(void* str1, void* str2, int count)
23 | {
24 | if (str1 == str2)
25 | return true;
26 |
27 | byte* s1 = (byte*)str1;
28 | byte* s2 = (byte*)str2;
29 | while (count-- > 0)
30 | {
31 | if (*s1++ != *s2++)
32 | return false;
33 | }
34 |
35 | return true;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/WrenCallContextUnsafeExtensions.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | namespace WrenSharp.Unsafe
3 | {
4 | public static class WrenCallContextUnsafeExtensions
5 | {
6 | public static
7 | }
8 | }
9 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/WrenClass.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 |
4 | namespace WrenSharp.Unsafe
5 | {
6 | public readonly unsafe struct WrenClass : IEquatable
7 | {
8 | private readonly WrenInternalObjClass* m_Ptr;
9 |
10 | #region Properties
11 |
12 | ///
13 | /// Indicates if the value has a valid underlying pointer.
14 | ///
15 | public bool IsValid => m_Ptr != null;
16 |
17 | ///
18 | /// The header for this object.
19 | ///
20 | public WrenObject Object => new WrenObject(&m_Ptr->Object);
21 |
22 | ///
23 | /// The number of fields.
24 | ///
25 | public int FieldCount => m_Ptr->NumFields;
26 |
27 | ///
28 | /// The superclass of this class.
29 | ///
30 | public WrenClass Superclass => new WrenClass(m_Ptr->Superclass);
31 |
32 | ///
33 | /// The name of the class.
34 | ///
35 | public WrenString Name => new WrenString(m_Ptr->Name);
36 |
37 | #endregion
38 |
39 | internal WrenClass(WrenInternalObjClass* cls)
40 | {
41 | m_Ptr = cls;
42 | }
43 |
44 | #region Object
45 |
46 | public bool Equals(WrenClass other) => other.m_Ptr == m_Ptr;
47 |
48 | public override bool Equals(object obj) => obj is WrenClass cls && Equals(cls);
49 |
50 | public override int GetHashCode() => ((IntPtr)m_Ptr).GetHashCode();
51 |
52 | public override string ToString() => Name.ToString();
53 |
54 | #endregion
55 |
56 | #region Operators
57 |
58 | public static bool operator ==(WrenClass left, WrenClass right) => left.Equals(right);
59 | public static bool operator !=(WrenClass left, WrenClass right) => !(left == right);
60 |
61 | #endregion
62 | }
63 | }
64 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/WrenForeign.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 |
4 | namespace WrenSharp.Unsafe
5 | {
6 | public readonly unsafe struct WrenForeign : IEquatable
7 | {
8 | private readonly WrenInternalObjForeign* m_Ptr;
9 |
10 | #region Properties
11 |
12 | ///
13 | /// Indicates if the value has a valid underlying pointer.
14 | ///
15 | public bool IsValid => m_Ptr != null;
16 |
17 | ///
18 | /// The header for this object.
19 | ///
20 | public WrenObject Object => new WrenObject(&m_Ptr->Object);
21 |
22 | ///
23 | /// The size of the memory block that was allocated for the instance.
24 | ///
25 | public int Size => (int)m_Ptr->Size;
26 |
27 | ///
28 | /// Gets the values of the instance's fields. It is recommended to fetch the span once and cache
29 | /// it in a local variable before iterating.
30 | ///
31 | public byte* Data => &m_Ptr->Data;
32 |
33 | ///
34 | /// Returns a span wrapping the foreign instance's data.
35 | ///
36 | public Span Span => new Span(&m_Ptr->Data, (int)m_Ptr->Size);
37 |
38 | #endregion
39 |
40 | internal WrenForeign(WrenInternalObjForeign* instance)
41 | {
42 | m_Ptr = instance;
43 | }
44 |
45 | public ref T As() where T : unmanaged => ref *(T*)&m_Ptr->Data;
46 |
47 | public T* AsPtr() where T : unmanaged => (T*)&m_Ptr->Data;
48 |
49 | public Span AsSpan() where T : unmanaged => new Span(&m_Ptr->Data, Size / sizeof(T));
50 |
51 | #region Object
52 |
53 | public bool Equals(WrenForeign other) => other.m_Ptr == m_Ptr;
54 |
55 | public override bool Equals(object obj) => obj is WrenForeign instance && Equals(instance);
56 |
57 | public override int GetHashCode() => ((IntPtr)m_Ptr).GetHashCode();
58 |
59 | public override string ToString() => $"instance of {Object.Class.Name}";
60 |
61 | #endregion
62 |
63 | public static bool operator ==(WrenForeign left, WrenForeign right) => left.Equals(right);
64 | public static bool operator !=(WrenForeign left, WrenForeign right) => !(left == right);
65 | }
66 | }
67 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/WrenInstance.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 |
4 | namespace WrenSharp.Unsafe
5 | {
6 | public readonly unsafe struct WrenInstance : IEquatable
7 | {
8 | private readonly WrenInternalObjInstance* m_Ptr;
9 |
10 | #region Properties
11 |
12 | ///
13 | /// Indicates if the value has a valid underlying pointer.
14 | ///
15 | public bool IsValid => m_Ptr != null;
16 |
17 | ///
18 | /// The header for this object.
19 | ///
20 | public WrenObject Object => new WrenObject(&m_Ptr->Object);
21 |
22 | ///
23 | /// Gets the of the instance.
24 | ///
25 | public WrenClass Class => new WrenClass(m_Ptr->Object.ClassObj);
26 |
27 | ///
28 | /// The number of fields.
29 | ///
30 | public int FieldCount => m_Ptr->Object.ClassObj->NumFields;
31 |
32 | ///
33 | /// Gets the values of the instance's fields. It is recommended to fetch the span once and cache
34 | /// it in a local variable before iterating.
35 | ///
36 | public Span Fields => new Span(&m_Ptr->Fields, m_Ptr->Object.ClassObj->NumFields);
37 |
38 | #endregion
39 |
40 | internal WrenInstance(WrenInternalObjInstance* instance)
41 | {
42 | m_Ptr = instance;
43 | }
44 |
45 | #region Object
46 |
47 | public bool Equals(WrenInstance other) => other.m_Ptr == m_Ptr;
48 |
49 | public override bool Equals(object obj) => obj is WrenInstance instance && Equals(instance);
50 |
51 | public override int GetHashCode() => ((IntPtr)m_Ptr).GetHashCode();
52 |
53 | public override string ToString() => $"instance of {Object.Class.Name}";
54 |
55 | #endregion
56 |
57 | public static bool operator ==(WrenInstance left, WrenInstance right) => left.Equals(right);
58 | public static bool operator !=(WrenInstance left, WrenInstance right) => !(left == right);
59 | }
60 | }
61 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/WrenInternalTypes.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | namespace WrenSharp.Unsafe
7 | {
8 | [StructLayout(LayoutKind.Sequential)]
9 | internal unsafe struct WrenInternalObj
10 | {
11 | public WrenObjectType Type;
12 | private readonly byte IsDark;
13 | public WrenInternalObjClass* ClassObj;
14 | private readonly WrenInternalObj* Next;
15 | }
16 |
17 | [StructLayout(LayoutKind.Sequential)]
18 | internal unsafe readonly struct WrenInternalObjClass
19 | {
20 | public readonly WrenInternalObj Object;
21 | public readonly WrenInternalObjClass* Superclass;
22 | public readonly int NumFields;
23 | private readonly WrenInternalBuffer m_MethodBuffer;
24 | public readonly WrenInternalObjString* Name;
25 |
26 | // Flexible array, size is undefined
27 | public readonly WrenValue AttributesValue;
28 | }
29 |
30 | [StructLayout(LayoutKind.Sequential)]
31 | internal unsafe struct WrenInternalObjString
32 | {
33 | public WrenInternalObj Object;
34 | public int Length;
35 | public int Hash;
36 |
37 | // Flexible array, size is undefined
38 | public byte ValueArray;
39 | }
40 |
41 | [StructLayout(LayoutKind.Sequential)]
42 | internal unsafe struct WrenInternalObjInstance
43 | {
44 | public WrenInternalObj Object;
45 |
46 | // Flexible array, size is undefined
47 | public WrenValue Fields;
48 | }
49 |
50 | [StructLayout(LayoutKind.Sequential)]
51 | internal unsafe struct WrenInternalObjForeign
52 | {
53 | public WrenInternalObj Object;
54 |
55 | // WrenSharp extension
56 | // Vanilla Wren does not store the size of the data block
57 | public ulong Size;
58 |
59 | // Flexible array, size is undefined
60 | public byte Data;
61 | }
62 |
63 | [StructLayout(LayoutKind.Sequential)]
64 | internal unsafe struct WrenInternalObjList
65 | {
66 | public WrenInternalObj Object;
67 | public WrenInternalBuffer Elements;
68 | }
69 |
70 | [StructLayout(LayoutKind.Sequential)]
71 | internal unsafe struct WrenInternalObjMap
72 | {
73 | [StructLayout(LayoutKind.Sequential)]
74 | internal unsafe struct Entry
75 | {
76 | public WrenValue Key;
77 | public WrenValue Value;
78 | }
79 |
80 | public WrenInternalObj Object;
81 | public uint Capacity;
82 | public uint Count;
83 | public Entry* Entries;
84 | }
85 |
86 | [StructLayout(LayoutKind.Sequential)]
87 | internal unsafe struct WrenInternalObjRange
88 | {
89 | public WrenInternalObj Object;
90 | public double From;
91 | public double To;
92 | [MarshalAs(UnmanagedType.U1)]
93 | public bool IsInclusive;
94 | }
95 |
96 | [StructLayout(LayoutKind.Sequential)]
97 | internal unsafe struct WrenInternalBuffer where T : unmanaged
98 | {
99 | public T* Data;
100 | public int Count;
101 | public int Capacity;
102 |
103 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
104 | public Span AsSpan() => new Span(Data, Count);
105 | }
106 |
107 | [StructLayout(LayoutKind.Explicit)]
108 | internal unsafe partial struct WrenInternalMethod
109 | {
110 | [FieldOffset(0)]
111 | private readonly IntPtr m_Primitive;
112 |
113 | // The rest of this must be filled out by the main project implementation,
114 | // as it differs between the standard lib and the Unity lib.
115 | }
116 | }
117 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/WrenNativeHandle.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 | using System.Runtime.CompilerServices;
4 |
5 | namespace WrenSharp.Unsafe
6 | {
7 | public readonly unsafe struct WrenNativeHandle : IEquatable
8 | {
9 | public readonly WrenValue Value;
10 | public readonly WrenNativeHandle* Prev;
11 | public readonly WrenNativeHandle* Next;
12 |
13 | #region Object
14 |
15 | public override bool Equals(object obj) => obj is WrenNativeHandle handle && Equals(handle);
16 |
17 | public bool Equals(WrenNativeHandle other) => other.Value == Value && other.Prev == Prev && other.Next == Next;
18 |
19 | public override int GetHashCode() => HashCode.Combine(Value, (IntPtr)Prev, (IntPtr)Next);
20 |
21 | public override string ToString() => $"{nameof(WrenNativeHandle)}({Value})";
22 |
23 | #endregion
24 |
25 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
26 | public static bool operator ==(WrenNativeHandle left, WrenNativeHandle right) => left.Equals(right);
27 |
28 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
29 | public static bool operator !=(WrenNativeHandle left, WrenNativeHandle right) => !(left == right);
30 |
31 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
32 | public static bool operator ==(WrenNativeHandle left, WrenValue right) => left.Value == right;
33 |
34 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
35 | public static bool operator !=(WrenNativeHandle left, WrenValue right) => left.Value != right;
36 | }
37 | }
38 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/WrenNativeList.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 | using System.Collections.Generic;
4 |
5 | namespace WrenSharp.Unsafe
6 | {
7 | public readonly unsafe struct WrenNativeList : IEquatable, IReadOnlyList
8 | {
9 | private readonly WrenInternalObjList* m_Ptr;
10 |
11 | #region Properties
12 |
13 | ///
14 | /// Indicates if the value has a valid underlying pointer.
15 | ///
16 | public bool IsValid => m_Ptr != null;
17 |
18 | ///
19 | /// The header for this object.
20 | ///
21 | public WrenObject Object => new WrenObject(&m_Ptr->Object);
22 |
23 | ///
24 | /// Gets the count of elements in the list
25 | ///
26 | public int Count => m_Ptr->Elements.Count;
27 |
28 | ///
29 | /// Gets the capacity of the list.
30 | ///
31 | public int Capacity => m_Ptr->Elements.Capacity;
32 |
33 | ///
34 | /// Gets a span of the elements in the list.
35 | ///
36 | public Span Elements => m_Ptr->Elements.AsSpan();
37 |
38 | ///
39 | /// Gets or sets the at .
40 | ///
41 | ///
42 | ///
43 | public WrenValue this[int index]
44 | {
45 | get
46 | {
47 | if (index < 0 || index >= m_Ptr->Elements.Count)
48 | throw new ArgumentOutOfRangeException(nameof(index));
49 |
50 | return m_Ptr->Elements.Data[index];
51 | }
52 |
53 | set
54 | {
55 | if (index < 0 || index >= m_Ptr->Elements.Count)
56 | throw new ArgumentOutOfRangeException(nameof(index));
57 |
58 | m_Ptr->Elements.Data[index] = value;
59 | }
60 | }
61 |
62 | #endregion
63 |
64 | internal WrenNativeList(WrenInternalObjList* instance)
65 | {
66 | m_Ptr = instance;
67 | }
68 |
69 | public bool Contains(WrenValue value) => IndexOf(value) >= 0;
70 |
71 | public int IndexOf(WrenValue value)
72 | {
73 | for (int i = 0, len = m_Ptr->Elements.Count; i < len; i++)
74 | {
75 | if (m_Ptr->Elements.Data[i] == value)
76 | return i;
77 | }
78 |
79 | return -1;
80 | }
81 |
82 | #region Object
83 |
84 | public bool Equals(WrenNativeList other) => other.m_Ptr == m_Ptr;
85 |
86 | public override bool Equals(object obj) => obj is WrenNativeList instance && Equals(instance);
87 |
88 | public override int GetHashCode() => ((IntPtr)m_Ptr).GetHashCode();
89 |
90 | public override string ToString() => $"instance of List";
91 |
92 | public Enumerator GetEnumerator() => new Enumerator(m_Ptr);
93 |
94 | #endregion
95 |
96 | #region IEnumerable
97 |
98 | IEnumerator IEnumerable.GetEnumerator() => new Enumerator(m_Ptr);
99 |
100 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => new Enumerator(m_Ptr);
101 |
102 | #endregion
103 |
104 | public static bool operator ==(WrenNativeList left, WrenNativeList right) => left.Equals(right);
105 | public static bool operator !=(WrenNativeList left, WrenNativeList right) => !(left == right);
106 |
107 | [Serializable]
108 | public struct Enumerator : IEnumerator, System.Collections.IEnumerator
109 | {
110 | private readonly WrenInternalObjList* m_List;
111 | private WrenValue* m_Current;
112 | private int m_Index;
113 |
114 | internal Enumerator(WrenInternalObjList* buffer)
115 | {
116 | m_List = buffer;
117 | m_Index = 0;
118 | m_Current = default;
119 | }
120 |
121 | public void Dispose()
122 | {
123 | }
124 |
125 | public bool MoveNext()
126 | {
127 | if ((uint)m_Index < (uint)m_List->Elements.Count)
128 | {
129 | m_Current = &m_List->Elements.Data[m_Index];
130 | m_Index++;
131 | return true;
132 | }
133 |
134 | return MoveNextRare();
135 | }
136 |
137 | private bool MoveNextRare()
138 | {
139 | m_Index = m_List->Elements.Count + 1;
140 | m_Current = default;
141 | return false;
142 | }
143 |
144 | public WrenValue Current => *m_Current;
145 |
146 | object System.Collections.IEnumerator.Current => Current;
147 |
148 | void System.Collections.IEnumerator.Reset()
149 | {
150 | m_Index = 0;
151 | m_Current = default;
152 | }
153 | }
154 | }
155 | }
156 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/WrenNativeMap.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 |
4 | namespace WrenSharp.Unsafe
5 | {
6 | public readonly unsafe struct WrenNativeMap : IEquatable
7 | {
8 | private readonly WrenInternalObjMap* m_Ptr;
9 |
10 | #region Properties
11 |
12 | ///
13 | /// Indicates if the value has a valid underlying pointer.
14 | ///
15 | public bool IsValid => m_Ptr != null;
16 |
17 | ///
18 | /// The header for this object.
19 | ///
20 | public WrenObject Object => new WrenObject(&m_Ptr->Object);
21 |
22 | ///
23 | /// Gets the count of entries in the map.
24 | ///
25 | public int Count => (int)m_Ptr->Count;
26 |
27 | ///
28 | /// Gets the capacity of the map.
29 | ///
30 | public int Capacity => (int)m_Ptr->Capacity;
31 |
32 | #endregion
33 |
34 | internal WrenNativeMap(WrenInternalObjMap* instance)
35 | {
36 | m_Ptr = instance;
37 | }
38 |
39 | #region Object
40 |
41 | public bool Equals(WrenNativeMap other) => other.m_Ptr == m_Ptr;
42 |
43 | public override bool Equals(object obj) => obj is WrenNativeMap instance && Equals(instance);
44 |
45 | public override int GetHashCode() => ((IntPtr)m_Ptr).GetHashCode();
46 |
47 | public override string ToString() => $"instance of Map";
48 |
49 | #endregion
50 |
51 | public static bool operator ==(WrenNativeMap left, WrenNativeMap right) => left.Equals(right);
52 | public static bool operator !=(WrenNativeMap left, WrenNativeMap right) => !(left == right);
53 | }
54 | }
55 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/WrenObjType.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace WrenSharp.Unsafe
6 | {
7 | public enum WrenObjType
8 | {
9 | // No Wren equivalent
10 | Unknown = -1,
11 |
12 | // OBJ_CLASS
13 | Class,
14 |
15 | // OBJ_CLOSURE
16 | Closure,
17 |
18 | // OBJ_FIBER
19 | Fiber,
20 |
21 | // OBJ_FN
22 | Function,
23 |
24 | // OBJ_FOREIGN
25 | Foreign,
26 |
27 | // OBJ_INSTANCE
28 | Instance,
29 |
30 | // OBJ_LIST
31 | List,
32 |
33 | // OBJ_MAP
34 | Map,
35 |
36 | // OBJ_MODULE
37 | Module,
38 |
39 | // OBJ_RANGE
40 | Range,
41 |
42 | // OBJ_STRING
43 | String,
44 |
45 | // OBJ_UPVALUE
46 | Upvalue
47 | }
48 |
49 | [StructLayout(LayoutKind.Sequential)]
50 | public unsafe struct WrenObj
51 | {
52 | public WrenObjType Type;
53 | private readonly byte IsDark;
54 | public WrenObjClass* ClassObj;
55 | private readonly WrenObj* Next;
56 | }
57 |
58 | [StructLayout(LayoutKind.Sequential)]
59 | public unsafe readonly struct WrenObjClass
60 | {
61 | public readonly WrenObj Object;
62 | public readonly WrenObjClass* Superclass;
63 | public readonly int NumFields;
64 | private readonly WrenBuffer m_MethodBuffer;
65 | internal readonly WrenObjString* m_Name;
66 |
67 | // Flexible array, size is undefined
68 | internal readonly WrenValue m_AttributesValue;
69 | }
70 |
71 | [StructLayout(LayoutKind.Sequential)]
72 | internal unsafe struct WrenObjString
73 | {
74 | ///
75 | /// Converts a UTF8 Wren string to a managed string.
76 | ///
77 | /// The to convert.
78 | /// A managed string containing the contents of .
79 | public static string ToManagedString(WrenObjString* str) => System.Text.Encoding.UTF8.GetString(&str->ValueArray, str->Length);
80 |
81 | public WrenObj Obj;
82 | public int Length;
83 | public int Hash;
84 |
85 | // Flexible array, size is undefined
86 | public byte ValueArray;
87 | }
88 |
89 | [StructLayout(LayoutKind.Sequential)]
90 | internal unsafe struct WrenObjInstance
91 | {
92 | public WrenObj Obj;
93 |
94 | // Flexible array, size is undefined
95 | public WrenValue Fields;
96 | }
97 |
98 | [StructLayout(LayoutKind.Sequential)]
99 | internal unsafe struct WrenObjRange
100 | {
101 | public WrenObj Obj;
102 | public double From;
103 | public double To;
104 | [MarshalAs(UnmanagedType.U1)]
105 | public bool IsInclusive;
106 | }
107 |
108 | [StructLayout(LayoutKind.Sequential)]
109 | internal unsafe struct WrenBuffer where T : unmanaged
110 | {
111 | internal T* m_Data;
112 | internal int m_Count;
113 | internal int m_Capacity;
114 | }
115 |
116 | [StructLayout(LayoutKind.Explicit)]
117 | internal unsafe readonly partial struct WrenMethod
118 | {
119 | [FieldOffset(0)]
120 | private readonly IntPtr m_Primitive;
121 |
122 | // The rest of this must be filled out by the main project implementation,
123 | // as it differs between the standard lib and the Unity lib.
124 | }
125 | }
126 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/WrenObject.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 | using System.Runtime.CompilerServices;
4 |
5 | namespace WrenSharp.Unsafe
6 | {
7 | public readonly unsafe struct WrenObject : IEquatable
8 | {
9 | internal readonly WrenInternalObj* m_Ptr;
10 |
11 | #region Properties
12 |
13 | ///
14 | /// Indicates if the value has a valid underlying pointer.
15 | ///
16 | public bool IsValid => m_Ptr != null;
17 |
18 | ///
19 | /// The class of the object.
20 | ///
21 | public WrenClass Class => new WrenClass(m_Ptr->ClassObj);
22 |
23 | ///
24 | /// The type of the object
25 | ///
26 | public WrenObjectType Type => m_Ptr->Type;
27 |
28 | #endregion
29 |
30 | internal WrenObject(WrenInternalObj* cls)
31 | {
32 | m_Ptr = cls;
33 | }
34 |
35 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
36 | public bool IsType(WrenObjectType type) => m_Ptr->Type == type;
37 |
38 | public WrenClass AsClass() => IsType(WrenObjectType.Class) ? new WrenClass((WrenInternalObjClass*)m_Ptr) : default;
39 |
40 | public WrenInstance AsInstance() => IsType(WrenObjectType.Instance) ? new WrenInstance((WrenInternalObjInstance*)m_Ptr) : default;
41 |
42 | public WrenForeign AsForeign() => IsType(WrenObjectType.Foreign) ? new WrenForeign((WrenInternalObjForeign*)m_Ptr) : default;
43 |
44 | public T AsForeign() where T : unmanaged => IsType(WrenObjectType.Foreign) ? *(T*)((WrenInternalObjForeign*)m_Ptr)->Data : default;
45 |
46 | public T* AsForeignPtr() where T : unmanaged => IsType(WrenObjectType.Foreign) ? (T*)((WrenInternalObjForeign*)m_Ptr)->Data : default;
47 |
48 | public WrenString AsString() => IsType(WrenObjectType.String) ? new WrenString((WrenInternalObjString*)m_Ptr) : default;
49 |
50 | public WrenNativeList AsList() => IsType(WrenObjectType.List) ? new WrenNativeList((WrenInternalObjList*)m_Ptr) : default;
51 |
52 | public WrenNativeMap AsMap() => IsType(WrenObjectType.Map) ? new WrenNativeMap((WrenInternalObjMap*)m_Ptr) : default;
53 |
54 | #region Object
55 |
56 | public bool Equals(WrenObject other) => other.m_Ptr == m_Ptr;
57 |
58 | public override bool Equals(object obj) => obj is WrenObject cls && Equals(cls);
59 |
60 | public override int GetHashCode() => ((IntPtr)m_Ptr).GetHashCode();
61 |
62 | public override string ToString() => WrenString.ToManagedString(m_Ptr->ClassObj->Name);
63 |
64 | #endregion
65 |
66 | #region Operators
67 |
68 | public static bool operator ==(WrenObject left, WrenObject right) => left.Equals(right);
69 | public static bool operator !=(WrenObject left, WrenObject right) => !(left == right);
70 |
71 | public static explicit operator WrenObjectType(WrenObject obj) => obj.Type;
72 | public static explicit operator WrenClass(WrenObject obj) => obj.AsClass();
73 | public static explicit operator WrenInstance(WrenObject obj) => obj.AsInstance();
74 | public static explicit operator WrenString(WrenObject obj) => obj.AsString();
75 | public static explicit operator WrenForeign(WrenObject obj) => obj.AsForeign();
76 | public static explicit operator WrenNativeList(WrenObject obj) => obj.AsList();
77 | public static explicit operator WrenNativeMap(WrenObject obj) => obj.AsMap();
78 |
79 | #endregion
80 | }
81 | }
82 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/WrenObjectType.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | namespace WrenSharp.Unsafe
3 | {
4 | public enum WrenObjectType
5 | {
6 | // No Wren equivalent
7 | Unknown = -1,
8 |
9 | // OBJ_CLASS
10 | Class,
11 |
12 | // OBJ_CLOSURE
13 | Closure,
14 |
15 | // OBJ_FIBER
16 | Fiber,
17 |
18 | // OBJ_FN
19 | Function,
20 |
21 | // OBJ_FOREIGN
22 | Foreign,
23 |
24 | // OBJ_INSTANCE
25 | Instance,
26 |
27 | // OBJ_LIST
28 | List,
29 |
30 | // OBJ_MAP
31 | Map,
32 |
33 | // OBJ_MODULE
34 | Module,
35 |
36 | // OBJ_RANGE
37 | Range,
38 |
39 | // OBJ_STRING
40 | String,
41 |
42 | // OBJ_UPVALUE
43 | Upvalue
44 | }
45 | }
46 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/Unsafe/WrenString.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 |
4 | namespace WrenSharp.Unsafe
5 | {
6 | ///
7 | /// A managed wrapper for a Wren string object.
8 | ///
9 | public readonly unsafe struct WrenString : IEquatable
10 | {
11 | ///
12 | /// Converts a UTF8 Wren string to a managed string.
13 | ///
14 | /// The to convert.
15 | /// A managed string containing the contents of .
16 | internal static string ToManagedString(WrenInternalObjString* str) => System.Text.Encoding.UTF8.GetString(&str->ValueArray, str->Length);
17 |
18 | private readonly WrenInternalObjString* m_Ptr;
19 |
20 | #region Properties
21 |
22 | ///
23 | /// Indicates if the value has a valid underlying pointer.
24 | ///
25 | public bool IsValid => m_Ptr != null;
26 |
27 | ///
28 | /// The header for this object.
29 | ///
30 | public WrenObject Object => new WrenObject(&m_Ptr->Object);
31 |
32 | ///
33 | /// The number of code points in the string. Wren strings are UTF8 encoded.
34 | ///
35 | public int Length => m_Ptr->Length;
36 |
37 | ///
38 | /// The hash of the string.
39 | ///
40 | public int Hash => m_Ptr->Hash;
41 |
42 | ///
43 | /// The pointer to the contents of the string.
44 | ///
45 | public byte* ValuePtr => &m_Ptr->ValueArray;
46 |
47 | ///
48 | /// A span containing the the code points of the string.
49 | ///
50 | public ReadOnlySpan ValueSpan => new ReadOnlySpan(&m_Ptr->ValueArray, m_Ptr->Length);
51 |
52 | #endregion
53 |
54 | internal WrenString(WrenInternalObjString* stringObj)
55 | {
56 | m_Ptr = stringObj;
57 | }
58 |
59 | public bool Equals(WrenString other)
60 | {
61 | if (other.m_Ptr == m_Ptr)
62 | return true;
63 |
64 | return other.m_Ptr->Hash == m_Ptr->Hash &&
65 | other.m_Ptr->Length == m_Ptr->Length &&
66 | UnsafeUtils.Memeq(&other.m_Ptr->ValueArray, &m_Ptr->ValueArray, m_Ptr->Length);
67 | }
68 |
69 | public override bool Equals(object obj) => obj is WrenString other && Equals(other);
70 |
71 | public override int GetHashCode() => ((IntPtr)m_Ptr).GetHashCode();
72 |
73 | public override string ToString() => ToManagedString(m_Ptr);
74 | }
75 | }
76 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/WrenErrorType.cs:
--------------------------------------------------------------------------------
1 | namespace WrenSharp
2 | {
3 | ///
4 | /// Represents error types that can be returned from Wren. These map directly to the
5 | /// values that Wren can return.
6 | ///
7 | public enum WrenErrorType
8 | {
9 | ///
10 | /// Represents a compile error while interpreting Wren source.
11 | /// C value: WREN_ERROR_COMPILE
12 | ///
13 | Compile,
14 |
15 | ///
16 | /// Represents a runtime error while executing Wren bytecode.
17 | /// C value: WREN_ERROR_RUNTIME
18 | ///
19 | Runtime,
20 |
21 | ///
22 | /// Represents a stack trace line from an error.
23 | /// C value: WREN_ERROR_STACK_TRACE
24 | ///
25 | StackTrace,
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/WrenInterpretResult.cs:
--------------------------------------------------------------------------------
1 | namespace WrenSharp
2 | {
3 | ///
4 | /// Return values from Wren VM interpret or method calls.
5 | ///
6 | public enum WrenInterpretResult
7 | {
8 | ///
9 | /// A successful result.
10 | /// C value: WREN_RESULT_SUCCESS
11 | ///
12 | Success,
13 |
14 | ///
15 | /// A compile error result.
16 | /// C value: WREN_RESULT_COMPILE_ERROR
17 | ///
18 | CompileError,
19 |
20 | ///
21 | /// A runtime error result.
22 | /// C value: WREN_RESULT_RUNTIME_ERROR
23 | ///
24 | RuntimeError,
25 | }
26 |
27 | public static class WrenInterpretResultExtensions
28 | {
29 | ///
30 | /// Indicates if is equal to .
31 | ///
32 | /// The result to check.
33 | /// True if is a success, otherwise false.
34 | public static bool IsSuccess(this WrenInterpretResult result) => result == WrenInterpretResult.Success;
35 |
36 | ///
37 | /// Indicates if is not equal to .
38 | ///
39 | /// The result to check.
40 | /// True if is not a success, otherwise false.
41 | public static bool IsFailure(this WrenInterpretResult result) => result != WrenInterpretResult.Success;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/WrenNativeTypes.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace WrenSharp.Native
5 | {
6 | public partial class WrenNativeFn
7 | {
8 | #region Delegate Declarations
9 |
10 | // Memory
11 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
12 | public delegate IntPtr Reallocate(IntPtr memory, ulong newSize, IntPtr userData);
13 |
14 | // Modules
15 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
16 | public delegate WrenLoadModuleResult LoadModule(IntPtr vm, string name);
17 |
18 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
19 | public delegate void LoadModuleComplete(IntPtr vm, string name, WrenLoadModuleResult result);
20 |
21 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
22 | public delegate string ResolveModule(IntPtr vm, string importer, string name);
23 |
24 | // Writers
25 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
26 | public delegate void Write(IntPtr vm, string text);
27 |
28 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
29 | public delegate void Error(IntPtr vm, WrenErrorType errorType, string module, int line, string message);
30 |
31 | // Foreign
32 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
33 | public delegate WrenForeignClassMethods BindForeignClass(IntPtr vm, string module, string className);
34 |
35 |
36 | #endregion
37 | }
38 |
39 | ///
40 | /// Represents the native WrenConfiguration struct that is passed to Wren when creating new VM.
41 | /// C type: struct WrenConfiguration
42 | ///
43 | [StructLayout(LayoutKind.Sequential, Size = 88)]
44 | public struct WrenConfiguration
45 | {
46 | ///
47 | /// Creates a new, initialized . This method creates a new configuration,
48 | /// calls on it and returns the initialized value.
49 | ///
50 | /// An initialized .
51 | public static WrenConfiguration InitializeNew()
52 | {
53 | var config = new WrenConfiguration();
54 | Wren.InitConfiguration(ref config);
55 | return config;
56 | }
57 |
58 | // This struct is passed directly into Wren native functions,
59 | // so the layout must match the native C WrenConfiguration type.
60 |
61 | public WrenNativeFn.Reallocate Reallocate;
62 | public WrenNativeFn.ResolveModule ResolveModule;
63 | public WrenNativeFn.LoadModule LoadModule;
64 | public WrenNativeFn.BindForeignMethod BindForeignMethod;
65 | public WrenNativeFn.BindForeignClass BindForeignClass;
66 | public WrenNativeFn.Write Write;
67 | public WrenNativeFn.Error Error;
68 | public ulong InitialHeapSize;
69 | public ulong MinHeapSize;
70 | public int HeapGrowthPercent;
71 | public IntPtr UserData;
72 |
73 | ///
74 | /// Indicates if the configuration has been initialized.
75 | ///
76 | public readonly bool IsInitialized => Reallocate != null && InitialHeapSize > 0;
77 | }
78 |
79 | ///
80 | /// Represents the native WrenLoadModuleResult struct that is sent to Wren when a module load request is made.
81 | /// C type: struct WrenLoadModuleResult
82 | ///
83 | [StructLayout(LayoutKind.Sequential, Size = 24)]
84 | public struct WrenLoadModuleResult
85 | {
86 | ///
87 | /// Gets a representing a failed load with no callback or user data attached.
88 | ///
89 | public static WrenLoadModuleResult Failed => new WrenLoadModuleResult
90 | {
91 | Source = IntPtr.Zero,
92 | UserData = IntPtr.Zero,
93 | #if WRENSHARP_UNITY
94 | OnCompleteCallback = IntPtr.Zero,
95 | #else
96 | OnCompleteCallback = null,
97 | #endif
98 | };
99 |
100 | // This struct is passed directly into Wren native functions,
101 | // so the layout must match the native C WrenConfiguration type.
102 |
103 | ///
104 | /// Pointer to the string of Wren source that will be interpreted for the module.
105 | /// A value of should be used if the module was not found.
106 | ///
107 | public IntPtr Source;
108 |
109 | ///
110 | /// Function pointer to a delegate.
111 | ///
112 | #if WRENSHARP_UNITY
113 | // Unity IL2CPP fails to marshal the WrenNativeFn.LoadModuleComplete via p/invoke automatically.
114 | // Using an IntPtr and marshalling it manually as the correct type seems to work around this problem.
115 | // Possibly because one of its arguments is a struct of this type (WrenLoadModuleResult)?
116 | public IntPtr OnCompleteCallback;
117 | #else
118 | public WrenNativeFn.LoadModuleComplete OnCompleteCallback;
119 | #endif
120 |
121 | ///
122 | /// Pointer to user data
123 | ///
124 | public IntPtr UserData;
125 | }
126 |
127 | #if WRENSHARP_EXT
128 | [StructLayout(LayoutKind.Sequential, Size = 16)]
129 | public readonly struct WrenFiberResume
130 | {
131 | private readonly IntPtr m_Fiber;
132 | private readonly IntPtr m_ApiStack;
133 |
134 | ///
135 | /// Indicates if the value represents a value resume token.
136 | ///
137 | public bool IsValid => m_Fiber != IntPtr.Zero;
138 | }
139 | #endif
140 | }
141 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/WrenSharp.Lib.Shared.projitems:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 | true
6 | 18977aba-f8c7-4a53-a95b-9c181286f462
7 |
8 |
9 | WrenSharp.Internal
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/WrenSharp.Lib.Shared.shproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 18977aba-f8c7-4a53-a95b-9c181286f462
5 | 14.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.Shared/WrenType.cs:
--------------------------------------------------------------------------------
1 | namespace WrenSharp
2 | {
3 | ///
4 | /// Represents Wren data types, used for indicating the type of a value in a variable or slot.
5 | ///
6 | public enum WrenType
7 | {
8 | ///
9 | /// A boolean value.
10 | /// C value: WREN_TYPE_BOOL
11 | ///
12 | Bool,
13 |
14 | ///
15 | /// A number value.
16 | /// C value: WREN_TYPE_NUM
17 | ///
18 | Number,
19 |
20 | ///
21 | /// A foreign value.
22 | /// C value: WREN_TYPE_FOREIGN
23 | ///
24 | Foreign,
25 |
26 | ///
27 | /// A list value.
28 | /// C value: WREN_TYPE_LIST
29 | ///
30 | List,
31 |
32 | ///
33 | /// A map value.
34 | /// C value: WREN_TYPE_MAP
35 | ///
36 | Map,
37 |
38 | ///
39 | /// A null value.
40 | /// C value: WREN_TYPE_NULL
41 | ///
42 | Null,
43 |
44 | ///
45 | /// A string value.
46 | /// C value: WREN_TYPE_STRING
47 | ///
48 | String,
49 |
50 | ///
51 | /// A unknown value. Receiving this type indicates an error.
52 | /// C value: WREN_TYPE_UNKNOWN
53 | ///
54 | Unknown
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.Unity/Unsafe/WrenMethod.cs:
--------------------------------------------------------------------------------
1 | #if WRENSHARP_EXT
2 | using System;
3 | using System.Runtime.InteropServices;
4 | using WrenSharp.Native;
5 |
6 | namespace WrenSharp.Unsafe
7 | {
8 | internal unsafe partial struct WrenInternalMethod
9 | {
10 | [FieldOffset(8)]
11 | private fixed byte methods[WrenForeignMethodData.Size];
12 |
13 | [FieldOffset(8 + WrenForeignMethodData.Size)]
14 | private readonly IntPtr m_Closure;
15 | }
16 | }
17 | #endif
--------------------------------------------------------------------------------
/WrenSharp.Lib.Unity/Wren.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace WrenSharp.Native
5 | {
6 | public partial class Wren
7 | {
8 | #if WRENSHARP_UNITY_INTERNAL
9 | public const string NativeLibrary = "__Internal";
10 | #else
11 | public const string NativeLibrary = "wren_unity";
12 | #endif
13 | }
14 |
15 | public partial class WrenNativeFn
16 | {
17 | // Foriegn
18 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
19 | public delegate WrenForeignMethodData BindForeignMethod(IntPtr vm, string module, string className, byte isStatic, string signature);
20 |
21 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
22 | public delegate void ForeignMethod(IntPtr vm, ushort symbol);
23 |
24 | [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
25 | public delegate void Finalizer(IntPtr data, ushort symbol);
26 | }
27 |
28 | ///
29 | /// Represents the native WrenForeignClassMethods struct that provides allocate and finalize
30 | /// function pointers for a Wren foreign class instantiation.
31 | /// C type: struct WrenForeignClassMethods
32 | ///
33 | [StructLayout(LayoutKind.Sequential, Size = WrenForeignClassMethods.Size)]
34 | public struct WrenForeignClassMethods
35 | {
36 | ///
37 | /// The size of the struct type, in bytes.
38 | ///
39 | public const int Size = 32;
40 |
41 | // This struct is passed directly into Wren native functions,
42 | // so the layout must match the native C WrenConfiguration type.
43 |
44 | public WrenNativeFn.ForeignMethod Allocate;
45 | public ushort AllocateSymbol;
46 |
47 | public WrenNativeFn.Finalizer Finalize;
48 | public ushort FinalizeSymbol;
49 | }
50 |
51 | ///
52 | /// Represents the native WrenFindForeignMethodResult struct that provides a function pointer for a foreign method
53 | /// in a Wren class.
54 | /// C type: struct WrenFindForeignMethodResult
55 | ///
56 | [StructLayout(LayoutKind.Sequential, Size = WrenForeignMethodData.Size)]
57 | public unsafe struct WrenForeignMethodData
58 | {
59 | ///
60 | /// The size of the struct type, in bytes.
61 | ///
62 | public const int Size = 16;
63 |
64 | ///
65 | /// A representing a method that could not be found.
66 | ///
67 | public static WrenForeignMethodData NotFound => new WrenForeignMethodData() { Function = null, Symbol = 0 };
68 |
69 | // This struct is passed directly into Wren native functions,
70 | // so the layout must match the native C WrenConfiguration type.
71 |
72 | public WrenNativeFn.ForeignMethod Function;
73 | public ushort Symbol;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.Unity/WrenSharp.Lib.Unity.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.1
5 | disable
6 | True
7 | Debug;Release;Unity_Internal
8 |
9 |
10 |
11 | $(DefineConstants);WRENSHARP_UNITY;WRENSHARP_EXT
12 |
13 |
14 |
15 | $(DefineConstants);WRENSHARP_UNITY;WRENSHARP_EXT
16 |
17 |
18 |
19 | $(DefineConstants);WRENSHARP_UNITY;WRENSHARP_UNITY_INTERNAL;WRENSHARP_EXT
20 | True
21 |
22 |
23 |
24 |
25 | Always
26 |
27 |
28 | Always
29 |
30 |
31 | Always
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/WrenSharp.Lib.Unity/wren_unity.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevewoolcock/WrenSharp/6b44a219a1dfb0bca559480532e97645e879ff8b/WrenSharp.Lib.Unity/wren_unity.dll
--------------------------------------------------------------------------------
/WrenSharp.Lib.Unity/wren_unity.exp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevewoolcock/WrenSharp/6b44a219a1dfb0bca559480532e97645e879ff8b/WrenSharp.Lib.Unity/wren_unity.exp
--------------------------------------------------------------------------------
/WrenSharp.Tests/SharedDataTests.cs:
--------------------------------------------------------------------------------
1 | namespace WrenSharp.Tests
2 | {
3 | public class WrenSharedDataTests
4 | {
5 | [Fact]
6 | public void Add_Contains_Pass()
7 | {
8 | var table = new WrenSharedDataTable();
9 | var handle = table.Add("hello world");
10 | Assert.True(table.Contains(handle));
11 | }
12 |
13 | [Fact]
14 | public void Contains_Fail()
15 | {
16 | var table = new WrenSharedDataTable();
17 | var handle = table.Add("hello world");
18 | Assert.False(table.Contains(handle + 1));
19 | }
20 |
21 | [Fact]
22 | public void Remove_Pass()
23 | {
24 | var table = new WrenSharedDataTable();
25 | var handle = table.Add("hello world");
26 | table.Remove(handle);
27 | Assert.False(table.Contains(handle));
28 | }
29 |
30 | [Fact]
31 | public void Clear_Pass()
32 | {
33 | var table = new WrenSharedDataTable();
34 | var handle1 = table.Add("hello world");
35 | var handle2 = table.Add("foobar");
36 |
37 | table.Clear();
38 |
39 | Assert.Equal(0, table.Count);
40 | Assert.False(table.Contains(handle1));
41 | Assert.False(table.Contains(handle2));
42 | }
43 |
44 | [Fact]
45 | public void Add_Remove_SingleHandle_EnsureHandleReuse()
46 | {
47 | var table = new WrenSharedDataTable();
48 | var handle1 = table.Add("hello world");
49 | table.Remove(handle1);
50 |
51 | var handle2 = table.Add("foobar");
52 |
53 | Assert.Equal(handle1, handle2);
54 | }
55 |
56 | [Fact]
57 | public void Add_Remove_MultipleHandles_EnsureHandleReuse()
58 | {
59 | var table = new WrenSharedDataTable();
60 |
61 | var handle1 = table.Add("hello world");
62 | var handle2 = table.Add("foobar");
63 | var handle3 = table.Add("quick brown fox");
64 |
65 | table.Remove(handle2);
66 | table.Remove(handle1);
67 |
68 | var handle4 = table.Add("jumps over");
69 | var handle5 = table.Add("the lazy dog");
70 |
71 | // Last handle release should be reused
72 | Assert.Equal(handle4, handle1);
73 | Assert.Equal(handle5, handle2);
74 |
75 | table.Remove(handle3);
76 |
77 | var handle6 = table.Add("lorem ipsum dolor");
78 | Assert.Equal(handle6, handle3);
79 | }
80 |
81 | [Fact]
82 | public void Get_ValidHandle_Pass()
83 | {
84 | var table = new WrenSharedDataTable();
85 | var value = "hello world";
86 | var handle = table.Add(value);
87 | var retrievedValue = table.Get(handle);
88 | Assert.Equal(value, retrievedValue);
89 | }
90 |
91 | [Fact]
92 | public void Get_FreedHandle_ThrowInvalidHandleException()
93 | {
94 | var table = new WrenSharedDataTable();
95 | var value = "hello world";
96 | var handle = table.Add(value);
97 |
98 | // Remove the handle
99 | table.Remove(handle);
100 |
101 | // Attempt to get the value with the now invalid handle
102 | // This should throw an invalid handle exception
103 | Assert.Throws(() => table.Get(handle));
104 | }
105 |
106 | [Fact]
107 | public void Get_InvalidHandle_ThrowInvalidHandleException()
108 | {
109 | var table = new WrenSharedDataTable();
110 | table.Add("hello world");
111 |
112 | Assert.Throws(() => table.Get(WrenSharedDataHandle.Invalid));
113 | }
114 |
115 | [Fact]
116 | public void Set_ValidHandle_Pass()
117 | {
118 | var table = new WrenSharedDataTable();
119 | var value = "hello world";
120 | var handle = table.Add(value);
121 |
122 | // Change the value at the handle's address
123 | table.Set(handle, "foobar");
124 |
125 | Assert.Equal("foobar", (string)table.Get(handle));
126 | }
127 |
128 | [Fact]
129 | public void Set_InvalidHandle_ThrowInvalidHandleException()
130 | {
131 | var table = new WrenSharedDataTable();
132 | var handle = (WrenSharedDataHandle)10;
133 | Assert.Throws(() => table.Set(handle, "foobar"));
134 | }
135 |
136 | [Fact]
137 | public void Set_FreedHandle_ThrowInvalidHandleException()
138 | {
139 | var table = new WrenSharedDataTable();
140 | var handle = table.Add("hello world");
141 | table.Remove(handle);
142 |
143 | Assert.Throws(() => table.Set(handle, "foobar"));
144 | }
145 | }
146 | }
--------------------------------------------------------------------------------
/WrenSharp.Tests/Usings.cs:
--------------------------------------------------------------------------------
1 | global using Xunit;
--------------------------------------------------------------------------------
/WrenSharp.Tests/WrenSharp.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 | enable
7 |
8 | false
9 |
10 | True
11 |
12 |
13 |
14 |
15 |
16 |
17 | runtime; build; native; contentfiles; analyzers; buildtransitive
18 | all
19 |
20 |
21 | runtime; build; native; contentfiles; analyzers; buildtransitive
22 | all
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/.gitignore:
--------------------------------------------------------------------------------
1 | # This .gitignore file should be placed at the root of your Unity project directory
2 | #
3 | # Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
4 | #
5 | /[Ll]ibrary/
6 | /[Tt]emp/
7 | /[Oo]bj/
8 | /[Bb]uild/
9 | /[Bb]uilds/
10 | /[Ll]ogs/
11 | /[Uu]ser[Ss]ettings/
12 |
13 | # Keep local packages
14 | !/[Pp]ackages/**
15 |
16 | # MemoryCaptures can get excessive in size.
17 | # They also could contain extremely sensitive data
18 | /[Mm]emoryCaptures/
19 |
20 | # Recordings can get excessive in size
21 | /[Rr]ecordings/
22 |
23 | # Uncomment this line if you wish to ignore the asset store tools plugin
24 | # /[Aa]ssets/AssetStoreTools*
25 |
26 | # Autogenerated Jetbrains Rider plugin
27 | /[Aa]ssets/Plugins/Editor/JetBrains*
28 |
29 | # Visual Studio cache directory
30 | .vs/
31 |
32 | # Gradle cache directory
33 | .gradle/
34 |
35 | # Autogenerated VS/MD/Consulo solution and project files
36 | ExportedObj/
37 | .consulo/
38 | *.csproj
39 | *.unityproj
40 | *.sln
41 | *.suo
42 | *.tmp
43 | *.user
44 | *.userprefs
45 | *.pidb
46 | *.booproj
47 | *.svd
48 | *.pdb
49 | *.mdb
50 | *.opendb
51 | *.VC.db
52 |
53 | # Unity3D generated meta files
54 | *.pidb.meta
55 | *.pdb.meta
56 | *.mdb.meta
57 |
58 | # Unity3D generated file on crash reports
59 | sysinfo.txt
60 |
61 | # Builds
62 | *.apk
63 | *.aab
64 | *.unitypackage
65 | *.app
66 |
67 | # Crashlytics generated file
68 | crashlytics-build.properties
69 |
70 | # Packed Addressables
71 | /[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
72 |
73 | # Temporary auto-generated Android Assets
74 | /[Aa]ssets/[Ss]treamingAssets/aa.meta
75 | /[Aa]ssets/[Ss]treamingAssets/aa/*
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/.vsconfig:
--------------------------------------------------------------------------------
1 | {
2 | "version": "1.0",
3 | "components": [
4 | "Microsoft.VisualStudio.Workload.ManagedGame"
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Assets/FiraCode-Medium.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevewoolcock/WrenSharp/6b44a219a1dfb0bca559480532e97645e879ff8b/WrenSharp.Unity.Project/Assets/FiraCode-Medium.ttf
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Assemblies.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 88ce335372bb97c4ca53e20dbe1fe746
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Assemblies/WrenSharp.Unity.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevewoolcock/WrenSharp/6b44a219a1dfb0bca559480532e97645e879ff8b/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Assemblies/WrenSharp.Unity.dll
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Assemblies/WrenSharp.Unity.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 77e60f088dc4c3d40b63cabbe621e2b2
3 | PluginImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | iconMap: {}
7 | executionOrder: {}
8 | defineConstraints: []
9 | isPreloaded: 0
10 | isOverridable: 1
11 | isExplicitlyReferenced: 0
12 | validateReferences: 1
13 | platformData:
14 | - first:
15 | : Any
16 | second:
17 | enabled: 0
18 | settings:
19 | Exclude Editor: 0
20 | Exclude Linux64: 0
21 | Exclude OSXUniversal: 0
22 | Exclude Switch: 0
23 | Exclude Win: 0
24 | Exclude Win64: 0
25 | - first:
26 | Any:
27 | second:
28 | enabled: 1
29 | settings: {}
30 | - first:
31 | Editor: Editor
32 | second:
33 | enabled: 1
34 | settings:
35 | CPU: AnyCPU
36 | DefaultValueInitialized: true
37 | OS: AnyOS
38 | - first:
39 | Nintendo Switch: Switch
40 | second:
41 | enabled: 1
42 | settings: {}
43 | - first:
44 | Standalone: Linux64
45 | second:
46 | enabled: 1
47 | settings:
48 | CPU: AnyCPU
49 | - first:
50 | Standalone: OSXUniversal
51 | second:
52 | enabled: 1
53 | settings:
54 | CPU: None
55 | - first:
56 | Standalone: Win
57 | second:
58 | enabled: 1
59 | settings:
60 | CPU: x86
61 | - first:
62 | Standalone: Win64
63 | second:
64 | enabled: 1
65 | settings:
66 | CPU: x86_64
67 | - first:
68 | Windows Store Apps: WindowsStoreApps
69 | second:
70 | enabled: 0
71 | settings:
72 | CPU: AnyCPU
73 | userData:
74 | assetBundleName:
75 | assetBundleVariant:
76 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Assemblies/WrenSharp.Unity.xml.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c5e816de2fdd21b46870c7be8d9a39ca
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: af5746f470688864aa8c9e4a6aae99e4
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e941a9031e2e70946b43b4bf1c785f3c
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren/Internal.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5c657b2cbd6753043868a4e26c61a07f
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren/Internal/netstandard2.1.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 11b0673df0bdeef43bcca13ea0e8b754
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren/Internal/netstandard2.1/WrenSharp.Lib.Unity.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevewoolcock/WrenSharp/6b44a219a1dfb0bca559480532e97645e879ff8b/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren/Internal/netstandard2.1/WrenSharp.Lib.Unity.dll
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren/Internal/netstandard2.1/WrenSharp.Lib.Unity.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 95a9214219256444c9414051039d4186
3 | PluginImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | iconMap: {}
7 | executionOrder: {}
8 | defineConstraints: []
9 | isPreloaded: 0
10 | isOverridable: 1
11 | isExplicitlyReferenced: 0
12 | validateReferences: 1
13 | platformData:
14 | - first:
15 | : Any
16 | second:
17 | enabled: 0
18 | settings:
19 | Exclude Editor: 1
20 | Exclude Linux64: 1
21 | Exclude OSXUniversal: 1
22 | Exclude Switch: 0
23 | Exclude Win: 1
24 | Exclude Win64: 1
25 | - first:
26 | Any:
27 | second:
28 | enabled: 1
29 | settings: {}
30 | - first:
31 | Editor: Editor
32 | second:
33 | enabled: 0
34 | settings:
35 | CPU: AnyCPU
36 | DefaultValueInitialized: true
37 | OS: AnyOS
38 | - first:
39 | Nintendo Switch: Switch
40 | second:
41 | enabled: 1
42 | settings: {}
43 | - first:
44 | Standalone: Linux64
45 | second:
46 | enabled: 0
47 | settings:
48 | CPU: None
49 | - first:
50 | Standalone: OSXUniversal
51 | second:
52 | enabled: 0
53 | settings:
54 | CPU: None
55 | - first:
56 | Standalone: Win
57 | second:
58 | enabled: 0
59 | settings:
60 | CPU: None
61 | - first:
62 | Standalone: Win64
63 | second:
64 | enabled: 0
65 | settings:
66 | CPU: None
67 | - first:
68 | Windows Store Apps: WindowsStoreApps
69 | second:
70 | enabled: 0
71 | settings:
72 | CPU: AnyCPU
73 | userData:
74 | assetBundleName:
75 | assetBundleVariant:
76 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren/netstandard2.1.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 82e854b4c05b85e44bdcc2f3af17ee07
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren/netstandard2.1/WrenSharp.Lib.Unity.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevewoolcock/WrenSharp/6b44a219a1dfb0bca559480532e97645e879ff8b/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren/netstandard2.1/WrenSharp.Lib.Unity.dll
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren/netstandard2.1/WrenSharp.Lib.Unity.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c7588b5378ad0ab46beb5247ceef6b81
3 | PluginImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | iconMap: {}
7 | executionOrder: {}
8 | defineConstraints: []
9 | isPreloaded: 0
10 | isOverridable: 1
11 | isExplicitlyReferenced: 0
12 | validateReferences: 1
13 | platformData:
14 | - first:
15 | : Any
16 | second:
17 | enabled: 0
18 | settings:
19 | Exclude Editor: 0
20 | Exclude Linux64: 0
21 | Exclude OSXUniversal: 0
22 | Exclude Switch: 1
23 | Exclude Win: 0
24 | Exclude Win64: 0
25 | - first:
26 | Any:
27 | second:
28 | enabled: 0
29 | settings: {}
30 | - first:
31 | Editor: Editor
32 | second:
33 | enabled: 1
34 | settings:
35 | CPU: AnyCPU
36 | DefaultValueInitialized: true
37 | OS: AnyOS
38 | - first:
39 | Standalone: Linux64
40 | second:
41 | enabled: 1
42 | settings:
43 | CPU: AnyCPU
44 | - first:
45 | Standalone: OSXUniversal
46 | second:
47 | enabled: 1
48 | settings:
49 | CPU: None
50 | - first:
51 | Standalone: Win
52 | second:
53 | enabled: 1
54 | settings:
55 | CPU: None
56 | - first:
57 | Standalone: Win64
58 | second:
59 | enabled: 1
60 | settings:
61 | CPU: x86_64
62 | - first:
63 | Windows Store Apps: WindowsStoreApps
64 | second:
65 | enabled: 0
66 | settings:
67 | CPU: AnyCPU
68 | userData:
69 | assetBundleName:
70 | assetBundleVariant:
71 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren/wren_unity.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stevewoolcock/WrenSharp/6b44a219a1dfb0bca559480532e97645e879ff8b/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren/wren_unity.dll
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/Plugins/Wren/wren_unity.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b147cd396ab8fe943a1923e48c090f89
3 | PluginImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | iconMap: {}
7 | executionOrder: {}
8 | defineConstraints: []
9 | isPreloaded: 0
10 | isOverridable: 1
11 | isExplicitlyReferenced: 0
12 | validateReferences: 1
13 | platformData:
14 | - first:
15 | : Any
16 | second:
17 | enabled: 0
18 | settings:
19 | Exclude Editor: 0
20 | Exclude Linux64: 0
21 | Exclude OSXUniversal: 0
22 | Exclude Switch: 1
23 | Exclude Win: 0
24 | Exclude Win64: 0
25 | - first:
26 | Any:
27 | second:
28 | enabled: 0
29 | settings: {}
30 | - first:
31 | Editor: Editor
32 | second:
33 | enabled: 1
34 | settings:
35 | CPU: AnyCPU
36 | DefaultValueInitialized: true
37 | OS: Windows
38 | - first:
39 | Standalone: Linux64
40 | second:
41 | enabled: 1
42 | settings:
43 | CPU: AnyCPU
44 | - first:
45 | Standalone: OSXUniversal
46 | second:
47 | enabled: 1
48 | settings:
49 | CPU: None
50 | - first:
51 | Standalone: Win
52 | second:
53 | enabled: 1
54 | settings:
55 | CPU: x86
56 | - first:
57 | Standalone: Win64
58 | second:
59 | enabled: 1
60 | settings:
61 | CPU: x86_64
62 | userData:
63 | assetBundleName:
64 | assetBundleVariant:
65 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.deadreckoned.wrensharp",
3 | "version": "0.7.8",
4 | "displayName": "WrenSharp",
5 | "description": "A Unity wrapper for the Wren scripting language, compatible with both Mono and IL2CPP.",
6 | "unity": "2019.1",
7 | "documentationUrl": "https://github.com/stevewoolcock/WrenSharp/blob/main/README.md",
8 | "keywords": [
9 | "scripting",
10 | "utility",
11 | "wren"
12 | ],
13 | "author": {
14 | "name": "Dead Reckoned",
15 | "email": "info@deadreckoned.com",
16 | "url": "https://www.deadreckoned.com"
17 | }
18 | }
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp/package.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fa938b1d70c13bd4e8e19be82881367d
3 | PackageManifestImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/Packages/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "com.unity.ai.navigation": "1.1.1",
4 | "com.unity.collab-proxy": "2.0.3",
5 | "com.unity.feature.development": "1.0.1",
6 | "com.unity.ide.rider": "3.0.18",
7 | "com.unity.ide.visualstudio": "2.0.17",
8 | "com.unity.ide.vscode": "1.2.5",
9 | "com.unity.test-framework": "1.1.33",
10 | "com.unity.textmeshpro": "3.0.6",
11 | "com.unity.timeline": "1.7.4",
12 | "com.unity.ugui": "1.0.0",
13 | "com.unity.visualscripting": "1.8.0",
14 | "com.unity.modules.ai": "1.0.0",
15 | "com.unity.modules.androidjni": "1.0.0",
16 | "com.unity.modules.animation": "1.0.0",
17 | "com.unity.modules.assetbundle": "1.0.0",
18 | "com.unity.modules.audio": "1.0.0",
19 | "com.unity.modules.cloth": "1.0.0",
20 | "com.unity.modules.director": "1.0.0",
21 | "com.unity.modules.imageconversion": "1.0.0",
22 | "com.unity.modules.imgui": "1.0.0",
23 | "com.unity.modules.jsonserialize": "1.0.0",
24 | "com.unity.modules.particlesystem": "1.0.0",
25 | "com.unity.modules.physics": "1.0.0",
26 | "com.unity.modules.physics2d": "1.0.0",
27 | "com.unity.modules.screencapture": "1.0.0",
28 | "com.unity.modules.terrain": "1.0.0",
29 | "com.unity.modules.terrainphysics": "1.0.0",
30 | "com.unity.modules.tilemap": "1.0.0",
31 | "com.unity.modules.ui": "1.0.0",
32 | "com.unity.modules.uielements": "1.0.0",
33 | "com.unity.modules.umbra": "1.0.0",
34 | "com.unity.modules.unityanalytics": "1.0.0",
35 | "com.unity.modules.unitywebrequest": "1.0.0",
36 | "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
37 | "com.unity.modules.unitywebrequestaudio": "1.0.0",
38 | "com.unity.modules.unitywebrequesttexture": "1.0.0",
39 | "com.unity.modules.unitywebrequestwww": "1.0.0",
40 | "com.unity.modules.vehicles": "1.0.0",
41 | "com.unity.modules.video": "1.0.0",
42 | "com.unity.modules.vr": "1.0.0",
43 | "com.unity.modules.wind": "1.0.0",
44 | "com.unity.modules.xr": "1.0.0"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!11 &1
4 | AudioManager:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | m_Volume: 1
8 | Rolloff Scale: 1
9 | Doppler Factor: 1
10 | Default Speaker Mode: 2
11 | m_SampleRate: 0
12 | m_DSPBufferSize: 1024
13 | m_VirtualVoiceCount: 512
14 | m_RealVoiceCount: 32
15 | m_SpatializerPlugin:
16 | m_AmbisonicDecoderPlugin:
17 | m_DisableAudio: 0
18 | m_VirtualizeEffects: 1
19 | m_RequestedDSPBufferSize: 1024
20 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/ClusterInputManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!236 &1
4 | ClusterInputManager:
5 | m_ObjectHideFlags: 0
6 | m_Inputs: []
7 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!55 &1
4 | PhysicsManager:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 11
7 | m_Gravity: {x: 0, y: -9.81, z: 0}
8 | m_DefaultMaterial: {fileID: 0}
9 | m_BounceThreshold: 2
10 | m_SleepThreshold: 0.005
11 | m_DefaultContactOffset: 0.01
12 | m_DefaultSolverIterations: 6
13 | m_DefaultSolverVelocityIterations: 1
14 | m_QueriesHitBackfaces: 0
15 | m_QueriesHitTriggers: 1
16 | m_EnableAdaptiveForce: 0
17 | m_ClothInterCollisionDistance: 0
18 | m_ClothInterCollisionStiffness: 0
19 | m_ContactsGeneration: 1
20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
21 | m_AutoSimulation: 1
22 | m_AutoSyncTransforms: 0
23 | m_ReuseCollisionCallbacks: 1
24 | m_ClothInterCollisionSettingsToggle: 0
25 | m_ContactPairsMode: 0
26 | m_BroadphaseType: 0
27 | m_WorldBounds:
28 | m_Center: {x: 0, y: 0, z: 0}
29 | m_Extent: {x: 250, y: 250, z: 250}
30 | m_WorldSubdivisions: 8
31 | m_FrictionType: 0
32 | m_EnableEnhancedDeterminism: 0
33 | m_EnableUnifiedHeightmaps: 1
34 | m_DefaultMaxAngluarSpeed: 7
35 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1045 &1
4 | EditorBuildSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | m_Scenes: []
8 | m_configObjects: {}
9 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!159 &1
4 | EditorSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 11
7 | m_ExternalVersionControlSupport: Visible Meta Files
8 | m_SerializationMode: 2
9 | m_LineEndingsForNewScripts: 0
10 | m_DefaultBehaviorMode: 0
11 | m_PrefabRegularEnvironment: {fileID: 0}
12 | m_PrefabUIEnvironment: {fileID: 0}
13 | m_SpritePackerMode: 0
14 | m_SpritePackerPaddingPower: 1
15 | m_EtcTextureCompressorBehavior: 1
16 | m_EtcTextureFastCompressor: 1
17 | m_EtcTextureNormalCompressor: 2
18 | m_EtcTextureBestCompressor: 4
19 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;rsp;asmref
20 | m_ProjectGenerationRootNamespace:
21 | m_CollabEditorSettings:
22 | inProgressEnabled: 1
23 | m_EnableTextureStreamingInEditMode: 1
24 | m_EnableTextureStreamingInPlayMode: 1
25 | m_AsyncShaderCompilation: 1
26 | m_EnterPlayModeOptionsEnabled: 0
27 | m_EnterPlayModeOptions: 3
28 | m_ShowLightmapResolutionOverlay: 1
29 | m_UseLegacyProbeSampleCount: 0
30 | m_SerializeInlineMappingsOnOneLine: 1
31 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!30 &1
4 | GraphicsSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 13
7 | m_Deferred:
8 | m_Mode: 1
9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0}
10 | m_DeferredReflections:
11 | m_Mode: 1
12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0}
13 | m_ScreenSpaceShadows:
14 | m_Mode: 1
15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0}
16 | m_LegacyDeferred:
17 | m_Mode: 1
18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0}
19 | m_DepthNormals:
20 | m_Mode: 1
21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0}
22 | m_MotionVectors:
23 | m_Mode: 1
24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0}
25 | m_LightHalo:
26 | m_Mode: 1
27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0}
28 | m_LensFlare:
29 | m_Mode: 1
30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0}
31 | m_AlwaysIncludedShaders:
32 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
33 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0}
34 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0}
35 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0}
36 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
37 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
38 | m_PreloadedShaders: []
39 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
40 | type: 0}
41 | m_CustomRenderPipeline: {fileID: 0}
42 | m_TransparencySortMode: 0
43 | m_TransparencySortAxis: {x: 0, y: 0, z: 1}
44 | m_DefaultRenderingPath: 1
45 | m_DefaultMobileRenderingPath: 1
46 | m_TierSettings: []
47 | m_LightmapStripping: 0
48 | m_FogStripping: 0
49 | m_InstancingStripping: 0
50 | m_LightmapKeepPlain: 1
51 | m_LightmapKeepDirCombined: 1
52 | m_LightmapKeepDynamicPlain: 1
53 | m_LightmapKeepDynamicDirCombined: 1
54 | m_LightmapKeepShadowMask: 1
55 | m_LightmapKeepSubtractive: 1
56 | m_FogKeepLinear: 1
57 | m_FogKeepExp: 1
58 | m_FogKeepExp2: 1
59 | m_AlbedoSwatchInfos: []
60 | m_LightsUseLinearIntensity: 0
61 | m_LightsUseColorTemperature: 0
62 | m_LogWhenShaderIsCompiled: 0
63 | m_AllowEnlightenSupportForUpgradedProject: 0
64 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/MemorySettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!387306366 &1
4 | MemorySettings:
5 | m_ObjectHideFlags: 0
6 | m_EditorMemorySettings:
7 | m_MainAllocatorBlockSize: -1
8 | m_ThreadAllocatorBlockSize: -1
9 | m_MainGfxBlockSize: -1
10 | m_ThreadGfxBlockSize: -1
11 | m_CacheBlockSize: -1
12 | m_TypetreeBlockSize: -1
13 | m_ProfilerBlockSize: -1
14 | m_ProfilerEditorBlockSize: -1
15 | m_BucketAllocatorGranularity: -1
16 | m_BucketAllocatorBucketsCount: -1
17 | m_BucketAllocatorBlockSize: -1
18 | m_BucketAllocatorBlockCount: -1
19 | m_ProfilerBucketAllocatorGranularity: -1
20 | m_ProfilerBucketAllocatorBucketsCount: -1
21 | m_ProfilerBucketAllocatorBlockSize: -1
22 | m_ProfilerBucketAllocatorBlockCount: -1
23 | m_TempAllocatorSizeMain: -1
24 | m_JobTempAllocatorBlockSize: -1
25 | m_BackgroundJobTempAllocatorBlockSize: -1
26 | m_JobTempAllocatorReducedBlockSize: -1
27 | m_TempAllocatorSizeGIBakingWorker: -1
28 | m_TempAllocatorSizeNavMeshWorker: -1
29 | m_TempAllocatorSizeAudioWorker: -1
30 | m_TempAllocatorSizeCloudWorker: -1
31 | m_TempAllocatorSizeGfx: -1
32 | m_TempAllocatorSizeJobWorker: -1
33 | m_TempAllocatorSizeBackgroundWorker: -1
34 | m_TempAllocatorSizePreloadManager: -1
35 | m_PlatformMemorySettings: {}
36 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/NavMeshAreas.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!126 &1
4 | NavMeshProjectSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | areas:
8 | - name: Walkable
9 | cost: 1
10 | - name: Not Walkable
11 | cost: 1
12 | - name: Jump
13 | cost: 2
14 | - name:
15 | cost: 1
16 | - name:
17 | cost: 1
18 | - name:
19 | cost: 1
20 | - name:
21 | cost: 1
22 | - name:
23 | cost: 1
24 | - name:
25 | cost: 1
26 | - name:
27 | cost: 1
28 | - name:
29 | cost: 1
30 | - name:
31 | cost: 1
32 | - name:
33 | cost: 1
34 | - name:
35 | cost: 1
36 | - name:
37 | cost: 1
38 | - name:
39 | cost: 1
40 | - name:
41 | cost: 1
42 | - name:
43 | cost: 1
44 | - name:
45 | cost: 1
46 | - name:
47 | cost: 1
48 | - name:
49 | cost: 1
50 | - name:
51 | cost: 1
52 | - name:
53 | cost: 1
54 | - name:
55 | cost: 1
56 | - name:
57 | cost: 1
58 | - name:
59 | cost: 1
60 | - name:
61 | cost: 1
62 | - name:
63 | cost: 1
64 | - name:
65 | cost: 1
66 | - name:
67 | cost: 1
68 | - name:
69 | cost: 1
70 | - name:
71 | cost: 1
72 | m_LastAgentTypeID: -887442657
73 | m_Settings:
74 | - serializedVersion: 2
75 | agentTypeID: 0
76 | agentRadius: 0.5
77 | agentHeight: 2
78 | agentSlope: 45
79 | agentClimb: 0.75
80 | ledgeDropHeight: 0
81 | maxJumpAcrossDistance: 0
82 | minRegionArea: 2
83 | manualCellSize: 0
84 | cellSize: 0.16666667
85 | manualTileSize: 0
86 | tileSize: 256
87 | accuratePlacement: 0
88 | debug:
89 | m_Flags: 0
90 | m_SettingNames:
91 | - Humanoid
92 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/PackageManagerSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &1
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 61
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0}
13 | m_Name:
14 | m_EditorClassIdentifier:
15 | m_EnablePreReleasePackages: 0
16 | m_EnablePackageDependencies: 0
17 | m_AdvancedSettingsExpanded: 1
18 | m_ScopedRegistriesSettingsExpanded: 1
19 | m_SeeAllPackageVersions: 0
20 | oneTimeWarningShown: 0
21 | m_Registries:
22 | - m_Id: main
23 | m_Name:
24 | m_Url: https://packages.unity.com
25 | m_Scopes: []
26 | m_IsDefault: 1
27 | m_Capabilities: 7
28 | m_UserSelectedRegistryName:
29 | m_UserAddingNewScopedRegistry: 0
30 | m_RegistryInfoDraft:
31 | m_Modified: 0
32 | m_ErrorMessage:
33 | m_UserModificationsInstanceId: -830
34 | m_OriginalInstanceId: -832
35 | m_LoadAssets: 0
36 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!19 &1
4 | Physics2DSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 4
7 | m_Gravity: {x: 0, y: -9.81}
8 | m_DefaultMaterial: {fileID: 0}
9 | m_VelocityIterations: 8
10 | m_PositionIterations: 3
11 | m_VelocityThreshold: 1
12 | m_MaxLinearCorrection: 0.2
13 | m_MaxAngularCorrection: 8
14 | m_MaxTranslationSpeed: 100
15 | m_MaxRotationSpeed: 360
16 | m_BaumgarteScale: 0.2
17 | m_BaumgarteTimeOfImpactScale: 0.75
18 | m_TimeToSleep: 0.5
19 | m_LinearSleepTolerance: 0.01
20 | m_AngularSleepTolerance: 2
21 | m_DefaultContactOffset: 0.01
22 | m_JobOptions:
23 | serializedVersion: 2
24 | useMultithreading: 0
25 | useConsistencySorting: 0
26 | m_InterpolationPosesPerJob: 100
27 | m_NewContactsPerJob: 30
28 | m_CollideContactsPerJob: 100
29 | m_ClearFlagsPerJob: 200
30 | m_ClearBodyForcesPerJob: 200
31 | m_SyncDiscreteFixturesPerJob: 50
32 | m_SyncContinuousFixturesPerJob: 50
33 | m_FindNearestContactsPerJob: 100
34 | m_UpdateTriggerContactsPerJob: 100
35 | m_IslandSolverCostThreshold: 100
36 | m_IslandSolverBodyCostScale: 1
37 | m_IslandSolverContactCostScale: 10
38 | m_IslandSolverJointCostScale: 10
39 | m_IslandSolverBodiesPerJob: 50
40 | m_IslandSolverContactsPerJob: 50
41 | m_AutoSimulation: 1
42 | m_QueriesHitTriggers: 1
43 | m_QueriesStartInColliders: 1
44 | m_CallbacksOnDisable: 1
45 | m_ReuseCollisionCallbacks: 1
46 | m_AutoSyncTransforms: 0
47 | m_AlwaysShowColliders: 0
48 | m_ShowColliderSleep: 1
49 | m_ShowColliderContacts: 0
50 | m_ShowColliderAABB: 0
51 | m_ContactArrowScale: 0.2
52 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412}
53 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
54 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
55 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
56 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
57 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/PresetManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1386491679 &1
4 | PresetManager:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | m_DefaultPresets: {}
8 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/ProjectVersion.txt:
--------------------------------------------------------------------------------
1 | m_EditorVersion: 2022.2.16f1
2 | m_EditorVersionWithRevision: 2022.2.16f1 (d535843d11e1)
3 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/SceneTemplateSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "templatePinStates": [],
3 | "dependencyTypeInfos": [
4 | {
5 | "userAdded": false,
6 | "type": "UnityEngine.AnimationClip",
7 | "ignore": false,
8 | "defaultInstantiationMode": 0,
9 | "supportsModification": true
10 | },
11 | {
12 | "userAdded": false,
13 | "type": "UnityEditor.Animations.AnimatorController",
14 | "ignore": false,
15 | "defaultInstantiationMode": 0,
16 | "supportsModification": true
17 | },
18 | {
19 | "userAdded": false,
20 | "type": "UnityEngine.AnimatorOverrideController",
21 | "ignore": false,
22 | "defaultInstantiationMode": 0,
23 | "supportsModification": true
24 | },
25 | {
26 | "userAdded": false,
27 | "type": "UnityEditor.Audio.AudioMixerController",
28 | "ignore": false,
29 | "defaultInstantiationMode": 0,
30 | "supportsModification": true
31 | },
32 | {
33 | "userAdded": false,
34 | "type": "UnityEngine.ComputeShader",
35 | "ignore": true,
36 | "defaultInstantiationMode": 1,
37 | "supportsModification": true
38 | },
39 | {
40 | "userAdded": false,
41 | "type": "UnityEngine.Cubemap",
42 | "ignore": false,
43 | "defaultInstantiationMode": 0,
44 | "supportsModification": true
45 | },
46 | {
47 | "userAdded": false,
48 | "type": "UnityEngine.GameObject",
49 | "ignore": false,
50 | "defaultInstantiationMode": 0,
51 | "supportsModification": true
52 | },
53 | {
54 | "userAdded": false,
55 | "type": "UnityEditor.LightingDataAsset",
56 | "ignore": false,
57 | "defaultInstantiationMode": 0,
58 | "supportsModification": false
59 | },
60 | {
61 | "userAdded": false,
62 | "type": "UnityEngine.LightingSettings",
63 | "ignore": false,
64 | "defaultInstantiationMode": 0,
65 | "supportsModification": true
66 | },
67 | {
68 | "userAdded": false,
69 | "type": "UnityEngine.Material",
70 | "ignore": false,
71 | "defaultInstantiationMode": 0,
72 | "supportsModification": true
73 | },
74 | {
75 | "userAdded": false,
76 | "type": "UnityEditor.MonoScript",
77 | "ignore": true,
78 | "defaultInstantiationMode": 1,
79 | "supportsModification": true
80 | },
81 | {
82 | "userAdded": false,
83 | "type": "UnityEngine.PhysicMaterial",
84 | "ignore": false,
85 | "defaultInstantiationMode": 0,
86 | "supportsModification": true
87 | },
88 | {
89 | "userAdded": false,
90 | "type": "UnityEngine.PhysicsMaterial2D",
91 | "ignore": false,
92 | "defaultInstantiationMode": 0,
93 | "supportsModification": true
94 | },
95 | {
96 | "userAdded": false,
97 | "type": "UnityEngine.Rendering.PostProcessing.PostProcessProfile",
98 | "ignore": false,
99 | "defaultInstantiationMode": 0,
100 | "supportsModification": true
101 | },
102 | {
103 | "userAdded": false,
104 | "type": "UnityEngine.Rendering.PostProcessing.PostProcessResources",
105 | "ignore": false,
106 | "defaultInstantiationMode": 0,
107 | "supportsModification": true
108 | },
109 | {
110 | "userAdded": false,
111 | "type": "UnityEngine.Rendering.VolumeProfile",
112 | "ignore": false,
113 | "defaultInstantiationMode": 0,
114 | "supportsModification": true
115 | },
116 | {
117 | "userAdded": false,
118 | "type": "UnityEditor.SceneAsset",
119 | "ignore": false,
120 | "defaultInstantiationMode": 0,
121 | "supportsModification": false
122 | },
123 | {
124 | "userAdded": false,
125 | "type": "UnityEngine.Shader",
126 | "ignore": true,
127 | "defaultInstantiationMode": 1,
128 | "supportsModification": true
129 | },
130 | {
131 | "userAdded": false,
132 | "type": "UnityEngine.ShaderVariantCollection",
133 | "ignore": true,
134 | "defaultInstantiationMode": 1,
135 | "supportsModification": true
136 | },
137 | {
138 | "userAdded": false,
139 | "type": "UnityEngine.Texture",
140 | "ignore": false,
141 | "defaultInstantiationMode": 0,
142 | "supportsModification": true
143 | },
144 | {
145 | "userAdded": false,
146 | "type": "UnityEngine.Texture2D",
147 | "ignore": false,
148 | "defaultInstantiationMode": 0,
149 | "supportsModification": true
150 | },
151 | {
152 | "userAdded": false,
153 | "type": "UnityEngine.Timeline.TimelineAsset",
154 | "ignore": false,
155 | "defaultInstantiationMode": 0,
156 | "supportsModification": true
157 | }
158 | ],
159 | "defaultDependencyTypeInfo": {
160 | "userAdded": false,
161 | "type": "",
162 | "ignore": false,
163 | "defaultInstantiationMode": 1,
164 | "supportsModification": true
165 | },
166 | "newSceneOverride": 0
167 | }
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!78 &1
4 | TagManager:
5 | serializedVersion: 2
6 | tags: []
7 | layers:
8 | - Default
9 | - TransparentFX
10 | - Ignore Raycast
11 | -
12 | - Water
13 | - UI
14 | -
15 | -
16 | -
17 | -
18 | -
19 | -
20 | -
21 | -
22 | -
23 | -
24 | -
25 | -
26 | -
27 | -
28 | -
29 | -
30 | -
31 | -
32 | -
33 | -
34 | -
35 | -
36 | -
37 | -
38 | -
39 | -
40 | m_SortingLayers:
41 | - name: Default
42 | uniqueID: 0
43 | locked: 0
44 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!5 &1
4 | TimeManager:
5 | m_ObjectHideFlags: 0
6 | Fixed Timestep: 0.02
7 | Maximum Allowed Timestep: 0.33333334
8 | m_TimeScale: 1
9 | Maximum Particle Timestep: 0.03
10 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/UnityConnectSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!310 &1
4 | UnityConnectSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 1
7 | m_Enabled: 0
8 | m_TestMode: 0
9 | m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events
10 | m_EventUrl: https://cdp.cloud.unity3d.com/v1/events
11 | m_ConfigUrl: https://config.uca.cloud.unity3d.com
12 | m_DashboardUrl: https://dashboard.unity3d.com
13 | m_TestInitMode: 0
14 | CrashReportingSettings:
15 | m_EventUrl: https://perf-events.cloud.unity3d.com
16 | m_Enabled: 0
17 | m_LogBufferSize: 10
18 | m_CaptureEditorExceptions: 1
19 | UnityPurchasingSettings:
20 | m_Enabled: 0
21 | m_TestMode: 0
22 | UnityAnalyticsSettings:
23 | m_Enabled: 0
24 | m_TestMode: 0
25 | m_InitializeOnStartup: 1
26 | UnityAdsSettings:
27 | m_Enabled: 0
28 | m_InitializeOnStartup: 1
29 | m_TestMode: 0
30 | m_IosGameId:
31 | m_AndroidGameId:
32 | m_GameIds: {}
33 | m_GameId:
34 | PerformanceReportingSettings:
35 | m_Enabled: 0
36 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/VFXManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!937362698 &1
4 | VFXManager:
5 | m_ObjectHideFlags: 0
6 | m_IndirectShader: {fileID: 0}
7 | m_CopyBufferShader: {fileID: 0}
8 | m_SortShader: {fileID: 0}
9 | m_StripUpdateShader: {fileID: 0}
10 | m_RenderPipeSettingsPath:
11 | m_FixedTimeStep: 0.016666668
12 | m_MaxDeltaTime: 0.05
13 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/VersionControlSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!890905787 &1
4 | VersionControlSettings:
5 | m_ObjectHideFlags: 0
6 | m_Mode: Visible Meta Files
7 | m_CollabEditorSettings:
8 | inProgressEnabled: 1
9 |
--------------------------------------------------------------------------------
/WrenSharp.Unity.Project/ProjectSettings/XRSettings.asset:
--------------------------------------------------------------------------------
1 | {
2 | "m_SettingKeys": [
3 | "VR Device Disabled",
4 | "VR Device User Alert"
5 | ],
6 | "m_SettingValues": [
7 | "False",
8 | "False"
9 | ]
10 | }
--------------------------------------------------------------------------------
/WrenSharp.Unity/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore helper scripts
2 | /CopyToUnityProject.ps1
3 |
--------------------------------------------------------------------------------
/WrenSharp.Unity/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using System.Runtime.InteropServices;
3 |
4 | [assembly: InternalsVisibleTo("WrenSharp.Tests")]
5 | [assembly: ComVisible(false)]
6 | [assembly: Guid("0bca2bbc-729f-4ccb-8f58-61009e67354a")]
7 |
--------------------------------------------------------------------------------
/WrenSharp.Unity/Package:
--------------------------------------------------------------------------------
1 | ../WrenSharp.Unity.Project/Packages/com.deadreckoned.wrensharp
--------------------------------------------------------------------------------
/WrenSharp.Unity/Sources/WrenTextAssetSource.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Unity.Collections;
3 | using Unity.Collections.LowLevel.Unsafe;
4 | using UnityEngine;
5 |
6 | namespace WrenSharp
7 | {
8 | ///
9 | /// A Wren script source that reads from a Unity .
10 | ///
11 | public unsafe class WrenTextAssetSource : IWrenSource
12 | {
13 | private TextAsset m_Asset;
14 |
15 | #region Properties
16 |
17 | ///
18 | /// The containing the Wren script.
19 | ///
20 | public TextAsset TextAsset
21 | {
22 | get => m_Asset;
23 | set => m_Asset = value;
24 | }
25 |
26 | #endregion
27 |
28 | ///
29 | /// Creates a new .
30 | ///
31 | public WrenTextAssetSource()
32 | {
33 |
34 | }
35 |
36 | ///
37 | /// Creates a new .
38 | ///
39 | /// The to read from.
40 | public WrenTextAssetSource(TextAsset textAsset)
41 | {
42 | m_Asset = textAsset;
43 | }
44 |
45 |
46 | #region IModuleSource
47 |
48 | ///
49 | /// Get a pointer to the bytes containing the Wren script source that can be passed
50 | /// to the native Wren VM.
51 | ///
52 | /// The number of bytes in the source.
53 | /// A pointer to the source bytes.
54 | public IntPtr GetSourceBytes(out int byteCount)
55 | {
56 | if (m_Asset == null)
57 | {
58 | byteCount = 0;
59 | return IntPtr.Zero;
60 | }
61 |
62 | NativeArray data = m_Asset.GetData();
63 | byteCount = data.Length;
64 | return (IntPtr)NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(data);
65 | }
66 |
67 | #endregion
68 |
69 | #region IDisposable
70 |
71 | void IDisposable.Dispose()
72 | {
73 |
74 | }
75 |
76 | #endregion
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/WrenSharp.Unity/UnityWrenDebugOutput.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using UnityEngine;
4 |
5 | namespace WrenSharp.Unity
6 | {
7 | ///
8 | /// Forwards Wren write and error operations to the Unity logging methods.
9 | ///
10 | public class UnityWrenDebugOutput : IWrenWriteOutput, IWrenErrorOutput
11 | {
12 | ///
13 | /// Prefix used to print messages from Wren as warnings to the Unity log and console.
14 | ///
15 | public const string WarnPrefix = "!warn:";
16 |
17 | ///
18 | /// Prefix used to print messages from Wren as errors to the Unity log and console.
19 | ///
20 | public const string ErrorPrefix = "!error:";
21 |
22 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
23 | private void Write(LogType type, string message) => Debug.unityLogger.Log(type, message);
24 |
25 | #region WrenSharp Interfaces
26 |
27 | void IWrenWriteOutput.OutputWrite(WrenVM vm, string text)
28 | {
29 | if (string.IsNullOrWhiteSpace(text))
30 | return;
31 |
32 | static string Parse(string text, out LogType logType)
33 | {
34 | if (text.StartsWith(ErrorPrefix, StringComparison.OrdinalIgnoreCase))
35 | {
36 | logType = LogType.Error;
37 | return text.Substring(ErrorPrefix.Length);
38 | }
39 |
40 | if (text.StartsWith(WarnPrefix, StringComparison.OrdinalIgnoreCase))
41 | {
42 | logType = LogType.Warning;
43 | return text.Substring(WarnPrefix.Length);
44 | }
45 |
46 | logType = LogType.Log;
47 | return text;
48 | }
49 |
50 | string message = Parse(text, out LogType logType);
51 | Write(logType, message);
52 | }
53 |
54 | void IWrenErrorOutput.OutputError(WrenVM vm, WrenErrorType errorType, string moduleName, int lineNumber, string message)
55 | {
56 | switch (errorType)
57 | {
58 | case WrenErrorType.Compile:
59 | Write(LogType.Error, $"Wren compile error in {moduleName}:{lineNumber} : {message}");
60 | break;
61 |
62 | case WrenErrorType.StackTrace:
63 | Write(LogType.Error, $"at {message} in {moduleName}:{lineNumber}");
64 | break;
65 |
66 | case WrenErrorType.Runtime:
67 | Write(LogType.Error, string.IsNullOrEmpty(moduleName)
68 | ? $"{ErrorPrefix}Wren error: {message}"
69 | : $"{ErrorPrefix}Wren error in {moduleName}: {message}");
70 | break;
71 | }
72 | }
73 |
74 | #endregion
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/WrenSharp.Unity/WrenSharp.Unity.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.1
5 | disable
6 | True
7 | WrenSharp.Unity
8 | True
9 |
10 |
11 |
12 | $(DefineConstants);WRENSHARP_UNITY;WRENSHARP_EXT
13 |
14 |
15 |
16 | $(DefineConstants);WRENSHARP_UNITY;WRENSHARP_EXT
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | C:\Program Files\Unity\Hub\Editor\2021.3.16f1\Editor\Data\Managed\UnityEngine.dll
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/WrenSharp.Unity/WrenVMConfiguration.cs:
--------------------------------------------------------------------------------
1 | using WrenSharp.Native;
2 |
3 | namespace WrenSharp
4 | {
5 | public partial class WrenVMConfiguration
6 | {
7 | ///
8 | ///
9 | /// A custom memory reallocation delegate. Leave null to use Wren's default native memory reallocation function.
10 | ///
11 | ///
12 | /// This delegate should free memory when the newSize parameter is zero, and reallocate the
13 | /// pointer memory to a new block of memory of at least newSize bytes.
14 | ///
15 | ///
16 | /// Failing to free allocated memory when newSize is zero will result in memory leaks.
17 | ///
18 | ///
19 | public WrenNativeFn.Reallocate Reallocate { get; set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/WrenSharp/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using System.Runtime.InteropServices;
3 |
4 | [assembly: InternalsVisibleTo("WrenSharp.Tests")]
5 | [assembly: ComVisible(false)]
6 | [assembly: Guid("9986db13-06a3-4fad-91d6-1e748b045df5")]
7 |
--------------------------------------------------------------------------------
/WrenSharp/WrenConsoleOutput.cs:
--------------------------------------------------------------------------------
1 | namespace WrenSharp
2 | {
3 | ///
4 | /// A Wren writer and error receiver that forwards output to .
5 | ///
6 | public class WrenConsoleOutput : IWrenWriteOutput, IWrenErrorOutput
7 | {
8 | public void OutputWrite(WrenVM vm, string text)
9 | {
10 | Console.Write(text);
11 | }
12 |
13 | public void OutputError(WrenVM vm, WrenErrorType errorType, string moduleName, int lineNumber, string message)
14 | {
15 | switch (errorType)
16 | {
17 | case WrenErrorType.Compile:
18 | Console.WriteLine($"Wren compile error in {moduleName}:{lineNumber} : {message}");
19 | break;
20 |
21 | case WrenErrorType.StackTrace:
22 | Console.WriteLine($"at {message} in {moduleName}:{lineNumber}");
23 | break;
24 |
25 | case WrenErrorType.Runtime:
26 | Console.WriteLine(string.IsNullOrEmpty(moduleName)
27 | ? $"Wren error: {message}"
28 | : $"Wren error in {moduleName}: {message}");
29 | break;
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/WrenSharp/WrenForeign.cs:
--------------------------------------------------------------------------------
1 | using WrenSharp.Native;
2 |
3 | namespace WrenSharp
4 | {
5 | ///
6 | /// A builder for binding Wren foreign classes and methods.
7 | ///
8 | public sealed class WrenForeign : IWrenForeign
9 | {
10 | private readonly WrenVM m_Vm;
11 | private WrenNativeFn.ForeignMethod m_Allocator;
12 | private WrenNativeFn.Finalizer m_Finalizer;
13 | private Dictionary m_StaticMethods;
14 | private Dictionary m_InstanceMethods;
15 |
16 | internal WrenForeign(WrenVM vm)
17 | {
18 | m_Vm = vm;
19 | }
20 |
21 | #region Public API
22 |
23 | ///
24 | public IWrenForeign Allocate(IWrenForeign.Allocator allocator)
25 | {
26 | m_Allocator = (_) => allocator(m_Vm);
27 | return this;
28 | }
29 |
30 | ///
31 | public IWrenForeign Allocate(IWrenForeign.AllocatorCall allocator, byte paramCount = WrenVM.MaxCallParameters)
32 | {
33 | m_Allocator = (_) => allocator(new WrenCallContext(m_Vm, WrenMethodType.Allocator, paramCount));
34 | return this;
35 | }
36 |
37 | ///
38 | public unsafe IWrenForeign Allocate() where T : unmanaged
39 | {
40 | m_Allocator = (vmPtr) =>
41 | {
42 | T* data = (T*)Wren.SetSlotNewForeign(vmPtr, 0, 0, (ulong)sizeof(T));
43 | *data = new T();
44 | };
45 | return this;
46 | }
47 |
48 | ///
49 | public unsafe IWrenForeign Allocate(IWrenForeign.Allocator allocator) where T : unmanaged
50 | {
51 | m_Allocator = (vmPtr) =>
52 | {
53 | T* data = (T*)Wren.SetSlotNewForeign(vmPtr, 0, 0, (ulong)sizeof(T));
54 | *data = new T();
55 | allocator(m_Vm, ref *data);
56 | };
57 | return this;
58 | }
59 |
60 | ///
61 | public unsafe IWrenForeign Allocate(IWrenForeign.AllocatorCall allocator, byte paramCount = WrenVM.MaxCallParameters) where T : unmanaged
62 | {
63 | m_Allocator = (_) =>
64 | {
65 | T* data = (T*)Wren.SetSlotNewForeign(m_Vm.m_Ptr, 0, 0, (ulong)sizeof(T));
66 | *data = new T();
67 | allocator(new WrenCallContext(m_Vm, WrenMethodType.Allocator, paramCount), ref *data);
68 | };
69 | return this;
70 | }
71 |
72 | ///
73 | public IWrenForeign Finalize(IWrenForeign.Finalizer finalizer)
74 | {
75 | m_Finalizer = (data) => finalizer(data);
76 | return this;
77 | }
78 |
79 | ///
80 | public unsafe IWrenForeign Finalize(IWrenForeign.Finalizer finalizer) where T : unmanaged
81 | {
82 | m_Finalizer = (data) => finalizer(ref *(T*)data);
83 | return this;
84 | }
85 |
86 | ///
87 | public IWrenForeign Instance(string signature, WrenForeignMethod method)
88 | {
89 | InternalAddMethod(WrenMethodType.Instance, signature, method);
90 | return this;
91 | }
92 |
93 | ///
94 | public IWrenForeign Static(string signature, WrenForeignMethod method)
95 | {
96 | InternalAddMethod(WrenMethodType.Static, signature, method);
97 | return this;
98 | }
99 |
100 | #endregion
101 |
102 | private void InternalAddMethod(WrenMethodType methodType, string signature, WrenForeignMethod method)
103 | {
104 | var paramCount = WrenUtils.GetParameterCount(signature);
105 | if (paramCount == WrenVM.MaxCallParameters)
106 | throw new ArgumentException("Signature exceeds maximum parameter count.");
107 |
108 | void fn(IntPtr _) => method(new WrenCallContext(m_Vm, methodType, (byte)paramCount));
109 |
110 | if (methodType == WrenMethodType.Static)
111 | {
112 | m_StaticMethods ??= new Dictionary();
113 | m_StaticMethods[signature] = fn;
114 | }
115 | else
116 | {
117 | m_InstanceMethods ??= new Dictionary();
118 | m_InstanceMethods[signature] = fn;
119 | }
120 | }
121 |
122 | #region Internal
123 |
124 | internal WrenNativeFn.ForeignMethod FindMethod(bool isStatic, string signature)
125 | {
126 | var methods = isStatic ? m_StaticMethods : m_InstanceMethods;
127 | if (methods == null)
128 | return default;
129 |
130 | methods.TryGetValue(signature, out var method);
131 | return method;
132 | }
133 |
134 | internal WrenForeignClassMethods GetClassMethods() => new WrenForeignClassMethods()
135 | {
136 | Allocate = m_Allocator,
137 | Finalize = m_Finalizer,
138 | };
139 |
140 | #endregion
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/WrenSharp/WrenSharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | enable
6 | disable
7 | True
8 |
9 |
10 |
11 | $(DefineConstants);WRENSHARP_EXT
12 |
13 |
14 |
15 | $(DefineConstants);WRENSHARP_EXT
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/WrenSharp/WrenVMConfiguration.cs:
--------------------------------------------------------------------------------
1 | namespace WrenSharp
2 | {
3 | public partial class WrenVMConfiguration
4 | {
5 | ///
6 | ///
7 | /// A custom memory allocation delegate. Leave null to use Wren's default native memory reallocation function.
8 | ///
9 | ///
10 | /// This delegate should free memory when the newSize parameter is zero, and reallocate the
11 | /// pointer memory to a new block of memory of at least newSize bytes.
12 | ///
13 | ///
14 | /// Failing to free allocated memory when newSize is zero will result in memory leaks.
15 | ///
16 | ///
17 | public WrenReallocate Reallocator { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------