home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.forth      Forth programmers eat a lot of Bratwurst      117,927 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 117,631 of 117,927   
   Anton Ertl to okflo@teletyp.ist   
   Re: making http request with gforth   
   24 Oct 25 15:34:47   
   
   From: anton@mips.complang.tuwien.ac.at   
      
   okflo@teletyp.ist writes:   
   >okflo@teletyp.ist writes:   
   >- I use global variables (in the dictionary) for curl-data and   
   >  response-code. What would be the right way to do this locally in   
   >  http-request? The usual locals are on a stack IMHO - so I would need   
   >  to allocate cells?   
      
   It seems to me that variable-flavoured locals would work here, i.e.:   
      
   : http-request ( method url-addr url-len -- status content-addr content-len )   
     {: w^ curl-data w^ response-code :}   
      
   And then use the rest of the code as-is.   
      
   >- What is the best way, to convert an sstring to a cstring? I was   
   >  wondering, that there is a cstring>sstring in gforth, but not the   
   >  other way sstring>cstring?   
      
   In gforth 0.7.9 there is a C function   
      
   char *cstr(Char *from, UCell size)   
      
   with that is available as a Forth word   
      
   cstr ( c-addr u -- c-addr2 )   
      
   by including unix/cstr.fs.  You need to FREE c-addr2 eventually.   
      
   >  : >cstring ( addr u -- c-string-addr )   
   >    [ s\" \0" ] 2literal s+ drop ;   
      
   That's also a way to do it, but you can also write it as:   
      
   : >cstring ( addr u -- c-string-addr )   
      s\" \0" s+ drop ;   
      
   Like CSTR, >CSTRING allocates the string, and you probably should FREE   
   it at some point.   
      
   >  s" GET" >cstring constant method-get   
   >  s" POST" >cstring constant method-post   
   >  s" PUT" >cstring constant method-put   
   >  s" DELETE" >cstring constant method-delete   
   >  s" PATCH" >cstring constant method-patch   
      
   In those cases you probably do not want to FREE the results   
   of >CSTRING.   
      
   - anton   
   --   
   M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html   
   comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html   
        New standard: https://forth-standard.org/   
   EuroForth 2025 CFP: http://www.euroforth.org/ef25/cfp.html   
   EuroForth 2025 registration: https://euro.theforth.net/   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca