Skip to content

Add BOSL (Belfry OpenSCAD Library) bindings for LuaCAD#5

Merged
ad-si merged 1 commit intomainfrom
claude/add-bosl-functions-wGM3c
Feb 28, 2026
Merged

Add BOSL (Belfry OpenSCAD Library) bindings for LuaCAD#5
ad-si merged 1 commit intomainfrom
claude/add-bosl-functions-wGM3c

Conversation

@ad-si
Copy link
Owner

@ad-si ad-si commented Feb 26, 2026

Summary

This PR adds comprehensive Lua bindings for the BOSL (Belfry OpenSCAD Library), enabling LuaCAD users to access BOSL's extensive collection of 3D modeling functions directly from Lua scripts. All BOSL functions are registered under the bosl namespace and automatically generate the required OpenSCAD include/use directives.

Key Changes

  • New BOSL module (crates/luacad/src/bosl.rs):

    • Implements ~200+ BOSL function bindings across 20 BOSL modules (shapes, transforms, masks, threading, gears, etc.)
    • Provides helper functions to convert Lua values (numbers, tables, booleans) to OpenSCAD argument syntax
    • Implements make_bosl_fn() factory to generate Lua closures that wrap BOSL function calls
    • Registers BOSL constants (directional vectors, alignment values, mathematical constants like PHI)
    • Includes comprehensive test suite validating function registration, argument conversion, and SCAD generation
  • ScadNode enum extension (crates/luacad/src/scad_export.rs):

    • Added BoslCall variant to represent BOSL function/module calls in the AST
    • Implemented collect_bosl_modules() to recursively scan the node tree and collect all referenced BOSL modules
    • Updated generate_scad() to automatically emit include <BOSL/constants.scad> and use <BOSL/...> directives based on actual usage
    • Added rendering logic for BoslCall nodes to generate proper OpenSCAD syntax
  • Lua engine integration (crates/luacad/src/lua_engine.rs):

    • Integrated BOSL registration into the main Lua execution pipeline via register_bosl()
  • Library exports (crates/luacad/src/lib.rs):

    • Exported the new bosl module
  • Example script (examples/bosl_demo.lua):

    • Demonstrates usage of BOSL functions (cuboid, threaded_rod, gear, nema17_stepper)
    • Shows access to BOSL constants (V_UP, PHI)
    • Illustrates combining BOSL objects with standard CSG operations

Implementation Details

  • Argument conversion: Lua tables are intelligently converted to OpenSCAD syntax—sequential integer keys become arrays [...], string keys become named parameters key = value
  • Floating-point formatting: Numbers are formatted with trailing zero trimming to produce clean OpenSCAD output
  • Module organization: BOSL functions are grouped by their source file (shapes.scad, transforms.scad, etc.) for maintainability
  • Automatic directive generation: The SCAD exporter analyzes the node tree to determine which BOSL modules are actually used, avoiding unnecessary includes
  • Test coverage: Tests validate basic function calls, named arguments, multiple modules, constant access, and SCAD generation with proper directives

https://claude.ai/code/session_01LAjoXUcfTZ7QhrHKxz8Wa1

Add comprehensive bindings for all functions from the Belfry OpenSCAD
Library (BOSL). Functions are accessible via the `bosl` namespace
(e.g. `bosl.cuboid(...)`, `bosl.threaded_rod(...)`) and generate proper
OpenSCAD code with automatic `include`/`use` directives on SCAD export.

Covers all BOSL modules: shapes, transforms, masks, threading, paths,
beziers, involute_gears, joiners, sliders, metric_screws, linear_bearings,
nema_steppers, phillips_drive, torx_drive, wiring, quaternions,
triangulation, convex_hull, debug, math, and constants.

https://claude.ai/code/session_01LAjoXUcfTZ7QhrHKxz8Wa1
@ad-si ad-si merged commit c5a0c6f into main Feb 28, 2026
6 checks passed
@ad-si ad-si deleted the claude/add-bosl-functions-wGM3c branch February 28, 2026 19:47
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.

2 participants