From ff17b6749d7601353b16e2ac75ce5997728b71fd Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 23 Mar 2025 14:08:15 +0100 Subject: [PATCH] Refactored the Lua module loading & standard libraries from the plugin base to the factory --- .../Tools/PluginSystem/PluginBase.cs | 14 -------------- .../Tools/PluginSystem/PluginFactory.cs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/MindWork AI Studio/Tools/PluginSystem/PluginBase.cs b/app/MindWork AI Studio/Tools/PluginSystem/PluginBase.cs index 91b3e166..060e7cce 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/PluginBase.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/PluginBase.cs @@ -68,20 +68,6 @@ public abstract class PluginBase : IPluginMetadata { this.state = state; this.Type = type; - - // For security reasons, we don't want to allow the plugin to load modules: - this.state.ModuleLoader = new NoModuleLoader(); - - // Add some useful libraries: - this.state.OpenModuleLibrary(); - this.state.OpenStringLibrary(); - this.state.OpenTableLibrary(); - this.state.OpenMathLibrary(); - this.state.OpenBitwiseLibrary(); - this.state.OpenCoroutineLibrary(); - - // Add the module loader so that the plugin can load other Lua modules: - this.state.ModuleLoader = new PluginLoader(path); var issues = new List(); if(!string.IsNullOrWhiteSpace(parseError)) diff --git a/app/MindWork AI Studio/Tools/PluginSystem/PluginFactory.cs b/app/MindWork AI Studio/Tools/PluginSystem/PluginFactory.cs index 7b158af2..e136e714 100644 --- a/app/MindWork AI Studio/Tools/PluginSystem/PluginFactory.cs +++ b/app/MindWork AI Studio/Tools/PluginSystem/PluginFactory.cs @@ -3,6 +3,7 @@ using System.Text; using AIStudio.Settings; using Lua; +using Lua.Standard; namespace AIStudio.Tools.PluginSystem; @@ -94,6 +95,17 @@ public static partial class PluginFactory return new NoPlugin($"This plugin is forbidden: {forbiddenState.Message}"); var state = LuaState.Create(); + + // Add the module loader so that the plugin can load other Lua modules: + state.ModuleLoader = new PluginLoader(pluginPath); + + // Add some useful libraries: + state.OpenModuleLibrary(); + state.OpenStringLibrary(); + state.OpenTableLibrary(); + state.OpenMathLibrary(); + state.OpenBitwiseLibrary(); + state.OpenCoroutineLibrary(); try {