/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/ScriptEngine/Machine/Contexts/GlobalContextBase.cs
149 строк
4 KB
EvilBeaver
Удален устаревший метод OnAttach и массово исправлены неиспользуемые using
02 дек 2025, 11:20
02 дек 2025, 11:20
0301fed
Код
Авторство
О чём код?
/*---------------------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ using System; using OneScript.Contexts; using OneScript.Execution; using OneScript.Values; namespace ScriptEngine.Machine.Contexts { public abstract class GlobalContextBase<T> : BslObjectValue, IAttachableContext where T : GlobalContextBase<T> { protected ContextMethodsMapper<T> Methods { get; } = new ContextMethodsMapper<T>(); protected ContextPropertyMapper<T> Properties { get; } = new ContextPropertyMapper<T>(); #region IRuntimeContextInstance members public bool IsIndexed { get { return false; } } public bool DynamicMethodSignatures => false; public IValue GetIndexedValue(IValue index) { throw new NotImplementedException(); } public void SetIndexedValue(IValue index, IValue val) { throw new NotImplementedException(); } public virtual int GetPropertyNumber(string name) { return Properties.FindProperty(name); } public virtual bool IsPropReadable(int propNum) { return Properties.GetProperty(propNum).CanRead; } public virtual bool IsPropWritable(int propNum) { return Properties.GetProperty(propNum).CanWrite; } public virtual IValue GetPropValue(int propNum) { try { return Properties.GetProperty(propNum).Getter((T)this); } catch (System.Reflection.TargetInvocationException e) { throw e.InnerException; } } public virtual void SetPropValue(int propNum, IValue newVal) { try { Properties.GetProperty(propNum).Setter((T)this, newVal); } catch (System.Reflection.TargetInvocationException e) { throw e.InnerException; } } public int GetPropCount() { return Properties.Count; } public string GetPropName(int propNum) { var prop = Properties.GetProperty(propNum); return prop.Name; } public virtual int GetMethodNumber(string name) { return Methods.FindMethod(name); } public virtual BslMethodInfo GetMethodInfo(int methodNumber) { return Methods.GetRuntimeMethod(methodNumber); } public virtual BslPropertyInfo GetPropertyInfo(int propertyNumber) { return Properties.GetProperty(propertyNumber).PropertyInfo; } public virtual void CallAsProcedure(int methodNumber, IValue[] arguments, IBslProcess process) { Methods.GetCallableDelegate(methodNumber)((T)this, arguments, process); } public virtual void CallAsFunction(int methodNumber, IValue[] arguments, out IValue retValue, IBslProcess process) { retValue = Methods.GetCallableDelegate(methodNumber)((T)this, arguments, process); } public void CallAsProcedure(int methodNumber, IValue[] arguments) { CallAsProcedure(methodNumber, arguments, ForbiddenBslProcess.Instance); } public void CallAsFunction(int methodNumber, IValue[] arguments, out IValue retValue) { CallAsFunction(methodNumber, arguments, out retValue, ForbiddenBslProcess.Instance); } #endregion #region IAttachableContext members IVariable IAttachableContext.GetVariable(int index) { return Variable.CreateContextPropertyReference(this, index, GetPropName(index)); } BslMethodInfo IAttachableContext.GetMethod(int index) { return GetMethodInfo(index); } int IAttachableContext.VariablesCount => GetPropCount(); int IAttachableContext.MethodsCount => GetMethodsCount(); public virtual int GetMethodsCount() { return Methods.Count; } #endregion } }