Original Post
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
the api might look like this the native types are:
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:<font color=blue>group</font> <font color="#5D8B9A">-- this is a namespace in Cpp</font>
{
vector3:<font color=blue>def</font> <font color="#5D8B9A">-- this defines a user-type (class/struct in Cpp)</font>
{
<font color=blue>public</font>:
<font color="#5D8B9A">-- this declares three member variables
-- real is 32-bit float, for double use real8</font>
x, y, z:<font color=blue>real</font>;
<font color="#5D8B9A">-*
declares a function that returns the length of the vector
'nil' is the same as void in Cpp
-*</font>
length:<font color=blue>real</font> (<font color=blue>nil</font>)
{
<font color="#5D8B9A">-*
the sqrt function in the math group is accessed by a period symbol '.'
self member variables and functions require the preceding period symbol '.'
*-</font>
<font color=blue>return</font> math.sqrt (.x * .x + .y * .y + .z * .z);
}
<font color="#5D8B9A">-*
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
-*</font>
normalise:<font color=blue>nil</font> ()
{
len:<font color=blue>real</font> = .length ();
<font color=blue>if</font> (len == 0.0) len = 1.0;
.x /= len;
.y /= len;
.z /= len;
}
}
}
main:<font color=blue>int</font> (msg:<font color=blue>string</font>)
{
<font color="#5D8B9A">-* 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
*-</font>
hello:<font color=blue>^string</font> = <font color=blue>gc</font>:<font color=blue>string</font> (<font color=red>"Hello"</font>);
console.print (hello + <font color=red>", world! "</font> + <font color=red>"OMG"</font> + 1337); <font color="#5D8B9A">-* primitives are converted and added (or whatever other arithmetic) based on the l-value's type automatically *-
-- output is "Hello, world! OMG1337"</font>
<font color="#5D8B9A">-- arrays are declared like the following
-- variable length arrays must be declared as a reference and be gc'd like Cpp</font>
names:<font color=blue>^ string</font> [] = <font color=blue>gc</font>:<font color=blue>string</font>[10];
names_fixed:<font color=blue>string</font>[10] = { <font color=red>"My Name!"</font> };
<font color=blue>return false</font>;
}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)
}
<font color=blue>char
short
int
byte
word
dword
real
real8
string</font> 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]