[OpenSCAD] "lookup" with strings? a bug?

Jordan Brown openscad at jordan.maileater.net
Wed May 29 13:02:03 EDT 2019

On 5/29/2019 9:33 AM, Serge wrote:
> Is lookup function searches for keys which are strings? say
> <b> lookup("foo",myArray)? </b>
> I get  undef back. Is this a bug?
> what's the good Strings functions library for OpenScad?

lookup( ) doesn't explicitly say so, but since it interpolates it can't
work on anything but numbers.

You want search( ).


  * If you're searching for a string, the first argument needs to be an
    array containing as its only element that string.
  * For the default num_returns_to_match of 1, the not-found results are
    a little peculiar.  Found yields an array that contains as its only
    element the index of the entry; not-found yields an array that
    contains as its only element an empty array.

table=[ [ "bar", 0 ], [ "foo", 1 ], [ "foo", 1 ], [ "baz", 2 ] ];
echo(search(["baz"], table));
echo(search(["foo"], table));
echo(search(["junk"], table));

ECHO: [3]
ECHO: [1]
ECHO: [[]]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20190529/f7efb769/attachment.html>

More information about the Discuss mailing list