#Reference nested struct members

1 messages ยท Page 1 of 1 (latest)

normal peak
#

Maybe I'm trying to pet the cat backwards because I come from a 010 background, so if I could hold things better please let me know! Essentially I'm trying to write a pattern for a file format that holds multiple string tables and then I have objects that have indices into these string tables. Over in 010 land I would just do something like this:

typedef struct (StringTable &table)
{
    ubyte index;
    local string value = table.entries[index].value;
} StringTableReference <read=ReadStringTableReference>;

string ReadStringTableReference(StringTableReference &ref)
{
    return ref.value;
}

struct Foo(StringTable &table)
{
    StringTableReference name(table);
};

struct Header
{
    StringTable foo_string_table;
};

struct NestedThing(Header &header)
{
    ubyte count;
    Foo my_foos(header.foo_string_table)[count];  
};

Header header;
NestedThing nested(header);

Hope that kinda makes sense. With ImHex patterns this doesn't look like an option, instead my best option is to actually nest the structs and then use parent to navigate back up the chain to get the string table again. Is that true, or am I missing something in the pattern language?

#

I should add, essentially what I'm trying to do is pretty print the string itself in the pattern data view instead of just the index into the string table.

round quartz
#

Have you looked into templates with non-type arguments? you can use that to nest the structs.

normal peak
#

I have not! This is actually perfect because I am using a template for this right now and didn't know they supported non type arguments

round quartz
#

yes, you can pass any type included user defined types

#

as non-types I mean, sorry if thar's confusing

normal peak
#

sigh this is what I get for not fully reading the manual

#

I was looking in all the wrong places and never read past the base template reference

round quartz
#

documentation definitely needs some love.

#

one thing to look out for is recursive structs. those dont support arguments and you will need to use parent for them.

normal peak
#

How would I use a template type in a formatter?

#
{
    u8 index;
} [[format("format_string_table_reference)]];

fn format_string_table_reference(StringTableReference v) {
    return  v.Table.strings[v.index];
};
round quartz
#

auto

normal peak
#

This doesn't quite work, which isn't super unexpected

round quartz
#

use auto for the type in the function as well

normal peak
#
    return  T.strings[v.index];
};```

```E: error: Expected '(' after type cast, got Identifier ('T').
E:   -->   in <Source Code>:58:55
E: 58 | ference(StringTableReference<auto T> v) {```
#

I promise I'm not normally this dense ๐Ÿ˜

#

Eh, who am I kidding, I am

round quartz
#
struct StringTableReference<auto Table>
{
    u8 index;
} [[format("format_string_table_reference)]];

fn format_string_table_reference(auto v) {
    return  v.Table.strings[v.index];
};
normal peak
#

Ooooooohhhh

#

Thank you!