A few holes (imho) in the ecosystem of libraries

Adam D Ruppe destructionator at gmail.com
Mon May 15 13:21:39 UTC 2023


On Monday, 15 May 2023 at 13:04:57 UTC, Guillaume Piolat wrote:
>    * support a registry with font, parsed from system, but also 
> added manually

simpledisplay.d has a thing to pull out of the operating system, 
and then you can get the bytes to feed back into a stb 
ttf/freetype kind of thing, or just use it directly with the OS 
draw functions.

I like it quite a bit, since writing that (iirc 2019ish, with the 
get ttf bytes added in Sept 2021), I've used it in many places.

Doesn't do a custom added registry.... integrating that so the OS 
functions can read it might take some effort but if you just 
wanted loading that'd be a fairly easy add-on interface.

If someone were to write such a thing, I'd adopt it under my 
umbrella.

> 2. A I/O abstraction really suitable for parsing/emitting
>    * just ubyte[]
>    * no exceptions, instead provide a way to parse anyway (past 
> stream end) and get the error later, so that we don't need to 
> check for stream end (like stb does)
>    * parse base types with provided endianness
>    * good names, not so easy to come across
>    * abstract over (say) fread, ftell, fwrite, fseek, for 
> operations over files/memory
> ranges/lazy streams/growable memory ranges
>    * helpers to skip bytes, ensure remaining bytes, substream, 
> backtrack, etc.
>    * not overly templated, struct-based, even manual delegation 
> for wrapped I/O
>    I have done a variation of that badly for both audio-formats 
> and gamut, and it's annoyingly similar.



Yeah, I've done this a few times myself too and it is one of the 
things I'm putting in my new arsd.core lib (which was originally 
slated for release today, but I'm pretty far behind right now)

This is what I have so far:

https://github.com/adamdruppe/arsd/blob/7958a5eb939fadd55c3ae01c08bc60027d977430/core.d#L4889


The unittest shows how you might use it:


	auto fiber = new Fiber(() {
		position = 1;
		int a = stream.get!int(ByteOrder.littleEndian);
		assert(a == 10);
		position = 2;
		ubyte b = stream.get!ubyte;
		assert(b == 33);
		position = 3;
	});

	fiber.call();
	assert(position == 1);
	stream.feedData([10, 0, 0, 0]);
	assert(position == 2);
	stream.feedData([33]);
	assert(position == 3);


(the same interface can also fread() instead of getting fed data 
from outside with other subclass implementations, but I 
specifically wanted it to be fiber compatible like this, so a 
task can be put on hold waiting for new data, e.g., from a 
network socket or ipc pipe.)


I'm fairly happy with it but haven't used it in a real program 
yet so that might change. But the templated get/put things give 
you the types an then the virtual feed/flush convert that to just 
a byte array for transport.

Then my declarativeloader.d can be adapted to use this instead of 
its current fgetc and friends impl to be more generic to load up 
structs. (The only thing I've used it for right now is reading 
Java's .class files, but that covers a lot of common ground.)



Day job been keeping me busy during the day and kid during the 
night so I'm behind schedule on the arsd 11 tag, but I'm sure 
I'll be caught up and ready to tag in a couple more weeks so we 
can start really playing with this stuff.


More information about the Digitalmars-d mailing list