🎉 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!

Abusing Bindings for Tools

Started by
0 comments, last by WitchLord 9 years ago

While writing C++/CLI bindings I was getting pretty tired of it, so I started looking around for an alternative means to speed up the process. With a hefty amount of existing Angelscript bindings it seemed sensible to parse the script registration methods...

Then it clicked that I could just write an implementation of asIScriptEngine abstract class that did nothing but build data about the script bindings.

The "SpoofEngine" does absolutely nothing except with methods that perform registrations, instead of actually binding anything it just uses the given information to build an XML document. By redefining the asMETHOD/asFUNCTION (and their PR versions) to return a junk asFuncPtr while recording their method/function name into the Spoof singleton so I'd have the C++ method/function name/signature to use for constructing a binding from the data. All other functions do nothing.

It was incredibly simple as the script engine registration methods are very crystal clear as to what's going on (took at most 30 minutes), all that's needed to be done to build the data is run the existing script registration process with the "Spoof" script engine. No fuss and minimal muck.


<type name="Sphere">
			<behavior type="0" declaration="void f()" cfunction="ConstructSphere" />
			<behavior type="0" declaration="void f(const Sphere&amp;in)" cfunction="ConstructSphereCopy" />
			<behavior type="0" declaration="void f(const Vector3&amp;in, float)" cfunction="ConstructSphereInit" />
			<behavior type="0" declaration="void f(const BoundingBox&amp;in)" cfunction="ConstructSphereBoundingBox" />
			<behavior type="0" declaration="void f(const Frustum&amp;in)" cfunction="ConstructSphereFrustum" />
			<behavior type="0" declaration="void f(const Polyhedron&amp;in)" cfunction="ConstructSpherePolyhedron" />
			<method declaration="Sphere&amp; opAssign(const Sphere&amp;in)" cmethod="operator =" signature="(const Sphere&amp;)" return="Sphere&amp;" />
			<method declaration="bool &amp;opEquals(const Sphere&amp;in) const" cmethod="operator ==" />
			<method declaration="void Define(const Vector3&amp;in, float)" cmethod="Define" signature="(const Vector3&amp;, float)" return="void" />
			<method declaration="void Define(const BoundingBox&amp;in)" cmethod="Define" signature="(const BoundingBox&amp;)" return="void" />
			<method declaration="void Define(const Frustum&amp;in)" cmethod="Define" signature="(const Frustum&amp;)" return="void" />
			<method declaration="void Define(const Polyhedron&amp;in)" cmethod="Define" signature="(const Polyhedron&amp;)" return="void" />
			<method declaration="void Define(const Sphere&amp;in)" cmethod="Define" signature="(const Sphere&amp;)" return="void" />
			<method declaration="void Merge(const Vector3&amp;in)" cmethod="Merge" signature="(const Vector3&amp;)" return="void" />
			<method declaration="void Merge(const BoundingBox&amp;in)" cmethod="Merge" signature="(const BoundingBox&amp;)" return="void" />
			<method declaration="void Merge(const Frustum&amp;in)" cmethod="Merge" signature="(const Frustum&amp;)" return="void" />
			<method declaration="void Merge(const Sphere&amp;in)" cmethod="Merge" signature="(const Sphere&amp;)" return="void" />
			<method declaration="void Clear()" cmethod="Clear" />
			<method declaration="Intersection IsInside(const Vector3&amp;in) const" cmethod="IsInside" signature="(const Vector3&amp;) const" return="Intersection" />
			<method declaration="Intersection IsInside(const Sphere&amp;in) const" cmethod="IsInside" signature="(const Sphere&amp;) const" return="Intersection" />
			<method declaration="Intersection IsInside(const BoundingBox&amp;in) const" cmethod="IsInside" signature="(const BoundingBox&amp;) const" return="Intersection" />
			<method declaration="float Distance(const Vector3&amp;in) const" cmethod="Distance" />
			<field declaration="Vector3 center" />
			<field declaration="float radius" />
			<field declaration="bool defined" />
		</type>

The results are incredibly easy to parse and make sense of for use in generating code (with the exception of the "return" attribute, which is just the explicit ret-value for an asMETHODPR binding).

Reusing all that effort on scripting bindings means weeks I won't spend writing C++/CLI or band-aiding my way around missing functionality that I'm used to having in Angelscript.

Nevermind that bindings that match so closely is incredibly convenient.

Advertisement

It might just be that I'm tired right now, but I fail to understand what you plan on doing with the data you now have in the XML.

Something that I feel would be a very useful auto-binding tool, would be one that is capable of parsing C++ code and generate potential bindings automatically, then store that in an XML that can be adjusted by the developer to decide if something should be registered in a different way, or not registered at all. The tool should then be able to detect if the C++ code changed to alert the developer that the binding may need to be adjusted too.

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