ams-hackers / gbforth

👾 A Forth-based Game Boy development kit
https://gbforth.org
MIT License
121 stars 23 forks source link

Strings lib #338

Open tkers opened 2 years ago

tkers commented 2 years ago

Some extra words for working with strings.

Appending strings +PLACE (sometimes known as append) is already added to the core lib, as it's a very common (even if non-standard) word.

Appending characters or numbers This strings lib adds c+place and #+place for appending a single character or numeric value to a string. Not sure about existing name conventions? This used to be cappend and #append, but being consistent with +place probably makes sense.

Longer counted strings gbforth supports counted strings (and the related words place and count) that use a single char for storing the string length. This limits the length of counted strings to 255 characters.

Some forth systems use a cell (2 chars) for this, so longer strings are allowed, at the expense of using a bit more bytes for storage. While using strings that are longer than 255 characters might not be very common, it might be nice to support them anyway so that things ✨ just work ✨

Alternatively, we can include a longer-strings.fs lib that redefines the words place and +place (and any other related words) to use a cell count rather than a char count.

Todo