simvx.core.script

ScriptManager — file-based class script loading for nodes.

Scripts are standard Python classes that extend the node’s type. ScriptManager imports the module, finds the matching class, and swaps node.__class__ so the node gains the script’s methods (ready, process, etc.).

Inline scripts (exec-based) are preserved for backward compatibility with demos.

Public API: ScriptManager.load(node, project_dir) ScriptManager.unload(node) ScriptManager.reload(node, project_dir) ScriptManager.exec_inline(node) ScriptManager.load_tree(root, project_dir)

Module Contents

Classes

ScriptManager

Static manager for loading/unloading file-based class scripts on nodes.

Data

API

simvx.core.script.log

‘getLogger(…)’

simvx.core.script.__all__

[‘ScriptManager’]

class simvx.core.script.ScriptManager

Static manager for loading/unloading file-based class scripts on nodes.

classmethod load(node: simvx.core.engine.Node, project_dir: str = '') bool

Load a file-based or embedded script onto node.

For file-backed scripts: resolves node.script as a path relative to project_dir, imports the module, finds the class that best matches the node’s type, and swaps node.__class__.

For embedded scripts: registers source with EmbeddedScriptFinder, imports it, and applies the same class swap.

Returns True on success, False on error (logged, not raised).

classmethod unload(node: simvx.core.engine.Node) None

Restore the node’s original class, removing the script behavior.

classmethod reload(node: simvx.core.engine.Node, project_dir: str = '') bool

Reload a node’s script (re-import module, re-swap class).

Preserves Property values across the reload.

classmethod exec_inline(node: simvx.core.engine.Node) None

Execute a node’s inline script string via exec() (backward compat).

classmethod load_tree(root: simvx.core.engine.Node, project_dir: str = '') list[simvx.core.engine.Node]

Walk root’s tree: load file-based scripts, then exec inline scripts.

Returns list of nodes that had file-based scripts loaded (class swapped), so the caller can invoke ready() or other lifecycle methods.

classmethod invalidate(abs_path: str) None

Remove a module from the cache so it will be re-imported on next load.

classmethod clear_cache() None

Clear the entire module cache.