slviajero/tinybasic

How to return a string as a function?

Closed this issue · 6 comments

I have in mind a function that would take no argument, but return a string (not the same one every time). I can't seem to make sense of things after reading the code. I have the feeling I need to push the length, and point ir2 towards the string but that's about it.

Could you confirm, or explain, please? Thanks.

If need be I could accept an argument, albeit bogus...

Oh this is excellent! Thanks a lot for this. I will try it this weekend, and see how it goes. The @x$ command looks like the best best. And lenstring() will be useful too: if there's nothing to return, it will return 0.

Hi! In between I managed to make it work, I have now a shiny @P$ read-only variable (thanks for that!) but I hit another issue, completely unrelated to strings. So I think I should close this, and start a separate issue (it is, I think, related to interrupts).

@P$ is for packet: I am compiling Tinybasic on a RAK4631 (nRF42840 + SX1262) and when a packet is received, a callback saves it into a buffer. But somehow the callback only fires when I try to access the variable. Weird. I'll detail this in a separate issue.

Meanwhile I'll have a look at your brand new basic.c.