j
: Next unread message k
: Previous unread message j a
: Jump to all threads
j l
: Jump to MailingList overview
Could someone provide me with a code example on how to combine two strings together in forth please. Here is my attempt. For some reason it doesn't work. Any help would be great.
\ (addr len -- )
: loadLocalVariable dup 9 + dup
r
alloc-mem " variable " rot dup
r
swap move r> r> + swap 3dup move 9 + dup
r
- r> eval drop ;
All this code does this basically
sprintf(defineVariableCommandString, "variable %s", variableString); feval(defineVariableCommandString);
Boy I love C.
Attachments:
On 2010-8-31 8:06 PM, Programmingkid wrote:
Could someone provide me with a code example on how to combine two strings together in forth please. Here is my attempt. For some reason it doesn't work. Any help would be great.
The below takes two strings of the form (addr len), allocates a chunk of memory for them, and concatenates them into that allocated memory, returning addr len.
: $cat2 ( $1 $2 -- $3 ) 2 pick over + dup >r alloc-mem >r 2swap tuck r@ swap move ( $2 $1-len ) r@ + swap move ( ) r> r> ;