-
-
Notifications
You must be signed in to change notification settings - Fork 0
APIReference
Daynlight edited this page Dec 13, 2025
·
4 revisions
This section is an overview of the classes and functions that Graphite has.
All user scripts must implement the following interface:
class ScriptInterface {
public:
virtual ~ScriptInterface() = default;
virtual void Init() = 0; // Called once at startup
virtual void Update() = 0; // Called every frame
virtual void Draw() = 0; // Called every frame for rendering
virtual void Destroy() = 0; // Called before unloading
};Export functions for DLL:
extern "C" ScriptInterface* SCRIPT_API GetScript();
extern "C" void SCRIPT_API DeleteScript(ScriptInterface* script);// Graphite
// Copyright 2025 Daynlight
// Licensed under the Apache License, Version 2.0.
// See LICENSE file for details.
#define BUILDING_SCRIPT_DLL
#include <Graphite/ScriptInterface.h>
class Script : ScriptInterface{
/* ... */ // Declarations
void Init(){
/* ... */ // Initialization
};
void Update(){
/* ... */ // Update Per Frame
};
void Draw(){
/* ... */ // Drawing on window
};
void Destroy(){
/* ... */ // Destructor
};
};
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;
};- Scripts are compiled to shared libraries (
Graphite.so) - Loaded/unloaded at runtime via
dlopen,dlsym,dlclose - Functions:
GetScript,DeleteScript
- Use sandbox mode for safer script editing.
- Always clean up in
Destroy(). - Verbose mode for debugging output.
Point class is used inside script for drawing single point. It is than added to plot.
namespace Graphite::Math {
class Point {
Point(std::array<float, 2> pos, std::array<float, 3> color);
std::array<float, 2> getPos();
void setPos(std::array<float, 2> pos);
std::array<float, 3> getColor();
void setColor(std::array<float, 3> color);
};
};Plot is our 2D canvas where we draw elements. We add others Math classes to cells.
namespace Graphite::Math{
class Plot2D{
public:
std::unordered_map<std::string, Graphite::Math::Point> point_cell;
private:
void drawPoint(Graphite::Math::Point point);
public:
Plot2D();
~Plot2D();
void draw();
};
};AppRenderer is wrapper for my CWindow library that contains functions require for Graphite.
namespace Graphite{
class AppRenderer{
private:
CW::Renderer::iRenderer* renderer;
public:
AppRenderer();
~AppRenderer();
template<typename F>
void renderFrame(F&& fun);
bool isRunning();
};
};ScriptController is used for Script compilation and hot-reloading also for sandbox mode via forks.
namespace Graphite{
class ScriptLoader{
private:
std::string path = "";
bool cant_find_file_print = 1;
std::filesystem::file_time_type lastWriteTime{};
void* script_handler = nullptr;
ScriptInterface* script = nullptr;
public:
ScriptLoader(const std::string& path);
~ScriptLoader();
bool checkLastWrite();
void updateScript();
int compile();
int loadModule();
void removeModule();
void init();
void update();
void draw();
void destroy();
};
};It is entry point for program, loads flags and start Graphite.
namespace Graphite{
class Graphite{
private:
std::unordered_map<std::string, bool> flags;
std::filesystem::path path = std::filesystem::path("./");
private:
void initFile(const std::string& filename, const char* data);
void init();
void help();
void verbose();
void sandbox();
void longFlags(int* i, int args, const char* argv[]);
void shortFlags(int* i, int args, const char* argv[]);
void detectPath(int* i, int args, const char* argv[]);
void detectFlags(int args, const char* argv[]);
void executeFlags();
public:
void run(int args, const char* argv[]);
void runProgram();
};
};-
-h/--help: Show help. -
-i/--init: Initialize default files. -
-s/--sandbox: Enable sandbox mode (safe script execution). -
-v/-d/--verbose/--debug: Enable verbose/debug output.
GraphiteInstaller is small program for easy installation process.
Graphite Wiki ยฉ 2025 Daynlight & Contributors
Licensed under the Apache License 2.0
- ๐ Home
- ๐ ๏ธ Installation
- ๐งโ๐ป Usage
- ๐ Tutorials
- ๐งโ๐ฌ Examples
- ๐ WritingScripts
- ๐ฆ PackageManager
- ๐งฎ Math
- ๐๏ธ APIReference
- ๐ผ๏ธ RenderingEngine
- ๐๏ธ Architecture
- ๐ Roadmap
- ๐ Versions
- ๐ ChangeLog
- ๐ถ Planning
- ๐ค Community
- ๐ Credits
- ๐ Troubleshooting
- โ FAQ