/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
v2.0.0
src/OneScript.Native/Runtime/BslNativeMethodInfo.cs
68 строк
2 KB
EvilBeaver
Неоконченая локальная работа, бэкап
15 мар 2025, 20:35
15 мар 2025, 20:35
2ce20b1
Код
Авторство
О чём код?
/*---------------------------------------------------------- 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.Globalization; using System.Linq.Expressions; using System.Reflection; using OneScript.Contexts; using OneScript.Exceptions; using OneScript.Execution; using OneScript.Values; namespace OneScript.Native.Runtime { public class BslNativeMethodInfo : BslScriptMethodInfo { private CallableMethod _callable; public BslNativeMethodInfo() { _callable = new CallableMethod(this); } public void SetImplementation(LambdaExpression lambda) { Implementation = lambda; _callable.Compile(); } internal CallableMethod GetCallable() => _callable; public LambdaExpression Implementation { get; private set; } public bool IsInstance { get; internal set; } public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) { // FIXME: Из стековой машины дефолтные значения могут прийти, как null или Skipped // здесь мы принудительно проставляем пропущенные параметры var bslArguments = new BslValue[parameters.Length - 1]; for (int i = 0; i < bslArguments.Length; i++) { var param = parameters[i + 1]; if (param == null || param == BslSkippedParameterValue.Instance) { if (_parameters[i].HasDefaultValue) bslArguments[i] = (BslValue)_parameters[i].DefaultValue; else throw RuntimeException.MissedArgument(); } else if(param is BslValue bslVal) { bslArguments[i] = bslVal; } else if (param is IVariable variable) { bslArguments[i] = variable.BslValue; } } return _callable.Invoke((IBslProcess)parameters[0], obj, bslArguments); } } }