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.
Functions are split across several files:
-
c_constants.scad— Constant definitionsDocumentation is in
c_constants.md. Tests/examples are inc_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 functionsDocumentation is in
c_string.md. Tests/examples are inc_string-test.scad.Requires
c_constants.scad.-
Generic:
printf→ Ouput formatted string to consolesprintf→ Format string
-
C-like:
strchr→ Find character in stringstrcspn→ Get prefix of string not containing a set of charactersstrlen→ Determine length of string (same as OpenSCAD'slen)strpbrk→ Find one of a set of characters in stringstrrchr→ Find character in string (starting from end)strspn→ Get prefix of string containing only a set of charactersstrstr→ Find string in a second stringstrtok→ Split string into tokens
-
Perl-like:
index→ Find string in second stringrindex→ Find string in second string (starting from end)substr→ Extract substring from string
-
-
c_numeric.scad— Number-related functionsDocumentation in
c_numeric.md. Tests/examples are inc_numeric-test.scad.Requires
c_constants.scadandc_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
-
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.
include <c_constants.scad>;
use <c_numeric.scad>;
In addition c_constants.scad and c_string.scad must also be present in your scripts directory.
include <c_constants.scad>;
use <c_string.scad>;
Please submit any bug reports or feature requests via GitHub.
| Date | c_constants | c_string | c_numeric | Notes |
|---|---|---|---|---|
| 2025-11-24 | 1.0.0 | 1.0.0 | 1.0.0 | Initial public release |