Struct objects

Hi,

Maybe a bit of a strange query, but has anyone used structs in HSL?

I’ve tried stuff like the below, but can’t get it to work…

struct Person {
  char name;
} testPerson;

testPerson.name = "Gareth";
Trace(testPerson.name);

Thanks.

Hi @Gareth,

See below for the three options for declaring your example structure. The Help file image you posted is a bit confusing, but what it is trying to get across is that the structure id can be either leading, trailing, or both. In the case of both, the ids need to match.

image

image

image

Thank you,
Dan

2 Likes

Thanks Dan, I’ll give that a go.
Why does it need the first curly bracket?
And does the struct work like the rest of the code I showed?
I was surprised that none of the library files I had used a struct at all, is it not recommended?

How do you assign it to a variable?

I’m going to be that guy to provide fair warning.

I have tried and tried to understand and use Hamilton Sign Language (HSL) (Joke) in the past with much frustration. I would advise against it at all costs. If Hamilton provided more support in this area then I feel I would have been successful. You can check the programming manual for hints to write HSL but as far as I know that is the only help you will find.

Bradley

2 Likes

Hey Bradley, thank you for the warning. I agree, I wish the documentation was better around it, but I actually quite enjoy writing HSL from time to time. I’m hoping that we can add to the wiki using all the really useful help Dan, Nick etc have responded with like above to increase the documentation :slight_smile:

HSL is not dissimilar to C, so I feel somewhat comfortable in it (although its been a while programming in C…). Not sure of your programming background but if you’re not used to those lower level languages I can understand it being frustrating.

I’d like to start using structs, and if HSL had enums that would also help (although of course there are alternatives to enums)

1 Like

Hi @Gareth,

I’ve not seen the structure object used in any of the HSL files I’ve dug through in the past. This is likely due to limited use cases stemming from limited functionality offered by the structure object itself.

The first curly bracket in my image is there because I tested the code as in-line HSL in VENUS Method Editor, which requires open/close brackets when declaring objects, as those objects are made local to that in-line code block.

As for the remainder of your code, see below for the required modifications:
image

This code traces the integer 71 (decimal ASCII for uppercase G). Note the single quotes around ‘Gareth’ as char is not a string, but is able to store the first character as an integer value. The default library, HSLStrLib, has a command for converting ASCII decimal to string values.

The code here allows assignment of the ‘name’ tag declaration to variable ‘testPerson’:
image

Both traces yield 71 in this case, too.

Thank you,
Dan

2 Likes

Thanks @DanHartman_Hamilton, that’s really helpful! Time to play around with it :slight_smile:

P.s. I didn’t know about the open/close brackets rule when declaring objects in-line, that’s good to know!

Gareth

2 Likes

Hi Gareth.

It is a good point about taking the information and creating a wiki. I’ve worked in C and C++ in my past for microcontroller programming so not too bad. I just feel that working with a language without proper documentation can sometimes feel like a fools errand. Maybe if this forum generates interest in HSL then Hamilton will share more thorough documentation!

Best of luck to you!

1 Like

You’re absolutely right, you know, and I didn’t properly consider that earlier. It is not like C in that C has so much documentation you could drown in it whereas the HSL docs are surprisingly thin and rely on external experience! It’s surprising given that Hamilton seem to have extensive documentation about pretty much everything, except for HSL it seems like…

1 Like

@BirdBare @Gareth

Here is a post about a way to get documentation for some HSL functions

Very useful! I’ll check it out. Thank you!

Thanks Stefan. The screenshot I posted was from there, some of the documentation in there is a bit sparse however.