Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Memory access (was: External library interface)

 [1/1] from: lmecir::mbox::vol::cz at: 3-Jul-2003 11:38


Hi all, Cyphre asked me to add some refinements, so here are my newest results: a: "123^(0)45" adr: address? a get-mem? adr ; == #"1" get-mem? adr + 1 ; == #"2" get-mem? adr + 2 ; == #"3" get-mem? adr + 3 ; == #"^@" get-mem? adr + 4 ; == #"4" get-mem? adr + 5 ; == #"5" get-mem? adr + 6 ; == #"^@" get-mem?/nts adr ; == "123" get-mem?/part adr 7 ; == "123^@45^@" get-mem?: function [ {get the byte from a memory address} address [integer!] /nts {a null-terminated string} /part {a binary with a specified length} length [integer!] ] [m] [ address: make struct! [i [integer!]] reduce [address] if nts [ m: make struct! [s [string!]] none change third m third address return m/s ] if part [ m: head insert/dup copy [] [. [char!]] length m: make struct! compose/deep [bin [struct! (reduce [m])]] none change third m third address return to string! third m/bin ] m: make struct! [c [struct! [chr [char!]]]] none change third m third address m/c/chr ]