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
source
stringThe full C# file as a single string.
namespaceName
stringThe 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
filePath
stringThe path to the script file.
classNamespace
stringThe namespace of the script class, e.g. "RisingV.BossDrops.Scripts".
options
ScriptLoaderOptionsOptional 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
scriptPath
stringThe path to the directory containing script files.
classNamespace
stringThe 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.