Class ScriptLoader
- Namespace
- RisingV.Scripting.RuntimeHost
- Assembly
- RisingV.Scripting.dll
Loads scripts from files, compiles them, and returns instances of IScript<TContext>.
public class ScriptLoader : IScriptLoader
- Inheritance
-
ScriptLoader
- Implements
- Inherited Members
- Extension Methods
Fields
UsingTemplate
Template for the using directives that will be prepended to the script source code.
public static readonly string UsingTemplate
Field Value
Methods
EnsureNamespaceInSource(string, string)
Ensures the given C# source text has the specified file-scoped namespace. If it's commented out, it'll be uncommented; if missing, it'll be injected after the last using.
public static string EnsureNamespaceInSource(string source, string namespaceName)
Parameters
sourcestringThe full C# file as a single string.
namespaceNamestringThe namespace to ensure, e.g. "RisingV.BossDrops.Scripts".
Returns
- string
The modified source text.
LoadScript(string, string, ScriptLoaderOptions?)
Loads a script from the specified file path and namespace.
public IScript<IScriptContext<ScriptData>> LoadScript(string filePath, string classNamespace, ScriptLoaderOptions? options = null)
Parameters
filePathstringThe path to the script file.
classNamespacestringThe namespace of the script class, e.g. "RisingV.BossDrops.Scripts".
optionsScriptLoaderOptionsOptional script loader options, such as the script name and whether to print diagnostics.
Returns
- IScript<IScriptContext<ScriptData>>
An instance of IScript<TContext> representing the loaded script.
Exceptions
- ScriptLoaderException
Thrown when the script cannot be loaded, compiled, or if the script class does not meet the required criteria.
LoadScripts(string, string)
Loads all scripts from the specified directory and namespace.
public List<IScript<IScriptContext<ScriptData>>> LoadScripts(string scriptPath, string classNamespace)
Parameters
scriptPathstringThe path to the directory containing script files.
classNamespacestringThe namespace of the script classes, e.g. "RisingV.BossDrops.Scripts".
Returns
- List<IScript<IScriptContext<ScriptData>>>
A list of instances of IScript<TContext> representing the loaded scripts.