<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf:RDF
	xmlns="http://purl.org/rss/1.0/"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel rdf:about="http://feeds.garagegames.com/rss/blogs/developer/61970/">
		<title>Blog for Matthias Georgi at GarageGames.com</title>
		<description>Blog feeds for Gamers and Developers in the GarageGames community.</description>
		<link>http://www.garagegames.com/</link>
		<image rdf:resource="http://www.garagegames.com/images/GarageGames_logo_small_w.gif" />
		<dc:date>2008-11-21T14:54:08+00:00</dc:date>
		<items>
			<rdf:Seq>
				<rdf:li rdf:resource="http://www.garagegames.com/blogs/61970/14190"/>
			</rdf:Seq>
		</items>
	</channel>
	<item rdf:about="http://www.garagegames.com/blogs/61970/14190">
		<dc:format>text/html</dc:format>
		<dc:date>2008-01-24T02:04:32+00:00</dc:date>
		<dc:creator>Matthias Georgi</dc:creator>
		<title>Ruby Binding for TGEA</title>
		<link>http://www.garagegames.com/blogs/61970/14190</link>
		<description>After finishing a working implementation of my binding for the Ruby language, I'm gonna try now a tighter support using gccxml. After reading the post of Prairie Games and their work on the Python binding I was inspired to use the same route for generating wrappers for C++ classes.&lt;br&gt;&lt;br&gt;My current implementation asks the Torque Scripting Environment for all defined classes, methods and fields and generates wrappers as script files, which call my binding code to interface with the Torque Engine. This has the drawback, that arguments and return values are converted to strings and my binding has to figure out, how to convert back and forth using the intermediate string representation.&lt;br&gt;&lt;br&gt;This works quite well and has some kind of type safety in contrast to the Torque Scripting Language. I was able to convert all torque scripts to ruby scripts and the syntax is very nice to work with. Especially the scripts for the world editor got a lot clearer by using Ruby. A simple example will show you the advantages of using a full fledged scripting language. This is my implementation of the FileDialog GUI:&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div class='codeblock'&gt;&lt;pre&gt;class FileDialogClass &amp;lt; GuiControl&lt;br&gt;  &lt;br&gt;  child_accessor :window, :okButton, :cancelButton, :dirTree, :textEdit, :fileList&lt;br&gt;  &lt;br&gt;  def_on(:add) do&lt;br&gt;&lt;br&gt;    window.on(:close) do&lt;br&gt;      close&lt;br&gt;    end&lt;br&gt;    &lt;br&gt;    okButton.on(:action) do |sender|&lt;br&gt;      @callback.call selectedFile&lt;br&gt;      close&lt;br&gt;    end&lt;br&gt;    &lt;br&gt;    cancelButton.on(:action) do |sender|&lt;br&gt;      close&lt;br&gt;    end&lt;br&gt;  &lt;br&gt;    dirTree.on(:selectPath) do |sender, path|&lt;br&gt;      fileList.setPath(path, @filespec)&lt;br&gt;    end&lt;br&gt;  &lt;br&gt;    fileList.on(:select) do |sender, id, filename|&lt;br&gt;      textEdit.setText(filename)&lt;br&gt;    end&lt;br&gt;    &lt;br&gt;    textEdit.on(:return) do |sender|&lt;br&gt;      @callback.call(selectedFile)&lt;br&gt;      close&lt;br&gt;    end&lt;br&gt;  end&lt;br&gt;  &lt;br&gt;  def open(title = &amp;quot;Open File&amp;quot;, button_text = &amp;quot;Open&amp;quot;, filespec = &amp;quot;*.*&amp;quot;, &amp;amp;proc)&lt;br&gt;    window.text = title&lt;br&gt;    okButton.text = button_text &lt;br&gt;    @filespec = filespec&lt;br&gt;    @callback = proc&lt;br&gt;    Canvas.pushDialog(self, 99)    &lt;br&gt;    fileList.setPath(dirTree.getSelectedPath, @filespec)&lt;br&gt;  end&lt;br&gt;  &lt;br&gt;  def selectedPath=(file)&lt;br&gt;    dirTree.setSelectedPath file&lt;br&gt;  end&lt;br&gt;  &lt;br&gt;  def selectedPath&lt;br&gt;    dirTree.getSelectedPath&lt;br&gt;  end&lt;br&gt;&lt;br&gt;  def selectedFile  &lt;br&gt;    &amp;quot;#{selectedPath}/#{textEdit.getValue}&amp;quot;&lt;br&gt;  end&lt;br&gt;  &lt;br&gt;  def close&lt;br&gt;    Canvas.popDialog(self)&lt;br&gt;  end&lt;br&gt;  &lt;br&gt;end&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;Essential was the implementation of the Event/Observer pattern, which simplifies the use of callbacks like onAdd. In Torque Script you are limited to one callback method for an event like onAdd. In my implementation you can attach more than one event listener to one instance or to the class itself. So you don't have to use namespaces, instead you attach the event listener to a particular instance, which should be done in the onAdd event handler, which gets called right after the creation of an object.&lt;br&gt;&lt;br&gt;You may have noticed the child_accessor method. This one generates a accessor method for getting the child or descendant of a SimObject. This is cool, as you can avoid messing up the global namespace. You just use the internalName property of a child object and reach it via the accessor method.&lt;br&gt;&lt;br&gt;So back to the GCCXML stuff. This is really exciting, as the xml format exposes the internal structure of a c++ program. I'm currently working on a small library, which parses the xml and makes the program structure accessible to the ruby world.&lt;br&gt;&lt;br&gt;A simple Rakefile (like Make in Ruby) will transform the C++ classes to their xml representation and automatically generate wrapper code, which can be compiled by good old Visual Studio. This route allows a tight ruby binding avoiding the intermediate string representation. Furthermore all desired elements of the engine may be exposed to scripting and the burden of writing repetitive wrapper code is avoided.&lt;br&gt;&lt;br&gt;If anyone is interested in ruby development, just let me know. I have invested a lot of time into this stuff (about 2 years) and like to share my experiences.</description>
	</item>
</rdf:RDF>
