summaryrefslogtreecommitdiff
path: root/swig-postprocess.rb
diff options
context:
space:
mode:
authorTobias Grimm <tobias@e-tobi.loc>2009-02-14 23:25:05 +0100
committerTobias Grimm <tobias@e-tobi.loc>2009-02-14 23:25:05 +0100
commit2bae6457006474655f971891a92341b1ae34840e (patch)
tree30a813fdbb1c096a08d7c35dd59fafc3f65154f4 /swig-postprocess.rb
downloadvdr-plugin-scripting-branches/v0.0.1.tar.gz
vdr-plugin-scripting-branches/v0.0.1.tar.bz2
Initial commitv0.0.1branches/v0.0.1
Diffstat (limited to 'swig-postprocess.rb')
-rw-r--r--swig-postprocess.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/swig-postprocess.rb b/swig-postprocess.rb
new file mode 100644
index 0000000..26dd268
--- /dev/null
+++ b/swig-postprocess.rb
@@ -0,0 +1,37 @@
+AUTOUNLINK = [ "COsdItem", "COsdMenu", "CMenuText" ]
+
+################################################################################
+
+#
+# Add auto unlink code to SWIG director destructors like:
+#
+# SwigDirector_<class>::~SwigDirector_<class>() {
+# SWIG_RubyUnlinkObjects(this);
+# SWIG_RubyRemoveTracking(this);
+# }
+#
+# With this code, when a C++ instance is delete, it will automatically remove
+# itself from the list of tracked objects and unlink itself from the Ruby object
+# it is used by. This means, that any call to a method of the C++ class from the
+# Ruby object will now throw an ObjectPreviouslyDeleted exception.
+#
+def add_auto_unlink_code
+ for klass in AUTOUNLINK
+ @swig_code.gsub!(/(SwigDirector_#{klass}::~SwigDirector_#{klass}\(\) \{\n)(\})/m,
+ "\\1 SWIG_RubyUnlinkObjects(this);\n SWIG_RubyRemoveTracking(this);\n\\2")
+ end
+end
+
+def improve_overloaded_error
+ @swig_code.gsub!(/("%s )(for overloaded.*msg,)( method, prototypes)/m,
+ '\1(%d) \2 argc-1,\3')
+end
+
+## main ##
+
+@swig_code = IO.read(ARGV[0])
+
+add_auto_unlink_code if ! AUTOUNLINK.empty?
+improve_overloaded_error
+
+File.new(ARGV[1], "w").write(@swig_code)