minscript - a simple Java/C++ like script interpreter

Minscript  is an object oriented scripting language. The scripting language is a small subset of the C++ language. It has even more in common with Java than with C++. The aim of  the script language is not to execute all possible C++ programs, instead every valid minscript program should compile with a C++ compiler. Have a look at the sample script to get an impression of the syntax of the scripting language.

The main features of the minscript language are:
Not supported features of the C++ language are:
Features of the minscript program packag are:
Known bugs of  minscript are:

Sample script

Sample1.ic:

/* 
A simple sample script with some features
*/

#define MAX 512

const string c_sString = "C++ is nice.";

// a simple class to test the scope mechanismus
class MyTestClass
{
public:
// allways inlining !
MyTestClass( int i )
{
__println( "MyTestClass::MyTestClass(int) i="+i );
m_i = i;
}
~MyTestClass()
{
__println( "MyTestClass::~MyTestClass(int) i="+m_i );
}

int f()
{
return m_i*m_i;
}
private:
int m_i;
};

void TestFunction( string s, double d )
{
double dResult = d * d - 4.5;
string sTemp;

/* create a result string */
sTemp = s + " Result="+dResult;

// now print the string
__println( sTemp );
}

int main()
{
TestFunction( "Hello minscript world ! This is a function.", 9.123 );

__println( "test scope..." );
{
MyTestClass aObj( 7 );

__println( "aObj.f() = " + aObj.f() );
}
__println( "test scope done." );

return 0;
}

#ifdef __MINSCRIPT__
main();
#endif

The output of this script is (run: minscript Sample1.ic):

Hello minscript world ! This is a function. Result=78.729129
test scope...
MyTestClass::MyTestClass(int) i=7
aObj.f() = 49
MyTestClass::~MyTestClass(int) i=7
test scope done.


Buildin functions

int __print( string s )
prints a string to the standard output stream
int __println( string s )
prints a string to the standard output stream and appends a new line
int __errorln( string s )
prints a string to the error stream and appends a new line
void __sleep( int iDelay )
suspends the program execution for iDelay ms
int __loaddll( string s )
load the module with a given name, returns the handle for the module
int __unloaddll( int hDll )
frees the module
long clockms()
return the clock value in ms


int sizeof( expression ) returns the size of the expression type


int fopen( string sFileName, string sMode ) opens a file in sMode (usual file-modes from <stdio.h>)
int fclose( int hFile ) closes a file
int feof( int hFile ) checks a file for end-of-file status
int ferror( int hFile ) checks a file for error status
int fputs( string sText, int hFile ) writes a string into a file
int fgets( string & sText, int hFile ) reads a string from a file


int current_time_hour()
return the hour value of the current time
int current_time_minute()
return the minute value of the current time
int current_time_second()
return the second value of the current time
int current_date_year()
return the year of the current date
int current_date_month()
return the month of the current date
int current_date_day()
return the day of the current date


string getenv( string sName )
reads an environment variable
int putenv( string sNameValue )
writes an environment variable
void exit( int iValue ) exits the program imediately with the exit-code iValue
int system( string sCmd )
system call, runs (synchroniously) the command in the string sCmd
bool splitpath( string sFullPath, string & sDrive, string & sPath, string & sName, string & sExt )
splits a given path in substrings for drive, path, name and extension


int string_read() reads a string from the standard input and returns the string
int string_npos()
returns a integer constant to show that the find-function was not successfull
int string_length( string s )
returns the length of the string
char string_at( string s, int iPos )
returns the character in the string at the given position
string string_setchar( string s, int iPos, char ch )
returns a string with the changed character at the given position
int string_find( string s, string sSearch )
returns the position of the sSerach-string in the string s, returns string_npos() if the search string was not found
string string_substr( string s, int iStartPos, int iLength )
returns a substring of the given string
string string_insert( string s, int iPos, string sInsert )
returns a string in which the sInsert string is inserted in the string s
string string_erase( string s, int iPos, int iLength )
returns a string in which the given range is erased
string string_replace( string s, int iPos, int iLength, string sReplace )
returns a string in which a part of the string is replaced by another string


double fabs( double d )
returns absolute value of d
double sin( double d )
returns the sinus of d
double asin( double d )
returns the arcus-sinus of d
double sinh( double d )
returns the sinus hyperbolicus of d
double cos( double d )
returns the cosinus of d
double acos( double d )
returns the arcus-cosinus of d
double cosh( double d )
returns the cosinus hyperbolicus of d
double tan( double d )
returns the tangens of d
double atan( double d )
returns the arcus-tangens of d
double atan2( double d1, double d2 )
returns the arcus-tangens of d
double tanh( double d )
returns the tanges hyperbolicus of d
double sqrt( double d )
returns the squareroot of d
double exp( double d )
returns the e the power of d
double log( double d )
returns the logarithm of d
double log10( double d )
returns the logarithm for base 10 of d
double pow( double d1, double d2 )
returns the power of d1 by d2


Language extensions

__exists variablename    
verifys if a variable with the given name exists
__dbghalt expression sets an user brakepoint, the execution of the script will be stoped when this statement will be reached.
Dumps all functions and methods if expression has the value "fcn".
typeof variablename
prints the type of the variable


Predefined symbols of the preprocessor

__MINSCRIPT__   
is defined if the script is executed by the minscript application
__STDC__ is allways set
__cplusplus
is allways set
_WIN32
is defined if the script is executed on the windows plattform
__MINGW32__
is defined if the script is executed on the Windows/Mingw plattform
__OS2__
is defined if the script is executed on the OS/2 plattform
__ZAURUS__
is defined if the script is executed on the ZAURUS plattform
__ANDROID__
is defined if the script is executed on the Android plattform
__APPLE__
is defined if the script is executed on an Apple/MacOS plattform
__linux__
is defined if the script is executed on the linux plattform
__UNKNOWN__
is defined if the script is executed on an unknown plattform
_NDEBUG
is defined if the script is executed without the --debug option
_DEBUG
is defined if the script is executed with the --debug option


Commandline options

Start minscript with the option -? for a complete list of available options.


Module interface

To generate a module see the demo module example.

The folowing steps are necessary

All these steps are done in the script buildmodule.ic (minscript buildmodule.ic -a module_test.h).


License

The usage of minscript is free for non commercial use.

Please contact the author if you want to use minscript commercially.

Warning: The minscript package comes without any warranty. Use it at your own risk.



Contact

Author: michael.neuroth.de at googlemail.com
Homepage: http://www.mneuroth.de/privat/zaurus/minscript.html


Copyright

Minscript is written by Michae Neuroth, (c) 1999-2014.