TypeToString function?

Is there a TypeToString function? The equivalent of EnumToString, but for custom defined types?

Use case: I want to call AddBookmark, passing in a typename. At present I am having to do this manually e.g. AddBookmark(pos. name, “MyType”, …), when I’d really like to write AddBookmark(pos, name, TypeToString(MyType), …)

Is this possible?

EDIT: Even passing the type as a string seems not to work. WRT ADF.bt, passing “DATABLOCKOFS” does not seem to make the type stick in the Bookmarks view; it just displays “DATABLOCKOFS” rather than “struct DATABLOCKOFS”. If I then Edit the bookmark manually, but just press “Update” without changing anything, the text changes to “struct DATABLOCKOFS” and the type takes. Is this user error or a bug?

Hello howprice. There is currently no TypeToString function and that is something we’d have to add in. For passing the type as a string, I just tried calling the AddBookmark function in a script and the type was picked up correctly right away. Are you calling AddBookmark in a script or a template? There could be a bug in calling AddBookmark from a template. If you are calling it from a script, could you check and see if you can consistently replicate the problem? The script should be run after the template to make sure the types are available.

Graeme
SweetScape Software

Hi Graeme. Thanks for getting back to me.

I’m pleased that this is working as expected for you. I am calling AddBookmark from a template.

I don’t seem to be able to attach a file to this post, but yesterday I submitted an updated version of ADF.bt to the Repository for review. I think have left the non-working code in the _checkRootblockChecksum function. If you have access to this and can repro and maybe advise how to get this working it would be great thanks.

void _checkRootblockChecksum(int blockNumber, BlockType blockType)
{
	local int64 blockAddr = blockNumber * BSIZE;
	local uint32 checksum = ReadUInt(blockAddr + (4 * kRootblockChecksumMemberLongwordIndex));
	local uint32 expectedChecksum = calculateRootblockChecksum(blockAddr);
	if (checksum != expectedChecksum)
	{
		local string filename = getFileHeaderBlockName(typedatablock.header_key);
		Printf("Invalid %s checksum. Block index %03Xh  Address: %05Xh  Checksum: %08Xh  Expected: %08Xh  File: %s\n", 
			EnumToString(blockType), blockNumber, blockAddr, typedatablock.chksum, expectedChecksum, filename);

		// TODO: Try to add a bookmark. See https://forum.sweetscape.com/t/typetostring-function/138
		// local string bookmarkName = Str("Invalid %s index %03Xh", EnumToString(DataBlock), blockNumber);
		// local string typename = "DATABLOCKOFS"; // TODO: Does a TypeToString function exist?
		// AddBookmark(blockAddr, bookmarkName, typename, -1, cNone, cRed);
	}
}