A material in GraphScript is a system that defines and implements side-effects for a GraphScript code file.
The [PY-INJ] material allows you to implement GraphScript syntax nodes via injected Python code. It is one of the first materials and a very primitive one, yet it is extremely powerful.
- Clone this repository.
- Remove the
.gitfolder (preferably, re-initialize the git repository). - Edit the
materials/template/main.pyfile to implement your own nodes. - Rename the
materials/templatefolder to your material name. - Edit the
test.gsamfile with relevant usage of your material. - Run the
test.gsamfile with the GraphScript runtime. (gsam test.gsam) - Edit the
README.mdfile to document your material. [OPTIONAL] - Publish your material to GitHub and share it with the GraphScript community. [OPTIONAL]
- Use your material in your GraphScript projects. [OPTIONAL, but highly recommended]
.
├── README.md
├── materials
│ └── <material_name>
│ ├── main.py
│ └── material.conf
└── test.gsam
A material is organized into the following sections:
- INTERFACES (Optional)
- RUNTIME IMPORTS (Required)
- UTILITY FUNCTIONS (Optional)
- IMPLEMENTATIONS (Required)
- NODE DEFINITIONS (Required)
- LOAD FUNCTION (Required)
Create a syntax node by subclassing SyntaxNode and implementing execute_material.
@extends
class ExampleNode(Interface.SyntaxNode):
def execute_material(
self: Interface.SyntaxNode,
syntax: Interface.SyntaxNode,
stream: Interface.ExecutionStream,
):
"""
# Example Node: Execute Material
- `self`: The registered node instance.
- `syntax`: The syntax node being executed.
- `stream`: The active execution stream.
"""
# Implement the node's side-effect here
...Export every syntax node through the _definitions dictionary.
_definitions = {
"example": ExampleNode,
}The key is the exported node name. The value is the corresponding SyntaxNode subclass.
Every material must define a load() function. The runtime calls it once when importing the material.
Typical responsibilities include:
- Reading material configuration.
- Registering exported nodes.
- Performing one-time initialization.
While the template already handles registering nodes via _definitions. Memory of the runtime can also be manually manipulated using the memory API. For example, you can register a node with a fixed name like this:
memory.upsert(
fixed_name,
NodeClass("*", fixed_name),
)Most materials benefit from helper functions for parsing arguments.
- Keyword Arguments
kw_parse(syntax)
- Positional Arguments
arg_parse(syntax)
These helpers are optional but recommended for consistency across materials.