Autoconversion - Spicery/Nutmeg GitHub Wiki

Autoconversion is a great answer to the common problem of how to make resources available to your program at runtime. It allows you to provide files to the compiler that will get baked into the program-bundle that is the output of the compiler. Your program can then access them as ordinary variables at runtime.

For example, let's suppose you wanted to display an image (background.jpg) as part of a fancy splash screen. All you need to do is tell the compiler that you want the image to be available like this:

% nutmegc --bundle=myprogram.bundle myprogram.nutmeg background.jpg
% 

Now your program can refer to the image via the variable background:

   splashScreen.setBackgroundImage( background )

Autoconversion is the name for the process of packaging the JPG image into the bundle, declaring the variable, loading the image from the bundle-file at point of demand into an Image object. You don't have to locate resources on disk through arcane system-calls, find the right way to parse a JPG rather than a GIF, or write the dynamic loading/unloading code. Autoconversion handles the entire process for you.

Autoconversion is able to handle folders of resources, fairly large assets (~1GB) and also large numbers of individual resources. The limitations on resources mainly come from the limitations on the bundle format (SQLITE). You can incrementally add resources to a nutmeg bundle by using the nutmegc command repeatedly e.g.

% nutmegc --bundle=myprogram.bundle images/*.jpg
% nutmegc --bundle=myprogram.bundle html/*.html
% find data/ -iname '*.csv' | xargs nutmegc --bundle=myprogram.bundle

Autoconversion recognises:

  • Common image formats (JPG, GIF, PNG, etc)
  • Text formats (TXT, MD, XHTML)
  • Popular data formats (CSV, XML, JSON, SQLITE)
  • Folders are recursively expanded into map objects.