C++ wrapper library for AngelScript
Seraph is a C++ wrapper library for AngelScript that streamlines type registration, function binding, and script-to-native interoperability.
- Builder-pattern APIs for type registration and function calling
- Support for value types, reference types, enums, interfaces, and globals
- Property reflection with metadata/attribute filtering
- Script loading and compilation management
Seraph currently ships as a Visual Studio project. Clone the repository into your project and configure your include directories to point to the Seraph headers. CMake support is planned.
#include <seraph/seraph.hpp>
srph::Engine scripting;Value Type (stack-allocated, copied)
srph::TypeRegistration::Class<glm::vec3, srph::ClassType::Value>(scripting, "vec3")
.BehavioursByTraits()
.Constructor<float, float, float>("float x, float y, float z")
.Property("float x", offsetof(glm::vec3, x))
.Property("float y", offsetof(glm::vec3, y))
.Property("float z", offsetof(glm::vec3, z));Reference Type (heap-allocated, handle-capable)
srph::TypeRegistration::Class<Transform, srph::ClassType::Reference>(scripting, "Transform", asOBJ_NOCOUNT)
.Method("vec3 GetPosition()", &Transform::GetPosition)
.Property("vec3 position", offsetof(Transform, position));Enum (automatic via magic_enum)
srph::TypeRegistration::Enum<KeyCode>(scripting).Register();Global Functions
srph::TypeRegistration::Global(scripting)
.Function("float sin(float)", [](float x) { return std::sin(x); })
.Function("float cos(float)", [](float x) { return std::cos(x); });Interfaces
srph::TypeRegistration::Interface(scripting, "IUpdatable")
.Method("void Update(float dt)");srph::ScriptLoader loader(scripting);
loader.Module("Game");
loader.LoadScript("assets/scripts/player.as");
if (loader.Build()) {
// Scripts compiled successfully
}srph::InstanceHandle handle = scripting.CreateInstance("Player", "Game");srph::FunctionCaller(&scripting)
.Module("Game")
.Function("void Update(float)", handle)
.Push(deltaTime)
.Call();auto fields = scripting.Reflect(handle, "Serialize");
for (auto& field : fields) {
// field.type, field.name, field.data
}class Player : IUpdatable {
[Serialize]
float speed = 5.0f;
void Update(float dt) {
// Access registered C++ types directly
vec3 movement = vec3(1.0f, 0.0f, 0.0f) * speed * dt;
}
}Seraph bundles the following libraries:
- AngelScript — core scripting engine
- Asio — async networking for the debugger (I plan to implement a more lightweight library)
- fmt — string formatting
- magic_enum — automatic enum type registration
- nlohmann/json — JSON serialization for debug protocol
MIT