Skip to content

WritingScripts

Daynlight edited this page Dec 8, 2025 · 1 revision

Writing Scripts

๐Ÿšง Note: For advanced scripting features (UI, 3D, live editing), see Roadmap.md for future plans!

This guide explains how to write scripts for Graphite using C++ and the provided interfaces.


Script Structure

Scripts must implement the ScriptInterface with these methods:

  • Init() โ€“ Initialization code
  • Update() โ€“ Per-frame logic
  • Draw() โ€“ Drawing code
  • Destroy() โ€“ Cleanup

Example:

#define BUILDING_SCRIPT_DLL
#include <Graphite/ScriptInterface.h>
#include <Graphite/Math.h>

class Script : ScriptInterface {
	void Init() {
		// Initialization
	}
	void Update() {
		// Frame logic
	}
	void Draw() {
		// Drawing
	}
	void Destroy() {
		// Cleanup
	}
};

extern "C" ScriptInterface* SCRIPT_API GetScript() {
	Script* script = new Script();
	return (ScriptInterface*)script;
}
extern "C" void SCRIPT_API DeleteScript(ScriptInterface* script) {
	Script* temp_script = (Script*)script;
	delete temp_script;
}

Using the Math Library

Create and draw points:

Graphite::Math::Point p({0.5f, 0.5f}, {1.0f, 0.0f, 0.0f});
p.drawPoint();

Tips

  • Always implement all four methods

  • Use sandbox mode for safer editing

  • Use verbose mode for debugging

  • For edition use sandbox mode it prevents segment fault and program crashes at runtime edition.

  • Sandbox mode runs the Graphite -v <path> on fork. If program breaks it doesn't stop whole program just check if script is changed.

  • Always end all threads in script in Destroy() function.

  • When script is stable use normal mode for performance.

  • See Examples.md for more sample scripts


For advanced scripting, see the API Reference and Tutorials.

Graphite Wiki Sidebar

Getting Started

References

Project & Versions

Community

Clone this wiki locally