Monday, July 31, 2017

Copying slots in the P/Invoke tool

This tool really needs a name, because typing out "my P/Invoke command-line tool" is going to get dry pretty quick.

Today I added a copyslot instruction that (surprise!) copies the contents of one slot to another.

newslot int oneInt = 3;
newslot int anotherInt = 2;
copyslot anotherInt = oneInt;
readslot anotherInt

That outputs 3. The instruction also has the option of specifying a field ID in a structure:

newslot block someBlock = int 4, byte 5;
newslot byte oneByte = 0;
copyslot oneByte = someBlock field 1;
readslot oneByte

That outputs 5, because field 1 of the block (numbering starting at zero) contains the byte 5. Finally, the instruction can use a raw byte offset:

newslot block someBlock = int 4, byte 5;
newslot byte oneByte = 0;
copyslot oneByte = someBlock offset 4;
readslot oneByte

That again outputs 5, because at byte 4 (zero-based), after four bytes' worth of int, there's the byte.

Unrelatedly, there's now a GUID kind that (no surprise) produces GUID structures.

No comments:

Post a Comment