omdl  v0.5
OpenSCAD Mechanical Design Library
utilities.scad
Go to the documentation of this file.
1 //! Miscellaneous utilities.
2 /***************************************************************************//**
3  \file utilities.scad
4  \author Roy Allen Sutton
5  \date 2015-2017
6 
7  \copyright
8 
9  This file is part of [omdl] (https://github.com/royasutton/omdl),
10  an OpenSCAD mechanical design library.
11 
12  The \em omdl is free software; you can redistribute it and/or modify
13  it under the terms of the [GNU Lesser General Public License]
14  (http://www.gnu.org/licenses/lgpl.html) as published by the Free
15  Software Foundation; either version 2.1 of the License, or (at
16  your option) any later version.
17 
18  The \em omdl is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with the \em omdl; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26  02110-1301, USA; or see <http://www.gnu.org/licenses/>.
27 
28  \details
29 
30  \ingroup utilities
31 *******************************************************************************/
32 
33 //----------------------------------------------------------------------------//
34 /***************************************************************************//**
35  \ingroup utilities
36  @{
37 *******************************************************************************/
38 //----------------------------------------------------------------------------//
39 
40 //! Format the function call stack as a string.
41 /***************************************************************************//**
42  \param b <decimal> The stack index bottom offset.
43  Include function names above this offset.
44  \param t <decimal> The stack index top offset.
45  Include function names below this offset.
46 
47  \returns <string> A colon-separated list of functions names for the
48  current function call stack.
49 
50  \note Returns \b undef when \p b is greater than the current number
51  of function instances (ie: <tt>bo > $parent_modules-1</tt>).
52  \note Returns the string \c "root()" when the function call stack
53  is empty (ie: at the root of the script).
54 *******************************************************************************/
55 function stack
56 (
57  b = 0,
58  t = 0
59 ) = let
60  (
61  bo = abs(b),
62  to = abs(t),
63  i = $parent_modules - 1 - bo
64  )
65  ($parent_modules == undef) ? "root()"
66  : (bo > $parent_modules-1) ? undef
67  : (i < to) ? "root()"
68  : (i == to) ? str( parent_module( i ), "()" )
69  : str( parent_module( i ), "(): ", stack( bo + 1, to ) );
70 
71 //! @}
72 
73 //----------------------------------------------------------------------------//
74 // end of file
75 //----------------------------------------------------------------------------//
function stack(b=0, t=0)
Format the function call stack as a string.