Skip to content

Latest commit

 

History

History
122 lines (85 loc) · 4.91 KB

File metadata and controls

122 lines (85 loc) · 4.91 KB

OpenSCAD compat

c_constants

© 2025 Alexander Hajnal v1.0.0

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

To include in your code by placing this file in the same directory as your OpenSCAD script and including the following in your script:

include <c_constants.scad>;

A stand-alone demo/test script can be found in c_constants-test.scad.

Please submit any bug reports or feature requests via GitHub.

ASCII special characters

A number of variables are defined containing strings that represent various special characters in 7-bit ASCII character set. These are:

  • compat_SOH = 0x01 → SOH (start of heading)
  • compat_STX = 0x02 → STX (start of text)
  • compat_ETX = 0x03 → ETX (end of text)
  • compat_EOT = 0x04 → EOT (end of transmission)
  • compat_ENQ = 0x05 → ENQ (enquiry)
  • compat_ACK = 0x06 → ACK (acknowledge)
  • compat_BEL = 0x07 → BEL (bell)
  • compat_BS  = 0x08 → BS  (backspace)
  • compat_HT  = 0x09 → HT  (horizontal tab)
  • compat_LF  = 0x0A → LF  (new line)
  • compat_VT  = 0x0B → VT  (vertical tab)
  • compat_FF  = 0x0C → FF  (form feed)
  • compat_CR  = 0x0D → CR  (carriage ret)
  • compat_SO  = 0x0E → SO  (shift out)
  • compat_SI  = 0x0F → SI  (shift in)
  • compat_DLE = 0x10 → DLE (data link escape)
  • compat_DC1 = 0x11 → DC1 (device control 1)
  • compat_DC2 = 0x12 → DC2 (device control 2)
  • compat_DC3 = 0x13 → DC3 (device control 3)
  • compat_DC4 = 0x14 → DC4 (device control 4)
  • compat_NAK = 0x15 → NAK (negative acknowledge)
  • compat_SYN = 0x16 → SYN (synchronous idle)
  • compat_ETB = 0x17 → ETB (end of trans. blk)
  • compat_CAN = 0x18 → CAN (cancel)
  • compat_EM  = 0x19 → EM  (end of medium)
  • compat_SUB = 0x1A → SUB (substitute)
  • compat_ESC = 0x1B → ESC (escape; non-standard escape sequence)
  • compat_FS  = 0x1C → FS  (file separator)
  • compat_GS  = 0x1D → GS  (group separator)
  • compat_RS  = 0x1E → RS  (record separator)
  • compat_US  = 0x1F → US  (unit separator)
  • compat_DEL = 0x7F → DEL (delete)

The null character (NULL = 0x00) is not representable in OpenSCAD.

In addition to the single characters above the compat_WHITESPACE variable contains all of the valid 7-bit ASCII whitespace characters (space, FF, NL [a.k.a. LF], CR, HT, and VT).

Library version numbers

Major versions indicate a non-backwards-compatible change to the API.

Minor versions indicate substantial new features or bug fixes.

Subminor versions indicate changes that don't [yet] warrant incrementing the minor version number.

A suffix may be added when the changes are so inconsequential that incrementing the version number isn't warranted. This may include things like tweaks to comment formatting, indents, and the like. It does not include any changes to the code's logic or syntax.

Library version related functions

  • c_constants_version() Returns the c_constants library version as an OpenSCAD list: [ Major, Minor, Subminor, Suffix ]

    (e.g. [ 1, 0, 2, "bis" ])

  • c_constants_version_string() Returns the c_constants library version as an OpenSCAD list: "Major.Minor.SubminorSuffix"

    (e.g. "1.0.2bis")

  • c_constants_require( major, minor, subminor ) Require at least the specified version of c_constants. Throws a fatal error if the c_constants library version is less than the one specified. All arguments are optional. Note that the suffix is ignored.

    Throws a fatal error if the c_constants library version is less than the one specified.

    This is a module and returns no value.

  • c_constants_require_exact(major,minor,subminor) Require a specific version of c_constants

    Throws a fatal error if the c_constants library version does not equal the one specified. All arguments are optional. Note that the suffix is ignored.

    This is a module and returns no value.

Note: To require any version of c_constants with a specific major (i.e. with a compatible API) but with at least a given revision (minor or minor.subminor) use e.g.:

c_constants_require_exact(major=1);     // Any 1.x.y version
c_constants_require(major=1, minor=2);  // Version 1.2.y or later
  • c_constants_version_major() Returns the c_constants library major version number as an integer.

  • c_constants_version_minor() Returns the c_constants library minor version number as an integer.

  • c_constants_version_subminor() Returns the c_constants library subminor version number as an integer.

  • c_constants_version_suffix() Returns the c_constants library version suffix as a string.

Version history

1.0.0 [2025-11-24] Initial public release

  • Initial version