PorygonSharp/PorygonSharp/StaticScope.cs

27 lines
1004 B
C#

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using PorygonSharp.EvalValues;
using PorygonSharp.Utilities;
namespace PorygonSharp
{
public static class StaticScope
{
private static List<object> _variables = new List<object>();
public static void RegisterStaticVariable(string name, object o)
{
var type = o.GetType();
var scriptType = ScriptType.ScriptTypeHandler.GetScriptType(type);
if (!scriptType.HasValue)
return;
var hash = name.ScriptHash();
var value = EvalValueCreator.CreateValue(o);
_variables.Add(o);
RegisterStaticVariable(hash, scriptType.Value, value.GetPointer());
}
[DllImport("PorygonLang", EntryPoint = "RegisterStaticVariable", CallingConvention = CallingConvention.Cdecl)]
private static extern void RegisterStaticVariable(uint hashId, IntPtr scriptType, IntPtr value);
}
}