Text arrays in custom types.

More
1 week 32 minutes ago #73 by fefa
Hello.

I’ve managed to use text arrays in a custom type. The idea was to use a field of type nat in the custom type and then use a parameter in a function to convert it into an array of nat, and from there be able to access the elements.I think I’m actually taking advantage of a weakness in the type checking system to achieve something that I probably should have done in a supported way, but which I don’t know about.Now that I see that in version 0.7.6 type checking in parameters is going to be improved, my code will probably stop compiling without errors.How should I do it, if the Lofi language is going to allow text arrays?Thanks in advance.

$FEFASample code:
Code:
type bbar {     byte x;     byte y;     byte size;     nat l; }; void drawBarAux(bbar bar, nat labels[]){     ...     print((text) labels[i]); // even cast is not necessary     ... } void drawBar(bbar bar) {     drawBarAux(bar, bar.l); } text lbls1[9] = {"1","2","3","4","0","5","6","7","8"}; text lbls2[9] = {"S","E","C","N","9","W","Z","B","b"}; bbar bar1 = { 1, 10, 9, &lbls1 }; bbar bar2 = { 80 - 4, 10, 9, &lbls2 }; drawBar(bar1); drawBar(bar2);

Please Log in or Create an account to join the conversation.

More
6 days 8 hours ago #76 by Franck
Replied by Franck on topic Text arrays in custom types.
This is totally legit as you basically store an address to a global array in your custom type. That goes to show you can do a lot with minimal language support. Well done !

Please Log in or Create an account to join the conversation.

More
3 days 22 hours ago #78 by fefa
Replied by fefa on topic Text arrays in custom types.
Thank you Franck for the reply.

Just if somebody takes this code as reference, the following one uses the size operator to get the size of the array:
Code:
type bbar {     byte x;     byte y;     byte size;     nat l; }; void drawBarAux(bbar bar, nat labels[]){     ...     print((text) labels[i]); // even cast is not necessary     ... } void drawBar(bbar bar) {     drawBarAux(bar, bar.l); } text lbls1[9] = {"1","2","3","4","0","5","6","7","8"}; text lbls2[9] = {"S","E","C","N","9","W","Z","B","b"}; bbar bar1 = { 1, 10, (byte) #lbls1, &lbls1 }; bbar bar2 = { 80 - 4, 10, (byte) #lbls2, &lbls2 }; drawBar(bar1); drawBar(bar2);

Please Log in or Create an account to join the conversation.

Time to create page: 0.163 seconds
Powered by Kunena Forum