Why am I getting the error ‘this is a leaf node without children’ when I use the S() method?

In the Translator it is often handy to convert a node into a string, i.e.

T.FirstName = PID[5][1]:S():lower()

The :S() method is not actually a built in part of the language. It is a little extension routine we use often but it is actually defined in a shared module we ship called “node”.

Note: The :S() function was added to the builtin node module in Iguana 5.6.16, so you only need to require() the node module if you are working with 5.6.15 or earlier.

If your script does not include a reference to the node module using:

require 'node' or require('node')

Then you’ll get a very unintuitive error message along the lines of “this is a leaf node without children” like this:

If you add the require line at the top of your script the problem will go away.

Note: The which string conversion should I use page explains when to use :S(), using the S() function as shorthand for tostring() explains how it works.

Another related problem you might run into is like this:

What the error message “attempt to call method ‘capitalize’ (a nil value)” is telling us is that there is no function called string.capitalize defined. The capitalize function is not part of the standard Lua string library but is an extension that we wrote. The problem could be occurring for one of two reasons:

  1. You might need to add in require(‘stringutil’) which in the most recent versions of Iguana will have this extension defined.
  2. or you have a old copy of stringutil.lua which doesn’t have this extension function.

It’s a deliberate design choice not to update any modules beyond the first install of an Iguana 5.0 instance as explained here. If you do have an older version of stringutil installed, then you can download the latest version from our code repository which has the capitalize function included, and copy-paste it into the module.

Leave A Comment?