profile image

Nafis Ayaz

C++ Software Engineer

Espresso: Fundamentals

  • Espresso - A web-framework that is compatible to C++14 and above. This Tutorial will guide you to know what are the basics or fundamentals that espresso module provides. All the sub-modules of espresso has it's own and converts to executable code. Distributed to apt repository from where can be installed on Linux system.
  • Check Gcc version already install, must have gcc-7.5 or above. Follow the link: Get Started





    Module

    when a module is imported means actually the module is initialized and the instance is returned, the typeof instance

    espresso Module: When espresso module is imported - all the basics modules are initiated and the super module espresso instance is returned, the typeof espresso . Example: the macro of current directory __dir is initialized through which current directory is accessed.

    auto espresso = import("espresso"); // Standard super module
    console.log(__dir);
    // console is instatiated and macro __dir is initialized


    Console

    Console is super module in which log function and err function are defined.

    console.log function:

    auto espresso = import("espresso");
    console.log("hello world");


    Default type

    Default type: auto , beside this there are few more types are defined: var, Integer .

    auto type:

    auto espresso = import("espresso");
    auto n = 123;

    console.log( __typeof n);
    // int


    var type:

    auto espresso = import("espresso");
    var n = 123;

    console.log( __typeof n);
    // var


    Integer type:

    auto espresso = import("espresso");
    Integer n = 123;

    console.log( __typeof n);
    // Integer



    Typeof

    Default type: auto , beside this there are few more types are defined: var, Integer .

    __typeof macro:

    auto espresso = import("espresso");
    Integer n = 123;

    console.log(__typeof n);



    New

    Allocates dynamic memory allocation, __new macro is allocates a memory on heap and returns a pointer pointing to.

    __new macro:

    auto espresso = import("espresso");
    var n = __new 123;

    console.log(__typeof n);
    // Integer * type -> naked pointer causes memory leakage



    Scope

    Allocates dynamic memory allocation, __new macro is allocates a memory on heap and returns a pointer pointing to.

    __new macro:

    auto espresso = import("espresso");
    var n = scope(__new 123);

    console.log(__typeof n);
    // Integer * type -> No memory leakage: Deletes the pointer when goes out of scope



    Functions

    Espresso provides multiple function like: Callback function, Anonymous function and Lambda function

    Callback function:

    auto espresso = import("espresso");
    void say(void(*foo)(char*)){

       foo("hello world");

    }


    say( function(msg){

       console.log(msg);

    });
    //Call the say() and prints hello world


    Lambda function:

    auto espresso = import("espresso");
    auto func = function(x, y){

        return x + y;

    }

    console.log(func(2, 2));
    // 4





    Single-statement macro ( put c++ code after colon)

    __cplusplus: const char* s = "hello __cplusplus macro";


    Multi-statements macro ( Put multiple c++ codes in inside the curly-braces)

    __cplusplus{
       const char* s = "hello __cplusplus macro";

       // do some more stuffs with C++ ...

    }

    console.log(s);// Correct


    Compile-time warnings:

    function say() {
        console.log(" hello");

    } // Warning

    function say() {
        char* s = "hello";

        return s;

    } // NO Warning


    Compile-time warnings: __no_return

    __no_return function say() {
        console.log(" hello");

    } // No Warning


    Current directory

    Espresso has it's in-built current directory path, __dir return current dirname where main application running.

    __dir macro:

    auto espresso = import("espresso");
    console.log(__dir);







    APIs reference documentation, provides details information about all fuctions and objects of Espresso, this documentation expalins every APIs in more details, so to implement easily C++ projects and all APIs are complete compatible with C++11/14/17. Espresso is very fast web-framework hybrid of C++, the main objective is just to make it easy and simple for C++ developers. This framework is built on top of C++14 and above
    NOTE: It's the first version: Espresso_v_1.0.0, so there may occur some exeptions-throw, error or you find any idea.
    Kindly contact me: sir.ayaz47@gmail.com