Hi, I've been toying with the idea of designing a scripting language and developing a virtual machine that uses a bit of template meta programming to help bind a Cpp application (including classes etc) to it.
The three main constraints for the scripting language and interpreter I wanted were:
* Type strict (theoretically if done right should go faster than dynamic typed, easier to develop and optimize etc)
* API designed for use in Cpp applications (games especially), which separates scripts for use in event systems and other such things
* Provide an easy binding system because I dislike having boost for libraries such as luabind (because its just so damn bulky and annoying to carry around) and also because only one or two binding libraries allow you to bind to native functions with ease not the int func (vm *) kind which is annoying especially for binding existing, unchangable code.
In this respect I have named my scripting language e for embeddable. While its designed to be a lot like Cpp there are a few major differences. Oh and what I have designed so far is not completed. I've started documentation (a Lua like documentation style), but have to change most of it to suite the new syntax style as I recently did a big overhaul.
I'll post a few examples of the code so you can see the syntax. One of the main difference is that variable declarations are mixed up to be "identifier1[, identifier2...n]:type" instead of "type identifier1[, identifier2...n]" like in Cpp.
Scripts will be run via an entry point as well.
a few syntax examples
math:group -- this is a namespace in Cpp
{
vector3:def -- this defines a user-type (class/struct in Cpp)
{
public:
-- this declares three member variables
-- real is 32-bit float, for double use real8
x, y, z:real;
-*
declares a function that returns the length of the vector
'nil' is the same as void in Cpp
-*
length:real (nil)
{
-*
the sqrt function in the math group is accessed by a period symbol '.'
self member variables and functions require the preceding period symbol '.'
*-
return math.sqrt (.x * .x + .y * .y + .z * .z);
}
-*
declares a function that normalizes the vector
a function that returns nothing must specify 'nil'
nil is not actually required in a parameter list if there
are no parameters
-*
normalise:nil ()
{
len:real = .length ();
if (len == 0.0) len = 1.0;
.x /= len;
.y /= len;
.z /= len;
}
}
}
main:int (msg:string)
{
-* declares a reference (counted) to a string (which is new'd (gc keyword)).
not having the reference symbol ^ will only copy the string and the new'd copy will be garbage collected
*-
hello:^string = gc:string ("Hello");
console.print (hello + ", world! " + "OMG" + 1337); -* primitives are converted and added (or whatever other arithmetic) based on the l-value's type automatically *-
-- output is "Hello, world! OMG1337"
-- arrays are declared like the following
-- variable length arrays must be declared as a reference and be gc'd like Cpp
names:^ string [] = gc:string[10];
names_fixed:string[10] = { "My Name!" };
return false;
}
the api might look like this
eVirtualMachine * evm = eCreateMachine (eAPI_VERSION);
eScript * script = 0;
if (evm->compileFile ("examples.e", &script) == eOk) // script pointer address can be NULL
{
// script can be retrieved like this as well
// eScript * script = evm->getScript ("examples.e");
// parameters in stack will be treated using the script function decl
script->call ("main", "Hello, world!"); // main:int (msg:string)
}
the native types are:
char
short
int
byte
word
dword
real
real8
string
A few libraries will be implemented with the following: console, math, system, io, string
What do you think? Any suggestions? There's a fair amount that can be assumed to be exactly like Cpp like logic etc
[Edited by - thre3dee on September 21, 2006 2:40:20 AM]