MewaScript is a dynamic language that aims to offer the flexibility of developing with a high level programming language and the performance of C/C++, a compiled language. This aim could only be achieved by designing a completely new programming language that throughout its design would bridge very well with C/C++. MewaScript bridges with C/C++ in 2 ways,
- Easy porting of scripts to C/C++ code, and vice versa.
- Easy integration of C/C++ code as a linked library.
Lets compare side by side 2 examples, the first written in C++ and the second written in MewaScript Both examples implement a min function, that returns the minimum of 2 values and print the result.
Comparing the above snapshots we can observe that,
- MewaScript reduces the amount of typing when compared to C++;
- There are no forward declarations and no header files; everything is declared exactly once;
- Initialization is expressive, automatic, and easy to use, to initialize a string just type (str="my string";)
- Syntax is clean and light on keywords;
Mewa is very versatil, although functions do not need to declare its input argument data types, Mewa offers the option to declare them. Below we have an example,
|Mewa function with declared input data types|
|Example of function overloading |
|Default values in parameters |
Till now we have seen functions passing argments by copy, this means that the arguments a and b are copies and can be modified inside the function without affecting any variable outside the function. Like C++, MewaScript also allows to pass arguments to functions by reference. This is a practical feature that allows, inside functions, to modify variables send as arguments.
In MewaScript function arguments are always passed by reference. This decision might change in the future, but it was adopted because it simplifies both the language syntax and interpreter engine. Below is an example of a function that swaps the values of its arguments.
|Mewa function passing arguments by reference|
MewaScript was designed from ground up to take advantage of dynamic programming, and at the same time, provide a very similar syntax compared to C/C++/Java, to save developers from learning a new programming language and make MewaScript code easily portable to C/C++/Java. The diferences between compiled languages and MewaScript start appearing when we create classes, and that's what I will talk about in a future post.