🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to Interface with C/C++?

Started by
6 comments, last by WitchLord 18 years, 7 months ago
I'm trying to see if an existing language already supports this and/or how hard it would be to add to AngelCode. I would like to be able to inside the script declare a structure struct { int Name; char Address[40]; } MyStruct; then pass this to the C/C++ code as a Raw data which would effectivly be 44 bytes of data. Easy, Hard? How about dynamically defining a struct MySize = 20; struct { int Size; char Data[MySize] } Zam. // lessbread edit - added a title
Advertisement
AngelScript doesn't let you define structures with that much control. First of all the array wouldn't be inline, but instead would be a pointer to an array object. Secondly the script declared structures hold extra data, such as reference counter, type id, etc.

If you need to do this with AngelScript, it would probably be better for you to write a set of application functions that would let the script define a data structure and then interact with it as raw data.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

There are other languages that let you do this however. VBA comes to mind immediately. So does SAS.
Pardon me for being a grump, but what do those other languages have to do with AngelScript? The main point of AngelScript IMHO is speed, ease of use, C/C++ coding similarities, and quick binding to existing code. Its just not a fair comparison to say something like that. Perhaps withlord will work on those items, but thats if they will benefit the current users. In short, yes you can do that in VBA and SAS (don't quite know what this is), but how many cross platform games use those as scripting languages?
Quote: Original post by WitchLord
AngelScript doesn't let you define structures with that much control. First of all the array wouldn't be inline, but instead would be a pointer to an array object. Secondly the script declared structures hold extra data, such as reference counter, type id, etc.

If you need to do this with AngelScript, it would probably be better for you to write a set of application functions that would let the script define a data structure and then interact with it as raw data.


Is there a easy way to pass the struct so that the C/C++ could access it in an array method such as:

for (i=0;i<Struct.ElementCount;i++) Struct.Element = MyData;

But it would need to be very quick; as I'm looking to needing to fill the data structures in RealTime.

_Zam_

:edited to fix spelling mistake. :)

[Edited by - _Zam_ on November 10, 2005 11:49:56 AM]
lxnyce:

_Zam_ stated that he was looking for a language that could do what he needs. SiCrane just offered a couple of options that is able to do what he wants. AngelScript, just like any other language, can't be the best choice as solution for all problems. It's good to know which options you have.

_Zam_:

The application can access script structures and arrays through the interfaces asIScriptStruct and asIScriptArray. As they have to be generic these are obviously not as fast as structures and arrays defined in C++, but for most occasions they should be fast enough, and if you need more speed maybe you should consider another solution than scripting.

If you can predefine the structures in the application, instead of relying on the scripts to declare them, then you will be able to make it even more efficient as AngelScript allows the application to decide practically everything in how an application registered object is handled.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Quote: Original post by WitchLord

The application can access script structures and arrays through the interfaces asIScriptStruct and asIScriptArray. As they have to be generic these are obviously not as fast as structures and arrays defined in C++, but for most occasions they should be fast enough, and if you need more speed maybe you should consider another solution than scripting.

If you can predefine the structures in the application, instead of relying on the scripts to declare them, then you will be able to make it even more efficient as AngelScript allows the application to decide practically everything in how an application registered object is handled.


Hmm, Thanks; More Q's. :)

What type of performance hit do you see with passing structured information between AngleScript and the compiled layer.

Which would be faster?

1. Declaring the structure in AS, and accessing it in C using asIScriptStruct, or
2. declaring the structure in C and then accessing its members in AS?

_Zam_



It's difficult to say what the performance hit will be. But if the structure is passed by address then the performance hit is very low. Obviously AngelScript (as any other scripting language) is slower than C++, so the less time spent in the script the faster the program will be.

As AngelScript can access the struct members directly through an offset, this is much more efficient than when C++ has to access script declared structure members. This is because the script declared structure members has to be enumerated by the application in order to access them. Though if performance is of importance, I guess you could do the enumeration once and then always use the same offset to access the members.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement