import config; import testlibrary; import testshlibrary; import std.stdio; import catalog; void main(char[][] args) { // Internationalization Example Catalog.Init(config.PACKAGE, config.PACKAGE_LOCALE_DIR); writefln(Catalog.GetString("Hello!")); writefln(HelloWorldFactory.getName() ~ ", " ~ HelloWorldSharedObjectFactory.getVersion() ~ " " ~ config.VERSION); writefln("Compiled using: " ~ config.GDC_VERSION); // auto type inference and built-in foreach foreach (argc, argv; args) { // Object Oriented Programming CmdLin cl = new CmdLin(argc, argv); // Improved typesafe printf writefln(cl.argnum, cl.suffix, " arg: %s", cl.argv); // Automatic or explicit memory management delete cl; } // Nested structs and classes struct specs { // all members automatically initialized int count, allocated; } // Nested functions can refer to outer // variables like args specs argspecs() { specs* s = new specs; // no need for '->' s.count = args.length; // get length of array with .length s.allocated = typeof(args).sizeof; // built-in native type properties foreach (argv; args) s.allocated += argv.length * typeof(argv[0]).sizeof; return *s; } // built-in string and common string operations writefln("argc = %d, " ~ "allocated = %d", argspecs().count, argspecs().allocated); } class CmdLin { private int _argc; private char[] _argv; public: this(int argc, char[] argv) // constructor { _argc = argc; _argv = argv; } int argnum() { return _argc + 1; } char[] argv() { return _argv; } char[] suffix() { char[] suffix = "th"; switch (_argc) { case 0: suffix = "st"; break; case 1: suffix = "nd"; break; case 2: suffix = "rd"; break; default: break; } return suffix; } }