Finished C binding

posted in noaktree leaves
Published July 11, 2005
Advertisement
The implementation I discussed in my previous entry is fully operational. Thanks to you who replied to my last post. Your helpful feedback is always appreciated.

How it all panned out...

A C function we will bind to the SL (Scripting Language) will take the form:

C_To_Magus_Return Function_Name ( Magus_To_C_Parameter_List Parameter_List );

An example function prints two integers:

// A function to be bound to the magus language
C_To_Magus_Return Print_Two_Integers(Magus_To_C_Parameter_List Parameter_List)
{
int a, b;

// Get parameter 0
if(Parameter_List.Get_Integer_At_Parameter_Index(0, a) == false)
return C_To_Magus_Return(0);

// Get parameter 1
if(Parameter_List.Get_Integer_At_Parameter_Index(1, b) == false)
return C_To_Magus_Return(0);

// Print the integers
cout << "Integer 0: "<< a << " Integer 1: " << b << endl;

// Return type integer
return C_To_Magus_Return(1);
}

You can see that type checking parameters is now in place. The overloaded C_To_Magus_Return constructors check return types. This function is then bound with the following function:

bool Bind_C_Function(C_To_Magus_Return(*Function_Pointer)(Magus_To_C_Parameter_List), string Function_Name, vector Parameter_Type_List, MagusC_Parameter_Type_e Return_Type);

The function can then be called from within the SL either as a part of an expression or as a standard function call.

function void main(void)
{
int x = Print_2_Integers(1; 2;);
print x;

Print_2_Integers(3; 4;);
}

Output:
Integer 0: 1 Integer 1: 2
1
Integer 0: 3 Integer 1: 4

What's next...

So far I only have integer types working. Next I'll add support for the 5 float types. I'm still working out how I'll add access to the float vector elements. I'd like to add swizzling if possible.
Previous Entry Binding C functions
Next Entry Integer arrays
0 likes 6 comments

Comments

choffstein
Looks dandy to me, mate.
July 11, 2005 09:22 PM
jollyjeffers
I'll second that... Looks to me like a cleaner and slightly improved, yet essentially the same, as your original idea - good job [grin]

Do you have arrays built in yet? strikes me that they could be a useful generic foundation to vectorized floats.

If you created a means by which to throw arrays around you could have a series of specific typedef style aliases:

typedef float4 my_array<float>(4); //or whatever the syntax...

That would mean that you can define, and use, a float4 as a 4D vector and/or array.

Dunno if that sort of implementation is of any advantage to your goals though [smile]

Jack
July 12, 2005 03:39 AM
noaktree
Thanks to both of you.

I don't have arrays built in yet. Thanks for the idea of using them as a generic foundation for vector types. I'll add arrays for integers next then come back to the floats. I've reached a point where I've got some design thinking to do.

At any rate aren't you guys proud of me for sticking with a single project for this long. [smile]

I did manage to come up with a name for the language besides magus:

July 12, 2005 02:07 PM
Rob Loach
A2... Nice! The next version of it can be A3 [smile].
July 12, 2005 11:13 PM
jollyjeffers
Quote:Thanks for the idea of using them as a generic foundation for vector types.

It's strictly an idea that came from my current studies into the wonderful world of shaders/HLSL.. but representing vectors as arrays (and vice-versa) means you can use the same fundamental language features for a variety of different operations.

Quote:aren't you guys proud of me for sticking with a single project for this long.

[lol] Very proud!

Quote:A2... Nice! The next version of it can be A3 [smile].

Well if it's only a minor release shouldn't it be A2.1? or maybe, it should be Amajorminor : A21. I'll be quiet now..

Jack
July 13, 2005 03:34 AM
Daerax
Yayyy! Can I pronounce is A Square?


Quote:I'll be quiet now..


Yes, you should. :P hehe, just kidding!
July 13, 2005 10:19 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement