From FIFE development wiki
Jump to: navigation, search

This article is part of design documentation. Design 32.png

Design documentation describes how software is implemented or is about to be implemented. It focuses on system structure (e.g. dependencies), module interactions and relevant algorithms. Concepts described in these articles should form the terminology that is used when discussing about the software that forms FIFE.


This article describes how script interface wrapping is done using SWIG. It is also meant to list common pitfalls that developers usually encounter when working with the scripting side.

Useful links



  • You get "No constructor defined" even though you are sure that there is constructor in interface file
    • Does some of the base classes contain abstract methods that are not defined in subclass that you try to instantiate?
      • In case all abstract methods are defined in you subclass, you can force swig to ignore abstractness by using %feature("notabstract") YOURCLASS;
    • Have you defined your methods correctly to be public (remember that in case there is no "public:" stated, methods are private)
  • You get terminate called after throwing an instance of 'Swig::DirectorMethodException' when execution arrives to your listener method in scripting side.
    • In this case something caused exception in your listener method. E.g. you tried to access some attributes that didn't exist in some instance. Hey! perhaps you forgot to mark those methods as public in the interface file?! (happened to me gazillion times) --Jasoka 22:58, 7 July 2007 (CEST)
  • You get a segfault on exit.
    • Are you creating an object in scripts and then giving it to the the engine? If the engine is responsible for cleaning up the object, you need to set the object's "thisown" attribute to 0 in scripts. This is because Python's refence counting mechanism keeps track of its own references, but it doesn't know what the engine is doing. Without the thisown definition,
      • python might collect its reference, causing correspoding c++ object to be deleted. Engine might still be using that → causes failure
      • engine could also delete c++ object, causing python originated (ref counted) deletion fail
    basically common guideline is that you should know for each object who is managing its memory (whose responsibility is it to allocate, and whose to delete)
  • You define a c++ object with an == operator and expose the object and the operator through swig, but inequality comparisons don't work script-side. Instead of using "A != B", try using "not (A == B)".