Struct comments in templates

Dear team,

I’m a heavy user of templates and declarative attributes to make the output as easily readable as possible, and 101 Editor already offers a lot of features regarding that. Since the tree navigation can sometimes make getting to the essence a bit tricky, I find myself using the <comment> attribute a lot to extract the most useful bits from a struct, much like Debuggers do in their tooltips for variables. I came across two questions though:

  1. Is there a single place to define a way a struct is displayed in a comment? For now, I’m having a lot of repetition by placing the comment on each use of the struct, e.g.
struct String
{
	int length;
	char content[length];
};

String s1 <comment=Str("Length = %i", this.length)>;
String s2 <comment=Str("Length = %i", this.length)>;
String s3 <comment=Str("Length = %i", this.length)>;

Placing the on the struct itself would seem like a logical place, but 101 treats it as a syntax error if I do so.

  1. Is there a way to display a string declared as char[] inside a comment? The following - continued from above example - does not seem to work (“content is not a member of the struct”):
String s1 <comment=Str("Text = %s", this.content)>;

In case this is not currently possible, I’d be happy if you considered it a suggestion for further enhancement of an already very good tool. :slight_smile:

Thanks,
Michael

Hello micTronic. You can specify a comment function for a struct, but you have to use a typedef like this:

typedef struct 
{
	int length;
	char content[length];
} String <comment=Str("Length = %i", this.length)>;

String s1;
String s2;
String s3;

Accessing a string inside a comment should work fine. We tried this and it worked for us:

typedef struct 
{
	int length;
	char content[length];
} String <comment=Str("Text = %s", this.content)>;

If it doesn’t work then there may be something else going on in your template and let us know if it doesn’t work. Cheers!

Graeme
SweetScape Software

Hi, if I change my structs to typedefs, then indeed both work. Thanks a lot for the hint Graeme!

Best,
Michael