PEEK and POKE
Jun 1, 2012 8:57:59 GMT 1
Post by Deleted on Jun 1, 2012 8:57:59 GMT 1
Peter,
I have finally gotten around to addressing the PEEK & POKE functionality in ScriptBasic as one of the new features in version 3. I'm building an extension module called SB3 which will be used as a code pool for inclusion into the core scriba interpreter. I have the following functions working as the first round of submissions to the SB3 project.
I'm leaning towards using a variation of PEEK that returns the correct value given the type.
Example:
PEEKB - BYTE
PEEKI - INTEGER
PEEKL - LONG
PEEKD - DOUBLE
PEEKF - FLOAT
PEEK alone assumes a BYTE and supports the length optional parameter. All other variations are one TYPE at a time. I could see down the road adding a template like option to extract complex structures and assign them to meaningful associative/mixed SB arrays.
Was the option method easier to implement in BaCon?
I have finally gotten around to addressing the PEEK & POKE functionality in ScriptBasic as one of the new features in version 3. I'm building an extension module called SB3 which will be used as a code pool for inclusion into the core scriba interpreter. I have the following functions working as the first round of submissions to the SB3 project.
- DIM - Fast way to initialize a single dimension array with a few tricks.
- FGET - File to string. (no need to OPEN, read or figure out it's length)
- FPUT - String to file. (same applies here as well)
- STRPTR - Returns the pointer to any SB string variable.
- VARPTR - Returns the pointer to any SB numeric variable.
- PEEK - Returns a string starting at the address given and the number of bytes requested.
- POKE - Assign memory a string of bytes starting and the address provided.
DECLARE SUB STRPTR ALIAS "STRPTR" LIB "cbx"
DECLARE SUB VARPTR ALIAS "VARPTR" LIB "cbx"
DECLARE SUB PEEK ALIAS "PEEK" LIB "cbx"
a = "ABC"
v = STRPTR(a)
PRINT PEEK(v,2),"\n"
PRINT PEEK(a,2),"\n"
v = STRPTR(MID(a,2))
PRINT PEEK(v,2),"\n"
PRINT PEEK(MID(a,2),2),"\n"
PRINT PEEK(v+1,1),"\n"
b = 1 + 2
v = VARPTR(b)
PRINT v,"\n"
PRINT PEEK(v,1),"\n"
PRINT ASC(PEEK(v,1)),"\n"
I'm leaning towards using a variation of PEEK that returns the correct value given the type.
Example:
PEEKB - BYTE
PEEKI - INTEGER
PEEKL - LONG
PEEKD - DOUBLE
PEEKF - FLOAT
PEEK alone assumes a BYTE and supports the length optional parameter. All other variations are one TYPE at a time. I could see down the road adding a template like option to extract complex structures and assign them to meaningful associative/mixed SB arrays.
Was the option method easier to implement in BaCon?