Jump to content
Sign in to follow this  
  • entries
    149
  • comments
    510
  • views
    95072

Finished C binding

Sign in to follow this  
noaktree

114 views

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.
Sign in to follow this  


6 Comments


Recommended Comments

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

Share this comment


Link to comment
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:

Share this comment


Link to comment
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

Share this comment


Link to comment
Yayyy! Can I pronounce is A Square?


Quote:
I'll be quiet now..


Yes, you should. :P hehe, just kidding!

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!