Advertisement

Importing functions that use objects of classes defined in script

Started by March 24, 2009 01:30 PM
5 comments, last by WitchLord 15 years, 8 months ago
Hello, I have some class defined in header file: class CFacility { ... } Then, in some module, I'm managing the array of objects of type CFacility. So I want to expose following function to other modules: CFacility@ GetFacility(...) In that modules, I'm using: import CFacility@ GetFacility(...). This modules include header file with class definition, so everything compiles ok. But I got error during scripts binding, all modules that have aforementioned import, can't be bound. PS. Sorry if I'm not providing as much details as needed - I don't have access to the host application.
A class built in one module is not treated as the same class built in another module, even if the script is the same. If you call GetTypeIdByDecl() for the class on both modules, you'll see that the id is different. This is because they may be accessing global variables, etc, that would be different from the two.

Interfaces however are treated the same if they are using only common types. Thus the solution is implement your scripts as follows:

interface IFacility {...}import IFacility @GetFacility(...) from "module";


The class that is to be accessed from the other module must then implement that interface.

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

Advertisement
Great,

Not only it works, but it also makes sense :)

Thanks!
Hmm, but that doesn't solve all my problems.

I have following scenario:

Include file (production_h): class and interface definitions
Main module (production): list of handlers to the IFacility interface objects

Other module (prod_still_rotgut): class that derives from CFacility - CRotgutFacility. In that module I am using AddFacility(IFacility@) method, imported from main module (so that it operates on that list). I call: AddFacility(CRotgutFacility(..)).

Then, I am obtaining the handler to IFacility in some global function in prod_still_rotgut module, and call one of the interface methods. And it calls the method on CFacility object, not on CRotgutFacility...
This is probably related to a bug that I fixed in the SVN. The order of the declarations of classes and interfaces was impacting the final result, especially when inheriting from a class that implements an interface.

I suggest you upgrade to the WIP version in the SVN. Don't worry, the version in the SVN is already complete. I'll probably release it this weekend after I've added just a bit more documentation.

If you do the upgrade, and the problem still persists, then please let me know right away so that I can have a closer look at it, and perhaps get it fixed before the release of 2.16.0.

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

When exactly it was fixed? We're using rev383 (not 100% sure...)
Advertisement
Yesterday. In revision 384. :)

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