Skip to content

Alex-Kent/OpenSCAD_compat

Repository files navigation

OpenSCAD compat

C and Perl compatible functions

OpenSCAD compat © 2025 Alexander Hajnal

License: CC BY-NC-SA Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International https://creativecommons.org/licenses/by-nc-sa/4.0/

A set of functions for OpenSCAD that closely follow ones found in the C standard library and Perl.

The semantics are usually similar but not identical to their C and Perl equivalents so cf. the syntax descriptions.

Supported functions

Functions are split across several files:

  • c_constants.scad — Constant definitions

    Documentation is in c_constants.md. Tests/examples are in c_constants-test.scad.

    A set of useful constants for OpenSCAD that closely follow those in the C standard library and Perl. These currently include:

    • ASCII special characters → A set of variables are defined that represent most of the unprintable 7-bit ASCII characters as well as the set of valid whitespace characters,
  • c_string.scad — String-related functions

    Documentation is in c_string.md. Tests/examples are in c_string-test.scad.

    Requires c_constants.scad.

    • Generic:

      • printf → Ouput formatted string to console
      • sprintf → Format string
    • C-like:

      • strchr → Find character in string
      • strcspn → Get prefix of string not containing a set of characters
      • strlen → Determine length of string (same as OpenSCAD's len)
      • strpbrk → Find one of a set of characters in string
      • strrchr → Find character in string (starting from end)
      • strspn → Get prefix of string containing only a set of characters
      • strstr → Find string in a second string
      • strtok → Split string into tokens
    • Perl-like:

      • index → Find string in second string
      • rindex → Find string in second string (starting from end)
      • substr → Extract substring from string
  • c_numeric.scad — Number-related functions

    Documentation in c_numeric.md. Tests/examples are in c_numeric-test.scad.

    Requires c_constants.scad and c_string.scad.

    • Miscellaneous numeric utility functions (non-C, non-Perl)

      None currently

    • C-like numeric utility functions

      None currently

    • C-like conversion functions (by datatype)

      • Returning 32-bit integers:

        • strtol(string, base=0)
    • Perl-like numeric functions

      None currently

Usage

Depending on the libraries used different include statements are required. The appropriate include/use code should be placed near the top of your script and each file mentioned should be placed in the same directory as your OpenSCAD script.

c_constants

include <c_constants.scad>;

c_numeric

use <c_numeric.scad>;

In addition c_constants.scad and c_string.scad must also be present in your scripts directory.

c_string

include <c_constants.scad>;
use <c_string.scad>;

Bugs/Feature requests

Please submit any bug reports or feature requests via GitHub.

Version history

Date c_constants c_string c_numeric Notes
2025-11-24 1.0.0 1.0.0 1.0.0 Initial public release

About

C and Perl compatible functions for OpenSCAD

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published