feat: add 2d shapes#4
Merged
Merged
Conversation
…ables in hostapi.hpp
There was a problem hiding this comment.
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
Coreentrypoint 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)butretis a ScopedJSValue wrapper; the other call sites correctly checkret.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 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 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 on lines
+1
to
+2
| #include <CLI/CLI.hpp> | ||
| #include "core.hpp" |
Comment on lines
+1
to
+4
| #pragma once | ||
| #include <format> | ||
| #include <raylib.h> | ||
| #include <quickjs.h> |
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 on lines
+205
to
+207
| if (config.class_id == 0) { | ||
| JS_NewClassID(rt, &config.class_id); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.