kei-lisp-plugin-graphics - v4.0.0
    Preparing search index...

    Class GraphicsPlugin

    Canvas2D drawing plugin for the kei-lisp interpreter. Implements the KeiLispPlugin contract (name / has / apply) and exposes 75 g… Lisp functions that proxy to a 2D rendering context. Failures (wrong arity, type mismatch, closed canvas, canvas-level errors) signal an EvalError that Lisp callers can intercept with (handler-case … (eval-error (e) …)). Two exceptions still go to process.stderr as diagnostics: asynchronous work (image loading, OffscreenCanvas file writes), which fails after the call has returned, and selectColor's best-effort color parsing, which falls back to black instead of failing.

    Keisuke Ikeda

    Implements

    • KeiLispPlugin
    Index

    Constructors

    Properties

    canvas: HTMLCanvasElement | OffscreenCanvas
    ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D | null
    isOpen: boolean
    name: string = 'graphics'

    Plugin identifier, used for diagnostics.

    Methods

    • Dispatches the given symbol to the matching g… method.

      Parameters

      • aSymbol: InterpretedSymbol

        the call symbol

      • arguments_: Cons

        the evaluated argument list

      • _context: PluginContext

        the interpreter context (unused by this plugin)

      Returns LispValue

      the method's result

    • Pops the most recently saved drawing state off the context's state stack. Pairs with gSave. Popping an empty stack is a no-op per the Canvas spec.

      Parameters

      • arguments_: Cons = Cons.nil

      Returns LispValue

      t on success

    • Pushes the current drawing state (styles, transform, clip) onto the context's state stack. Pairs with gRestore to let Lisp callers manage state explicitly. Replaces the legacy per-method context.save() calls, which pushed state on every draw with no matching restore() and grew the stack unbounded.

      Parameters

      • arguments_: Cons = Cons.nil

      Returns LispValue

      t on success

    • Returns true if this plugin handles the given symbol.

      Parameters

      • aSymbol: InterpretedSymbol

        the call symbol

      Returns boolean

      true if apply should be called

    • Shared implementation of gsave-jpeg / gsave-png. With no argument it triggers a browser download; with a single string argument it writes the encoded image to that file path on Node.js.

      Parameters

      • arguments_: Cons

        the evaluated argument list (empty, or one path string)

      • mimeType: string

        the image MIME type to encode

      • label: string

        the format name used in diagnostics ("jpeg" / "png")

      Returns LispValue

      t on success

    • Parses a color spec from the head of the argument Cons. Accepts (1 string), (3 numbers — rgb), or (4 numbers — rgba); falls back to 'black' on anything else (legacy behavior — a best-effort color parse that prints a diagnostic instead of signaling an error).

      Parameters

      • arguments_: Cons

        the argument Cons to parse

      Returns string

      CSS color string

    • Lists every Lisp function name this plugin registers.

      Returns string[]

      the sorted g… function names