Move Wasmtime for .NET to the Wasmtime repo.
This moves the Wasmtime for .NET implementation to the Wasmtime repo. Wasmtime for .NET is a binding of the Wasmtime API for use in .NET.
This commit is contained in:
50
crates/misc/dotnet/src/Global.cs
Normal file
50
crates/misc/dotnet/src/Global.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
|
||||
namespace Wasmtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a constant WebAssembly global value.
|
||||
/// </summary>
|
||||
public class Global<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Global<T>" /> with the given initial value.
|
||||
/// </summary>
|
||||
/// <param name="initialValue">The initial value of the global.</param>
|
||||
public Global(T initialValue)
|
||||
{
|
||||
InitialValue = initialValue;
|
||||
Kind = Interop.ToValueKind(typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The value of the global.
|
||||
/// </summary>
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Handle is null)
|
||||
{
|
||||
throw new InvalidOperationException("The global cannot be used before it is bound to a module instance.");
|
||||
}
|
||||
|
||||
unsafe
|
||||
{
|
||||
var v = stackalloc Interop.wasm_val_t[1];
|
||||
|
||||
Interop.wasm_global_get(Handle.DangerousGetHandle(), v);
|
||||
|
||||
// TODO: figure out a way that doesn't box the value
|
||||
return (T)Interop.ToObject(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal ValueKind Kind { get; private set; }
|
||||
|
||||
internal Interop.GlobalHandle Handle { get; set; }
|
||||
|
||||
internal T InitialValue { get; private set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user