lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 03/04/2010 00:59, KHMan wrote:
Luciano de Souza wrote:
In C or Pascal, it's possible to create resources files. WaAV, GIFs, HTMLs or any type of file can be packed in a single binary filed, in Windows, a DLL file. Using directly the Lua features, is it possible also to create this type of file?

Normally you need the resource compiler. You can't do it in Lua unless you write your own resource compiler, and you'd need a linking step as well, so you may also need to write that. If you just need .rc -> .dll, it's of course possible to write a simplified version, or a small one with cut-down features. But I haven't heard of any scripting language implementing their own resource compiler.

In positive answer, what is the library responsible to write and read it?

Different compilers have different steps. MinGW/gcc for example, compiles .rc to .o files, but you wouldn't be able to mix that with Visual C++. So a lot will have to do with your intended application...

Besides, I think you can't embed WAVs, GIFs and HTMLs unless they're embedded as binary data in the resource.

If all you want to do is to have these files accessible to the app, you can archive them together (ZIP, TAR, ...) and append the archive to the DLL (or EXE), e.g.:

copy/b original.dll + archive.zip final.dll

And then in your code you can open the DLL as a regular file, locate the archive at the end and read from it. To locate the archive one usually writes its size at the end of the DLL and perform some seeks to locate its beginning:

1. seek to the end position minus four bytes (meaning the archive size is encoded as a four-byte integer)
2. read the archive size
3. seek to the end position minus the archive size minus four bytes
4. read the archive

Cheers,

Andre