/
EvilBeaver
/
OneScript
Обзор
Документация
Войти
/
EvilBeaver
/
OneScript
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/OneScript.Native/Runtime/NativeExecutorProvider.cs
57 строк
2 KB
EvilBeaver
Доработки загрузки библиотек с процессом
13 мар 2025, 20:23
13 мар 2025, 20:23
d428320
Код
Авторство
О чём код?
/*---------------------------------------------------------- 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 System.Globalization; using System.Reflection; using OneScript.Contexts; using OneScript.Execution; using OneScript.Native.Compiler; using OneScript.Values; using ScriptEngine.Machine; namespace OneScript.Native.Runtime { public class NativeExecutorProvider : IExecutorProvider { public Type SupportedModuleType => typeof(DynamicModule); public Invoker GetInvokeDelegate() { return Executor; } private static BslValue Executor( IBslProcess process, BslObjectValue target, IExecutableModule module, BslScriptMethodInfo method, IValue[] arguments) { if (!(module is DynamicModule)) { throw new InvalidOperationException(); } if (!(target is IAttachableContext context)) { throw new InvalidOperationException(); } if (!(method is BslNativeMethodInfo nativeMethod)) { throw new InvalidOperationException(); } var methodArguments = new object[arguments.Length + 1]; methodArguments[0] = process; Array.Copy(arguments, 0, methodArguments, 1, arguments.Length); return (BslValue) nativeMethod.Invoke(context, BindingFlags.Default, null, methodArguments, CultureInfo.CurrentCulture); } } }