News for hackers. Stuff that matters.
Re:Static files in Go by TazeTSchnitzel on Tuesday August 09, 2016 @10:34PM (#12259149)
It's quite a common use-case to embed binary data into binaries, so I wonder why more languages don't directly support it with some sort of directive in source code.

Interestingly the X Window System took the opposite approach for its images. Rather than making C accommodate their images, they made their images accommodate C! https://en.wikipedia.org/wiki/X_BitMap and https://en.wikipedia.org/wiki/X_PixMap are both image formats that consist of C code.

Re:Static files in Go by adrianratnapala on Wednesday August 10, 2016 @01:32AM (#12259679)
Individual platforms do seem to do it. If I understand Windows resources (and I don't really), they are just file blobs munged into the executable and then accessed through a simple sort of namespace.

Seen that way, resources are over-engineered. The basic compiler feature we weant is something like:

    const char blob[] = __include_binary__("blob.dat");

But if I could do that, then probably the next thing I would do is invent some macro-magic to provide a resource-like namespace on top of the feature.
Re:Static files in Go by pjc50 on Wednesday August 10, 2016 @06:41AM (#12260669)
Windows resources were originally built to fulfil two requirements:

- display an icon for an executable

- automatic localisation of application menus etc.

So FindResource() takes three parameters: a type (icon, string, dialog, bitmap, menu etc), a name, and a language ID. That means that changing the language ID can transparently select a different UI layout and text as required.

Meanwhile Explorer (and its ancestor Program Manager) will display the first icon in the resource file as the default program icon.

Resources are just a separate section within the PE executable format.

Re:Static files in Go by adrianratnapala on Wednesday August 10, 2016 @02:17PM (#12263755)
Thanks for the explanation.

So it sounds like the critical thing that Windows resources have over the thing I outlined is that they and their namespaces are relatively transparent to external tools such as the Program Manager.

The critical thing is that MS could impose a standard. Anyone can write tools to put such a section to their ELF binaries. But it would be useless because then no one would know to read it.

Re:Static files in Go by pjmlp on Wednesday August 10, 2016 @05:12AM (#12260417)
Windows, Mac OS, BeOS, Symbian and quite a few others offer direct support for it, it is just a matter of using the OS APIs.

This was already like that on the 16 bit days.

For example, with Turbo Pascal for Windows, you only needed to do, after generating the resources via the resource compiler

   {$R resource name}
and then make use of FindResource/LoadResource/LoadFromResourceName
Re:Static files in Go by lloeki on Wednesday August 10, 2016 @06:10AM (#12260586)
You can always (ab)use the linker! [0]

[0]: (shameless plug) http://stackoverflow.com/questions/8923097/compile-a-binary-...