<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Z O O F W A R E</title>
	<atom:link href="http://zoofware.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://zoofware.com</link>
	<description>Development Blog</description>
	<lastBuildDate>Thu, 26 Aug 2010 16:55:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Mixing Vala and Pure C</title>
		<link>http://zoofware.com/2010/08/26/mixing-vala-and-pure-c/</link>
		<comments>http://zoofware.com/2010/08/26/mixing-vala-and-pure-c/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 16:54:53 +0000</pubDate>
		<dc:creator>JwB</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Vala]]></category>

		<guid isPermaLink="false">http://zoofware.com/?p=455</guid>
		<description><![CDATA[The Vala documentation is pretty poor around this area in my opinion, it focuses mainly on mixing Vala with Glib C based libraries rather than basic C object files. However, as it turns out, its pretty easy to do. Say for example, we have our C library in a folder named c; there are two [...]]]></description>
			<content:encoded><![CDATA[<p>The Vala documentation is pretty poor around this area in my opinion, it focuses mainly on mixing Vala with Glib C based libraries rather than basic C object files. However, as it turns out, its pretty easy to do.</p>
<p>Say for example, we have our C library in a folder named <code>c</code>; there are two files: <code>c/functions.h</code> and <code>c/functions.c</code>.</p>
<pre name="code" class="c">
/* c/functions.h */

int foo(int a, int b);
const char * hello();
</pre>
<pre name="code" class="c">
/* c/functions.c */

#include "functions.h"

int foo(int a, int b)
{
	return a * b;
}

const char * hello()
{
	char * s = "Hello from pure C!\n";
	return s;
}
</pre>
<p>Firstly, we need to compile a object file which contains the above functions which can then be used via Vala.</p>
<p><code>gcc -c c/functions.c -o c/functions.o</code></p>
<p>Now thats done, we can move onto creating a VAPI file which is similar to a C header file, it contains the same prototypes as <code>functions.h</code>, but in Vala syntax.</p>
<pre name="code" class="c-sharp">/* functions.vapi */

[CCode(cheader_filename = "functions.h")]
namespace functions {

	[CCode(cname = "foo")]
	int foo(int a, int b);

	[CCode(cname = "hello")]
	unowned string hello();
}
</pre>
<p>The VAPI file makes use of several attributes (in a way similar to how C# does), for example, <code>cname="foo"</code> is simply what the  function is referred to in <code>c/functions.h</code>, which allows us to change the name exposed to Vala for greater OOP clarity if necessary.</p>
<p>The method modifier <code>unowned</code> is used as an equivalent to C&#8217;s <code>const</code>. Try omitting <code>unowned</code> and see what happens when you run the end program, bonus points if you can explain why <img src='http://zoofware.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>Moving on to the main program, which should be self explanatory:</p>
<pre name="code" class="c-sharp">
/* main.vala */

using functions;

public static int main(string[] args)
{
	stdout.printf("\nfoo(7, 6): %d\n", foo(7, 6));
	stdout.printf("hello(): %s\n", hello());
	return 0;
}
</pre>
<p>Almost there now, we just need to link it all together using the Vala compiler. Open you favorite terminal and enter the following:</p>
<p><code>valac -X "-Ic/" -X "c/functions.o" --vapidir=. --pkg functions main.vala  </code></p>
<p>A quick explanation of the above and we&#8217;re done&#8230;</p>
<p>The <code>-X</code> flags specify arguments to pass to the C compiler: we need to pass the include directory of our <code>functions.h</code>, which is the <code>-l</code> flag and we also need to specify the object file which contains our C functions (<code>c/functions.o</code>).</p>
<p>Next up is the <code>--vapidir</code> parameter which simply points to the folder with our VAPI file in it. We specify which VAPI file to load using the <code>--pkg functions</code> parameter. As you can probably guess the pkg name must match the base name of it&#8217;s respective VAPI file.</p>
<p>Now finally, the end program can be run:</p>
<p><code>$ ./main</p>
<p>foo(7, 6): 42<br />
hello(): Hello from pure C!<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://zoofware.com/2010/08/26/mixing-vala-and-pure-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moviehat</title>
		<link>http://zoofware.com/2010/08/17/moviehat/</link>
		<comments>http://zoofware.com/2010/08/17/moviehat/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 17:52:17 +0000</pubDate>
		<dc:creator>JwB</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://zoofware.com/?p=450</guid>
		<description><![CDATA[Over the weekend I&#8217;ve been working on a little PHP and Javascript project for which I&#8217;ve chosen the fairly poor name of &#8216;Moviechat&#8217;. The idea is pretty simple, it&#8217;s a site built around Facebook which allows users to maintain a list of films they have watched and recommend them to friends. Whilst the concept isn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Over the weekend I&#8217;ve been working on a little PHP and Javascript project for which I&#8217;ve chosen the fairly poor name of &#8216;Moviechat&#8217;.</p>
<p>The idea is pretty simple, it&#8217;s a site built around Facebook which allows users to maintain a list of films they have watched and recommend them to friends.</p>
<p>Whilst the concept isn&#8217;t particularly new or exciting, it has been a <strong>very</strong> interesting project to do, giving me the opportunity to brush up on my PHP and Javascript skills and give my brain a rest from the torture of emulator debugging.</p>
<p>It needs a few performance tweaks and cross browser compatibility checking however. If more than a handful of people use it (which I doubt), I have a few more features to add.</p>
<p><a href="http://moviehat.co.uk">http://moviehat.co.uk</a></p>
<p>The suggest box is open for a better sexier Web 2.0-esque name <img src='http://zoofware.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://zoofware.com/2010/08/17/moviehat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Emulator Woes</title>
		<link>http://zoofware.com/2010/07/10/emulator-woes/</link>
		<comments>http://zoofware.com/2010/07/10/emulator-woes/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 22:10:46 +0000</pubDate>
		<dc:creator>JwB</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Z80/SMS Emulation]]></category>

		<guid isPermaLink="false">http://zoofware.com/?p=440</guid>
		<description><![CDATA[After having reimplemented most of my C# Z80 emulator in C, I&#8217;m now trying to figure out why every ZEXALL test is failing: james@jameslaptop:~/Projects/Emulation/ZZ80E$ ./a.out z80/zexall_sdsc.sms Z80 instruction exerciser ld hl,(nnnn)................. CRC:350e5018 expected:5f972487 ld sp,(nnnn)................. CRC:45f3041a expected:7acea11b ld (nnnn),hl................. CRC:c9f9ffd8 expected:a3608b47 ...etc... My first guess was that there was a bug in one of the [...]]]></description>
			<content:encoded><![CDATA[<p>After having reimplemented most of my C# Z80 emulator in C, I&#8217;m now trying to figure out why every ZEXALL test is failing:</p>
<p><code>james@jameslaptop:~/Projects/Emulation/ZZ80E$ ./a.out z80/zexall_sdsc.sms<br />
Z80 instruction exerciser</p>
<p>ld hl,(nnnn).................   CRC:350e5018 expected:5f972487<br />
ld sp,(nnnn).................   CRC:45f3041a expected:7acea11b<br />
ld (nnnn),hl.................   CRC:c9f9ffd8 expected:a3608b47<br />
...etc...</code></p>
<p>My first guess was that there was a bug in one of the opcodes used to calculate the CRC because I know for sure that the <code>ld</code> opcodes are fine.</p>
<p>However after going through the list of opcodes involved in the CRC with a toothpick, I still can&#8217;t find any glaring or even minor mistakes <img src='http://zoofware.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  The problem with emulator debugging, especially at such an early stage, is that it&#8217;s hard to tell if you&#8217;re looking in the right place; the bug might be in a seemingly unrelated piece of code, the effects of which have simply cascaded down the chain.</p>
<p>It&#8217;s going to be a long night.</p>
]]></content:encoded>
			<wfw:commentRss>http://zoofware.com/2010/07/10/emulator-woes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First Year Grades</title>
		<link>http://zoofware.com/2010/06/20/first-year-grades/</link>
		<comments>http://zoofware.com/2010/06/20/first-year-grades/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 10:34:06 +0000</pubDate>
		<dc:creator>JwB</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://zoofware.com/?p=327</guid>
		<description><![CDATA[I&#8217;m happy to brag that in my first year of university, I have received the following grades (pending ratification): Computer Architecture A Software Development I A Software Development II A Introduction to Databases A- Mathematical Methods 1 A Patterns of Problem Solving A- Basic Mathematical Techniques A Computational Mathematics A Not bad.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m happy to brag that in my first year of university, I have received the following grades (pending ratification):</p>
<table>
<tr>
<td>Computer Architecture</td>
<td>A</td>
</tr>
<tr>
<td>Software Development I</td>
<td>A</td>
</tr>
<tr>
<td>Software Development II</td>
<td>A</td>
</tr>
<tr>
<td>Introduction to Databases</td>
<td>A-</td>
</tr>
<tr>
<td>Mathematical Methods 1</td>
<td>A</td>
</tr>
<tr>
<td>Patterns of Problem Solving</td>
<td>A-</td>
</tr>
<tr>
<td>Basic Mathematical Techniques</td>
<td>A</td>
</tr>
<tr>
<td>Computational Mathematics</td>
<td>A</td>
</tr>
</table>
<p>Not bad. <img src='http://zoofware.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://zoofware.com/2010/06/20/first-year-grades/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My First OS (sort of&#8230;)</title>
		<link>http://zoofware.com/2010/06/19/my-first-os-sort-of/</link>
		<comments>http://zoofware.com/2010/06/19/my-first-os-sort-of/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 20:08:48 +0000</pubDate>
		<dc:creator>JwB</dc:creator>
				<category><![CDATA[OS Development]]></category>

		<guid isPermaLink="false">http://zoofware.com/?p=309</guid>
		<description><![CDATA[Well, this is something I&#8217;ve always wanted to learn more about; how operating systems work and how to write one of my own, and after a little light reading of Tanenbaum&#8217;s &#8220;Modern Operating System&#8221; I decided to give it a try. It&#8217;s pretty much the hardest thing I&#8217;ve ever attempted to do, and I haven&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Well, this is something I&#8217;ve always wanted to learn more about; how operating systems work and how to write one of my own, and after a little light reading of Tanenbaum&#8217;s &#8220;Modern Operating System&#8221; I decided to give it a try. It&#8217;s pretty much the hardest thing I&#8217;ve ever attempted to do, and I haven&#8217;t even got an OS per se, just a program which can print out text to the screen after the BIOS has booted. Here&#8217;s a boring screenshot of it running in QEMU:</p>
<p><a href="http://zoofware.com/wp-content/uploads/2010/06/zoofos_1.jpeg"><img src="http://zoofware.com/wp-content/uploads/2010/06/zoofos_1.jpeg" alt="" title="zoofos_1" width="728" height="427" class="aligncenter size-full wp-image-310" /></a></p>
<p>This Windows-killer took me the better half of a week to figure out, I&#8217;m sure I&#8217;ll have a fully functioning GUI, Nvdia drivers and a TCP stack by next Tuesday <img src='http://zoofware.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I&#8217;ve had to pick up a bit of x86 assembler on the way, with hopefully a lot more coming. A few of the functions look like this:</p>
<pre name="code" class="c">
; Initial entry point
[extern kmain]
[global load]
load:
    mov esp, stack_end
    push eax
    push ebx
    call kmain
    cli

hang:
    hlt
    jmp hang

; Returns CPU details
[global get_cpuid]
get_cpuid:
    push ebp				; save the base pointer
    mov ebp, esp			; move the current stack pointer to ebp
    mov eax, [ebp+8]		; get first parameter (mode)
    mov ebx, [ebp+12]		; get second parameter (pointer to string)
    push ebx
    cpuid
    pop eax
    mov [eax], ebx
    mov [eax + 4], edx
    mov [eax + 8], ecx
    leave
    ret

[global is_in_protected_mode]
is_in_protected_mode:
	xor eax, eax
	smsw ax
	and ax, 1
	ret
</pre>
<p><code>call kmain</code> transfers control over to a C function which inits the rest of the (insignificant) kernel.</p>
<pre name="code" class="c">
void kmain(void * mbd, unsigned int magic)
{
	gfx_init();
    gfx_clear();

    if(magic != 0x2badb002) {
		oops("Invalid magic number: %d", magic);
    }

    kprintf("Booting ZoofOS...\n");

    char cpuid[20];
    get_cpuid(0, cpuid);

	int mode = is_in_protected_mode();

    kprintf("CPU is a %s, and is running in %s mode.\n", cpuid, (mode) ? "protected" : "real" );
}
</pre>
<p>The most interesting thing with kernel development is that you have to do <strong>everything</strong> from scratch, no standard libraries, no nothing.</p>
<p>ZoofOS isn&#8217;t much right now and never will be, but it will be an incredible learning experience.</p>
]]></content:encoded>
			<wfw:commentRss>http://zoofware.com/2010/06/19/my-first-os-sort-of/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Re-writing ZZ80E in C</title>
		<link>http://zoofware.com/2010/06/08/re-writing-zz80e-in-c/</link>
		<comments>http://zoofware.com/2010/06/08/re-writing-zz80e-in-c/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 16:03:25 +0000</pubDate>
		<dc:creator>JwB</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Z80/SMS Emulation]]></category>

		<guid isPermaLink="false">http://zoofware.com/?p=287</guid>
		<description><![CDATA[Today I have started the momentous task of re-writing my Z80 emulator in C. It would have been possible to simply convert much of the C# code to C, but since I have learnt so much since I started writing it almost a year ago, I have decided to completely overhaul it. Progress has been [...]]]></description>
			<content:encoded><![CDATA[<p>Today I have started the momentous task of re-writing my Z80 emulator in C. It would have been possible to simply convert much of the C# code to C, but since I have learnt so much since I started writing it almost a year ago, I have decided to completely overhaul it.</p>
<p>Progress has been remarkably quick, with over a hundred of the most used opcodes implemented so far. One problem with the C# version was that as I wanted a built in disassembler and thought it would be cleaner, I had to have an individual method for each opcode which added the opcode&#8217;s mnemonic to the debug output. This time around, I have placed the vast majority of the opcode code in the switch statement, with common parts of code outsourced to inline functions. This has made the code a lot cleaner and manageable. To handle disassembly, I have created a Python script to convert a list of all the Z80 opcodes and their mnemonics to a C function which contains a huge switch statement to return the mnemonic. It might not be the fastest method, but it&#8217;s adequate for debugging.</p>
<p>This has been my first experience with C, and so far, it&#8217;s been a good one, I love the low level sexiness of it all. Would implementing a C standard library for Master System development using SDCC be too ambitious? <img src='http://zoofware.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://zoofware.com/2010/06/08/re-writing-zz80e-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Importance of Thread Safety in Gtk#</title>
		<link>http://zoofware.com/2010/05/15/the-importance-of-thread-safety-in-gtk/</link>
		<comments>http://zoofware.com/2010/05/15/the-importance-of-thread-safety-in-gtk/#comments</comments>
		<pubDate>Sat, 15 May 2010 13:41:53 +0000</pubDate>
		<dc:creator>JwB</dc:creator>
				<category><![CDATA[.NET / C#]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Gtk]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://zoofware.com/?p=279</guid>
		<description><![CDATA[Well, I&#8217;ve just spent way more time than necessary debugging an issue I had with a TreeView not being correctly updated and freezing the whole application. Unlike WPF (and also I think Winforms), Gtk# does not complain when a GUI object is accessed or modified from a separate thread, so I incorrectly assumed that the [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I&#8217;ve just spent way more time than necessary debugging an issue I had with a TreeView not being correctly updated and freezing the whole application.</p>
<p>Unlike WPF (and also I think Winforms), Gtk# does not complain when a GUI object is accessed or modified from a separate thread, so I incorrectly assumed that the issue wasn&#8217;t related to cross thread safety. As it turns out, my assumption was wrong (they usually are <img src='http://zoofware.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ).</p>
<p>In order to alter Gtk object from a separate thread, a method similar to the WPF Dispatcher can be used:</p>
<pre name="code" class="c-sharp">Gtk.Application.Invoke(delegate {
      randomGtkWindow.Title = "blah";
});</pre>
<p>Now, if we don&#8217;t invoke on the original Gtk thread, sometimes it will work, sometimes it won&#8217;t, with quite disastrous results. From what I&#8217;ve experienced so far, generally no error is thrown and if it is, then it&#8217;ll be quite cryptic.</p>
<p>Maybe the Gtk# developers should cause Gtk objects to throw an exception when accessed in a different thread?</p>
]]></content:encoded>
			<wfw:commentRss>http://zoofware.com/2010/05/15/the-importance-of-thread-safety-in-gtk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Return to GNU Linux</title>
		<link>http://zoofware.com/2010/05/08/my-return-to-gnu-linux/</link>
		<comments>http://zoofware.com/2010/05/08/my-return-to-gnu-linux/#comments</comments>
		<pubDate>Sat, 08 May 2010 10:56:35 +0000</pubDate>
		<dc:creator>JwB</dc:creator>
				<category><![CDATA[GNU Linux]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://zoofware.com/?p=273</guid>
		<description><![CDATA[Well; after exclusivity using Windows for the past two years, I have decided to go back to Linux land for awhile and try out Kubuntu. I&#8217;ve used Linux on and off now for almost as long as I can remember (since Mandrake 6 or 7 I think, which Wikipedia tells me were around 2000), I had Fedora [...]]]></description>
			<content:encoded><![CDATA[<p>Well; after exclusivity using Windows for the past two years, I have decided to go back to Linux land for awhile and try out Kubuntu. I&#8217;ve used Linux on and off now for almost as long as I can remember (since Mandrake 6 or 7 I think, which <a href="http://en.wikipedia.org/wiki/Mandriva_Linux#Table_of_versions">Wikipedia</a> tells me were around 2000), I had Fedora (up to version 4 or 5) as my primary OS for quite awhile before moving to Gentoo for probably a year, which was by far the best Linux OS I had used up until now.</p>
<p>I had honestly, never expected Linux to ever be ready for the desktop, yet maybe now after almost two decades I think it nearly is. After using Kubuntu for two days, I&#8217;m very impressed at how far it has come. Setup was a snap, KDE looks pretty (I used to only use GNOME), it feels solid and everything is nicely abstracted away from the command line, though obviously, all the flexibility and control which Linux provides is still available under the surface. I&#8217;m a geek and as such I don&#8217;t mind getting my hands dirty compiling sources, screwing with grub or rolling my own kernel, but sometimes it&#8217;s nice for things to just work without any hassle, especially when you have other things to focus on.</p>
<p>All it needs now is for Microsoft itself to port .NET to Linux and not Novell <img src='http://zoofware.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  *ducks*</p>
]]></content:encoded>
			<wfw:commentRss>http://zoofware.com/2010/05/08/my-return-to-gnu-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Matrix Calculator</title>
		<link>http://zoofware.com/2010/05/05/matrix-calculator/</link>
		<comments>http://zoofware.com/2010/05/05/matrix-calculator/#comments</comments>
		<pubDate>Tue, 04 May 2010 23:06:42 +0000</pubDate>
		<dc:creator>JwB</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Maths]]></category>

		<guid isPermaLink="false">http://zoofware.com/?p=271</guid>
		<description><![CDATA[The matrix calculator has been updated to include support for finding the inverse and determinants for square matrices of arbitrary dimensions. http://zoofware.com/zoofware-matrix-machine/]]></description>
			<content:encoded><![CDATA[<p>The matrix calculator has been updated to include support for finding the inverse and determinants for square matrices of arbitrary dimensions.</p>
<p><a href="http://zoofware.com/zoofware-matrix-machine/">http://zoofware.com/zoofware-matrix-machine/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://zoofware.com/2010/05/05/matrix-calculator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedding the DLR</title>
		<link>http://zoofware.com/2010/05/04/embedding-the-dlr/</link>
		<comments>http://zoofware.com/2010/05/04/embedding-the-dlr/#comments</comments>
		<pubDate>Tue, 04 May 2010 19:09:20 +0000</pubDate>
		<dc:creator>JwB</dc:creator>
				<category><![CDATA[.NET / C#]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://zoofware.com/?p=256</guid>
		<description><![CDATA[I&#8217;ve come across a rather interesting feature of IronPython and the DLR (forgive me if this is old news ) which I never previously knew about and would make an interesting addition to my planned Facebook XMPP client; the ability to execute embedded IronPython from any .NET language (even IronPython itself). using System; using System.Collections.Generic; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve come across a rather interesting feature of IronPython and the DLR (forgive me if this is old news <img src='http://zoofware.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) which I never previously knew about and would make an interesting addition to my planned Facebook XMPP client; the ability to execute embedded IronPython from any .NET language (even IronPython itself).</p>
<pre name="code" class="c-sharp">using System;
using System.Collections.Generic;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;

namespace ConsoleApplication3
{
	class Program
	{
		static void Main(string[] args)
		{
			Dictionary&lt;int, int&gt; bar = new Dictionary&lt;int, int&gt;();

			ScriptEngine engine = Python.CreateEngine();
			ScriptScope scope = engine.CreateScope();
			scope.SetVariable("bar", bar);

			string script = @"

from System import Console

foo = 'Hello from IronPython!'
Console.Title = foo

for i in range(0, 10):
	bar.Add(i, i**2)";

			engine.Execute(script, scope);
			Console.WriteLine(scope.GetVariable("foo"));

			foreach (KeyValuePair&lt;int, int&gt; kvp in bar)
			{
				Console.WriteLine("{0}^2 = {1}", kvp.Key, kvp.Value);
			}

			Console.ReadKey();
		}
	}
}
</pre>
<p>This is a great way to allow custom user defined scripts to alter a program without changing the actual code base. The embedded Python has complete access to the .NET library, likewise the calling C# has complete access to the embedded script.</p>
<p>I can&#8217;t see much practical use for this in a chat client, but I&#8217;m working on it <img src='http://zoofware.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://zoofware.com/2010/05/04/embedding-the-dlr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
