Hey I've got functions that return values to work in my scripting language. I wrote this little test script to demonstrate how functions look and work in my language.
function int Test_Add(int a, int b)
{ return a + b;
}
function int Recursive_Test(int a)
{
if(a > 0)
{ print "Recursive call";
return Recursive_Test(a - 1;);
}
else
{ return a;
}
}
function void main(void)
{ int x = Recursive_Test(5;);
print x;
x = Test_Add(5; 5;) + 2;
print x;
}
Output:
Recursive Call
Recursive Call
Recursive Call
Recursive Call
Recursive Call
0
12
The entry point is main(). Functions are declared similar to C syntax with the added function keyword. A function is called the same as in C except a semicolon is needed after each parameter. Parameters can be complete expressions that may include other function calls.
Next I'll bind C functions to the language so it can be useful.