Skip to content

feat: add 2d shapes#4

Merged
burdockcascade merged 24 commits into
masterfrom
shapes2d
Jul 25, 2026
Merged

feat: add 2d shapes#4
burdockcascade merged 24 commits into
masterfrom
shapes2d

Conversation

@burdockcascade

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings July 25, 2026 21:58
@burdockcascade burdockcascade linked an issue Jul 25, 2026 that may be closed by this pull request
@burdockcascade
burdockcascade merged commit 16ef114 into master Jul 25, 2026
4 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a native QuickJS + raylib host runtime for “vectorjs”, including initial TypeScript declarations and several 2D drawing primitives exposed to JS, plus examples and CI/release workflows.

Changes:

  • Introduces a QuickJS engine wrapper and a Core entrypoint to load/evaluate user scripts.
  • Implements a host API module (vectorjs) with classes (Application/Color/Vector2/Rectangle), palette/enums, and a 2D render context with shape-drawing functions.
  • Adds TS typings, examples, build system (CMake + FetchContent), and GitHub Actions verify/release workflows.

Reviewed changes

Copilot reviewed 21 out of 25 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/vectorjs.d.ts Adds TypeScript module declarations for the JS-facing API.
src/main.cpp Adds CLI entrypoint to run a JS script or show a welcome screen.
src/js_engine.hpp Declares a QuickJS runtime/context wrapper.
src/js_engine.cpp Implements JS evaluation + file loading + exception/stack extraction.
src/core.hpp Declares the Core wrapper and UI helper functions.
src/core.cpp Implements module initialization and welcome/BSOD rendering loops.
src/api/js_utils.hpp Adds QuickJS RAII helpers and class-registration utilities.
src/api/js_types.hpp Defines native-backed types and class IDs for the host API.
src/api/js_context.hpp Declares context object factories for update/draw loops.
src/api/hostapi.hpp Defines module export registration and version constants.
src/api/api_enums.cpp Exports Palette/Info/ConfigFlags objects into the JS module.
src/api/api_context.cpp Builds the draw/render context and binds 2D shape primitives.
src/api/api_classes.cpp Registers JS classes and implements Application.run frame loop.
README.MD Adds a basic usage example.
examples/info.js Adds an Info example script.
examples/2d/solar2d.js Adds a 2D “solar system” example using circles.
examples/2d/shapes2.js Adds an animated shapes example using multiple primitives.
examples/2d/shapes.js Adds a basic shapes showcase example.
examples/2d/clock.js Adds an analog clock example using line/circle drawing.
CMakeLists.txt Adds a CMake build with FetchContent dependencies.
.github/workflows/verify.yml Adds cross-platform build verification.
.github/workflows/release.yml Adds release packaging/upload workflows.
Comments suppressed due to low confidence (2)

src/api/api_classes.cpp:51

  • JSApplication::Run assumes argv[0] is an object and does not handle JS_GetPropertyStr returning JS_EXCEPTION (e.g., if user_app is non-object or property access throws). This can leave a pending exception and produce confusing behavior in the render loop; validate the config object and propagate property-access exceptions immediately.
        if (argc < 1) return JS_ThrowTypeError(ctx, "Expected a user application config object");
        JSValueConst user_app = argv[0];

        Utils::ScopedJSValue on_init_func(ctx, JS_GetPropertyStr(ctx, user_app, "onInit"));
        Utils::ScopedJSValue on_update_func(ctx, JS_GetPropertyStr(ctx, user_app, "onUpdate"));

src/api/api_classes.cpp:61

  • The onInit call checks JS_IsException(ret) but ret is a ScopedJSValue wrapper; the other call sites correctly check ret.get(). This should consistently check the underlying JSValue to avoid relying on implicit conversions.
        if (JS_IsFunction(ctx, on_init_func)) {
            Utils::ScopedJSValue ret(ctx, JS_Call(ctx, on_init_func, user_app, 0, nullptr));
            if (JS_IsException(ret)) return JS_EXCEPTION;
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/api/api_context.cpp
Comment on lines +8 to +17
static JSDrawOptions parse_draw_options(JSContext* ctx, JSValueConst optionsObj) {
JSDrawOptions options;
if (JS_IsObject(optionsObj)) {
Utils::try_get_opaque_property<JSColor>(ctx, optionsObj, "color", js_color_class_id, options.color);
Utils::try_get_opaque_property<JSVector2>(ctx, optionsObj, "origin", js_color_class_id, options.origin);
Utils::try_get_opaque_property<float>(ctx, optionsObj, "rotation", js_color_class_id, options.rotation);
Utils::try_get_opaque_property<bool>(ctx, optionsObj, "wireframe", js_color_class_id, options.wireframe);
}
return options;
}
Comment thread src/api/api_classes.cpp
Comment on lines +31 to +36
int32_t h = 0, w = 0;
if (argc > 0 && JS_ToInt32(c, &h, argv[0]) < 0) return JS_EXCEPTION;
if (argc > 1 && JS_ToInt32(c, &w, argv[1]) < 0) return JS_EXCEPTION;
std::string title = argc > 2 ? Utils::js_to_std_string(c, argv[2]) : "VectorJS Application";
return Utils::create_js_instance<JSApplication>(c, new_target, js_application_class_id, h, w, std::move(title));
},
Comment thread src/main.cpp
Comment on lines +1 to +2
#include <CLI/CLI.hpp>
#include "core.hpp"
Comment thread src/api/hostapi.hpp
Comment on lines +1 to +4
#pragma once
#include <format>
#include <raylib.h>
#include <quickjs.h>
Comment thread examples/info.js
Comment on lines +12 to +15
render.withLayer2D((ctx) => {
ctx.text.drawText(line1, `RAYLIB VERSION: ${Info.RAYLIB_VERSION}`)
ctx.text.drawText(line2, `QUICKJS VERSION: ${Info.QUICKJS_VERSION}`)
});
Comment thread src/api/js_utils.hpp
Comment on lines +205 to +207
if (config.class_id == 0) {
JS_NewClassID(rt, &config.class_id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add 2d shapes

2 participants