Fork me on GitHub

Nothing can kill Maccy, not even fire.

Welcome!

Macaroni for C++ parses a sleeker version of C++ that resembles Java or C# and generates C++ code, managing the physical structure of your project for you.

It also lets you to manipulate the model it creates using Lua scripts so you can easily generate code.

A Simple Example

The following single file of Macaroni code creates a class named "Calculator" with it's own .h and .cpp files which goes into a library (or DLL). It also creates two executable programs (i.e. exe files) to add and subtract numbers.

~import Calculator;
~import std::cin;
~import std::cout;
~import std::ostream;

class Calculator {
    private int number;

    public:
        Calculator(int number) : number(number) {}
        void add(int other) { number += other; }
        int result() { return number; }
        void subtract(int other) { number -= other; }
};

~unit "add" type=exe { ~block "cpp" {
        int main(int argc, char ** argv) {
            int n1, n2;
            cout << "Number 1? "; cin >> n1;
            cout << "Number 2? "; cin >> n2;
            Calculator c(n1);
            c.add(n2);
            cout << c.result() << "\n";
        }
}   }

~unit "subtract" type=exe { ~block "cpp" {
        int main(int argc, char ** argv) {
            int n1, n2;
            cout << "Number 1? "; cin >> n1;
            cout << "Number 2? "; cin >> n2;
            Calculator c(n1);
            c.subtract(n2);
            cout << c.result() << "\n";
        }
}   }

There's no need for header files along or other anachronisms such as include guards to do simple things. Macaroni lets you think about your code in terms of nodes to be imported rather than header files to be included, letting you focus on the logical structure of your program.

Because Macaroni copies the full blocks of C++ code you give it into the code it generates (and uses the #line directive) compiler error messages and debuggers call out the spot you made a mistake in the Macaroni source code instead of forcing you to reason about the generated source.

Yet Macaroni is about more than just avoiding the need to write header files. It allows you to add metadata to your source code which it can use to generate more code (such as glue for scripting languages) or even build scripts (CMake and Boost Build support is included out of the box). These powerful tools enable you to tackle the classic problems with the physical structure of C++ code as well as the lack of readily available runtime reflection mechanisms.

Curious? Click here to get started!



Copyright 2014 Tim Simpson, released under the Apache License