Core Function PTRWrite
From Sputnik Wiki
(Difference between revisions)
(→Example) |
m (1 revision) |
||
(5 intermediate revisions by one user not shown) | |||
Line 17: | Line 17: | ||
<pre> | <pre> | ||
[TYPE] [WHAT IT IS] | [TYPE] [WHAT IT IS] | ||
+ | r Raw bytes | ||
c ASCII char | c ASCII char | ||
C UNICODE char | C UNICODE char | ||
Line 29: | Line 30: | ||
f float | f float | ||
d double | d double | ||
+ | t pointer | ||
</pre> | </pre> | ||
+ | |||
+ | ==== offset ==== | ||
+ | |||
+ | Offset to add to the pointer. | ||
+ | |||
+ | ==== value ==== | ||
+ | |||
+ | The value to write to the pointer at the given offset. | ||
=== Return Value === | === Return Value === | ||
Line 72: | Line 82: | ||
Free($PTR); | Free($PTR); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Example of writing raw bytes to the pointer | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | $Value = "Hello World!"; | ||
+ | $PTR = Alloc(StrLen($Value) + 1); | ||
+ | $Bytes = Pack("A*", "Hello World!"); | ||
+ | PTRWrite($PTR, "r", 0, $Bytes); | ||
+ | $String = PTRToString(0, $PTR); | ||
+ | echo $String; | ||
+ | Free($PTR); | ||
+ | # Prints | ||
+ | # Hello World! | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:37, 14 June 2015
PTRWrite( <ptr>, <type>, <offset>, <value> )
Contents |
Description
Write data to a memory pointer optionally starting from a given index.
Parameters
ptr
The pointer to use.
type
The type of data to read
[TYPE] [WHAT IT IS] r Raw bytes c ASCII char C UNICODE char b unsigned byte B signed byte s signed int16 i signed int32 l signed int64 S unsigned int16 I unsigned int32 L unsigned int64 f float d double t pointer
offset
Offset to add to the pointer.
value
The value to write to the pointer at the given offset.
Return Value
Success: Returns 1.
Failure: Returns 0.
Remarks
None.
Example
$PTR = Alloc(300); PTRWrite($PTR, "f", 0, 133.77); PTRWrite($PTR, "l", 4, 777); PTRWrite($PTR, "i", 12, 1221); Println( PTRRead($PTR, "f", 0) ); Println( PTRRead($PTR, "l", 4) ); Println( PTRRead($PTR, "i", 12) ); Free($PTR);
This uses a string
$PTR = Alloc(300); PTRWrite($PTR, "f", 0, 133.77); PTRWrite($PTR, "l", 4, 777); PTRWrite($PTR, "i", 8, StringToPTR(0, "Hello World")); PTRWrite($PTR, "i", 12, 1221); Println( PTRRead($PTR, "f", 0) ); Println( PTRRead($PTR, "l", 4) ); Println( PTRToString(0, PTRRead($PTR, "i", 8)) ); Println( PTRRead($PTR, "i", 12) ); Free($PTR);
Example of writing raw bytes to the pointer
$Value = "Hello World!"; $PTR = Alloc(StrLen($Value) + 1); $Bytes = Pack("A*", "Hello World!"); PTRWrite($PTR, "r", 0, $Bytes); $String = PTRToString(0, $PTR); echo $String; Free($PTR); # Prints # Hello World!