using Newtonsoft.Json.Linq;
using Serein.Library;
using Serein.Library.Api;
using Serein.Library.Utils;
using Serein.Script.Node;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Xml.Linq;
namespace Serein.Script
{
public sealed class SereinSciptException : Exception
{
//public ASTNode Node { get; }
public override string Message { get; }
public SereinSciptException(ASTNode node, string message)
{
//this.Node = node;
Message = $"异常信息 : {message} ,代码在第{node.Row}行: {node.Code.Trim()}";
}
}
public class SereinScriptInterpreter
{
///
/// 定义的变量
///
private Dictionary _variables = new Dictionary();
///
/// 挂载的函数
///
private static Dictionary _functionTable = new Dictionary();
///
/// 挂载的函数调用的对象(用于函数需要实例才能调用的场景)
///
private static Dictionary> _callFuncOfGetObjects = new Dictionary>();
///
/// 定义的类型
///
private static Dictionary _classDefinition = new Dictionary();
///
/// 重置的变量
///
public void ResetVar()
{
foreach (var nodeObj in _variables.Values)
{
if (nodeObj is not null)
{
if (typeof(IDisposable).IsAssignableFrom(nodeObj?.GetType()) && nodeObj is IDisposable disposable)
{
disposable?.Dispose();
}
}
else
{
}
}
_variables.Clear();
}
///
/// 挂载函数
///
/// 函数名称
/// 方法信息
public static void AddFunction(string functionName, MethodInfo methodInfo, Func