<?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>Create Blog &#187; Framework</title>
	<atom:link href="http://create.tpsitulsa.com/blog/category/framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://create.tpsitulsa.com/blog</link>
	<description>the create framework blog</description>
	<lastBuildDate>Sat, 30 Jan 2010 20:08:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>For the Love of a Deity, Please Prove Me Wrong: IE Alpha</title>
		<link>http://create.tpsitulsa.com/blog/2009/12/29/ie-alpha/</link>
		<comments>http://create.tpsitulsa.com/blog/2009/12/29/ie-alpha/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 19:06:38 +0000</pubDate>
		<dc:creator>Alex Iskander</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Please Prove Me Wrong]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[SproutCore]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://create.tpsitulsa.com/blog/?p=317</guid>
		<description><![CDATA[Please no. Just, no. I mean, honestly, how far can IE sink? I really hope I am wrong here, but&#8230; If you check my test case, you may notice that it looks different in Internet Explorer than it does in sane browsers. What is the culprit? Simple: filter:alpha. Supposedly, making elements somewhat transparent is possible [...]]]></description>
			<content:encoded><![CDATA[<p>Please no. Just, no. I mean, honestly, how far can IE sink? I really hope I am wrong here, but&#8230;</p>

<p>If you <a href="http://create.tpsitulsa.com/static/tests/test-opacity.html">check my test case</a>, you may notice that it looks different in Internet Explorer than it does in sane browsers. What is the culprit?</p>

<p>Simple: filter:alpha.</p>

<p>Supposedly, making elements somewhat transparent is possible in <a href = "http://www.microsoft.com/windows/internet-explorer/default.aspx" rel="nofollow">everyone&#8217;s favorite browser</a>. Well, it is, but you have to use Microsoft&#8217;s proprietary &#8220;filter&#8221; CSS property.</p>

<p>Okay, fine, at least it works. Except in one case, from what I can tell: it will not apply transparency to absolutely positioned child elements of the element with the &#8220;filter&#8221; property set.</p>

<p>Why is this an issue? Let&#8217;s take the simple example of a button control (specifically, SproutCore&#8217;s SC.Button, but it should apply to other button controls as well): you have a left part (with nice rounded corners), a center part (that can be stretched), and a right part (again with the rounded corners). One part—for instance, the right part—is either positioned relatively or is the parent element itself, and simply has a background-position:right. The left and center parts, however, are positioned absolutely; something like <tt>left: 10; right: 10</tt> for the center part; <tt>right:0; width:10;</tt> for the right part (I just made these numbers up! They aren&#8217;t real!)</p>

<p>So, what happens if you try to fade the button out in Internet Explorer? Well, it looks really odd. In the above example, the right part fades out, but the left and center do not. They just stay as they were.</p>

<p>There is only one workaround that I know of: seting <tt>filter:alpha</tt> on every element. There are a few problems with this:</p>

<ul>
<li>Performance. Each setting of &#8220;opacity&#8221; will have to recursively loop through all child elements.</li>
<li>Performance * Animation fps. Yep, animating opacity in IE is plain screwed.</li>
<li>Pure messiness.</li>
<li>Long-term issues: what about when (if) Microsoft fixes the issue?</li>
</ul>

<p>Don&#8217;t you just love Internet Explorer?</p>

<p>I keep thinking I must be wrong, and there must be some nice little workaround, CSS hack, or even the simple explanation of <em>me just being plain wrong</em> (I actually hope I am).</p>

<p>Anyone know?</p>
]]></content:encoded>
			<wfw:commentRss>http://create.tpsitulsa.com/blog/2009/12/29/ie-alpha/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Notes on Bespin&#8217;s Model and Cursor Positions</title>
		<link>http://create.tpsitulsa.com/blog/2009/06/17/notes-on-bespins-model-and-cursor-positions/</link>
		<comments>http://create.tpsitulsa.com/blog/2009/06/17/notes-on-bespins-model-and-cursor-positions/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 19:43:40 +0000</pubDate>
		<dc:creator>Alex Iskander</dc:creator>
				<category><![CDATA[Bespin]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://create.tpsitulsa.com/blog/?p=153</guid>
		<description><![CDATA[I am writing this so that I will remember (as I have forgotten some of the things here before). However, since others may find it useful, and since I&#8217;d really like any double-checking I can get, I am publishing it. In a web-based Create Framework related project, we are using Mozilla&#8217;s wonderful Bespin text editor. [...]]]></description>
			<content:encoded><![CDATA[<p>I am writing this so that I will remember (as I have forgotten some of the things here before). However, since others may find it useful, and since I&#8217;d really like any double-checking I can get, I am publishing it.</p>

<p>In a web-based Create Framework related project, we are using Mozilla&#8217;s wonderful <a href="https://bespin.mozilla.com/">Bespin</a> text editor. In the process of using it, we sometimes need to modify the editor in some way, perhaps by adding new features, perhaps by finding and fixing bugs.</p>

<p>The following is technical in nature.</p>

<p><span id="more-153"></span></p>

<p>In Bespin, characters are arranged in rows and columns. Any character may be referred to with a row number and a column number. This set of two numbers is referred to as a position.</p>

<p>Bespin&#8217;s editor has two significant parts which each have their own kind of position: the editor, and the model. This may seem silly at first: why should the editor&#8217;s position at row 5 column 4 be any different than the model&#8217;s?</p>

<p>There are a few different reasons for this, and the reasons could grow. It boils down to one concept: the editor, in order to enhance the usability, does not show characters exactly as they are in the model. For instance, a single tab in the model will usually be transformed into more than one space in the editor (for instance, four spaces). In this case, column 4 is the column immediately following a tab at the beginning of the line in the editor &mdash; the model position would be (5, 1), pointing to the column immediately following the tab character.</p>

<p>Also, code folding hides some lines of code, so row 4 could actually have been lines 4 through 30, but collapsed to take just one line. In this case, the model position for (5, 4) would be (31, 1).</p>

<p>The positions in the editor are called cursor positions (as they are possible positions of the cursor in the editor), and the positions in the model are called model positions.</p>

<p>As detailed in Gordon Hemsley&#8217;s <a href="https://wiki.mozilla.org/Labs/Bespin/DeveloperGuide/Tabs">guide on working with tabs</a>, there are a few helper functions. There are two that are most important:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">cursorManager.<span style="color: #660066;">getCursorPosition</span><span style="color: #009900;">&#40;</span>modelPosition<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
cursorManager.<span style="color: #660066;">getModelPosition</span><span style="color: #009900;">&#40;</span>cursorPosition<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>As you might expect by looking at their names and arguments, they convert cursor positions to model positions and vice-versa. There are two proxies to these functions in the <em>editor</em> component as well:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">editor.<span style="color: #660066;">getCursorPos</span><span style="color: #009900;">&#40;</span>modelPosition<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//note the lack of &quot;ition&quot;</span>
editor.<span style="color: #660066;">getModelPos</span><span style="color: #009900;">&#40;</span>cursorPosition<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<p>So what positions are used where? The model, naturally, always uses model positions. The editor always uses cursor positions. Actions (where most of the actual editing takes place) have convert between the two.</p>

<p>For instance, the action insertCharacter (in <em>actions.js</em>), used whenever you type in a letter (with extra comments inserted marking the conversions):</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">    insertCharacter<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">editor</span>.<span style="color: #660066;">readonly</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">editor</span>.<span style="color: #660066;">selection</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">deleteSelectionAndInsertCharacter</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// SEE HERE:</span>
            <span style="color: #006600; font-style: italic;">// the &quot;pos&quot; argument given to insertCharacter is, of course, the current cursor position.</span>
            <span style="color: #006600; font-style: italic;">// so, we convert it to a model position and hand it off to the model.</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">model</span>.<span style="color: #660066;">insertCharacters</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cursorManager</span>.<span style="color: #660066;">getModelPosition</span><span style="color: #009900;">&#40;</span>args.<span style="color: #660066;">pos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> args.<span style="color: #660066;">newchar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cursorManager</span>.<span style="color: #660066;">moveRight</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">repaint</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">// undo/redo</span>
            args.<span style="color: #660066;">action</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;insertCharacter&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> redoOperation <span style="color: #339933;">=</span> args<span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> undoArgs <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> action<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;deleteCharacter&quot;</span><span style="color: #339933;">,</span> pos<span style="color: #339933;">:</span> bespin.<span style="color: #660066;">editor</span>.<span style="color: #660066;">utils</span>.<span style="color: #660066;">copyPos</span><span style="color: #009900;">&#40;</span>args.<span style="color: #660066;">pos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> queued<span style="color: #339933;">:</span> args.<span style="color: #660066;">queued</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #003366; font-weight: bold;">var</span> undoOperation <span style="color: #339933;">=</span> undoArgs<span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">editor</span>.<span style="color: #660066;">undoManager</span>.<span style="color: #660066;">addUndoOperation</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> bespin.<span style="color: #660066;">editor</span>.<span style="color: #660066;">UndoItem</span><span style="color: #009900;">&#40;</span>undoOperation<span style="color: #339933;">,</span> redoOperation<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://create.tpsitulsa.com/blog/2009/06/17/notes-on-bespins-model-and-cursor-positions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PDF Embedding and So, So Much More</title>
		<link>http://create.tpsitulsa.com/blog/2009/06/12/pdf-embedding-and-so-so-much-more/</link>
		<comments>http://create.tpsitulsa.com/blog/2009/06/12/pdf-embedding-and-so-so-much-more/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 21:01:35 +0000</pubDate>
		<dc:creator>Alex Iskander</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[What's New]]></category>

		<guid isPermaLink="false">http://create.tpsitulsa.com/blog/?p=150</guid>
		<description><![CDATA[The framework&#8217;s PDF engine has largely been rewritten. This adds a lot of new abilities which are quite exciting (and, in the meantime, we even changed a couple of unrelated things). Here&#8217;s a list of changes: Page Trees. We used to write one PDF array of pages. Now, we write trees of pages, allowing us [...]]]></description>
			<content:encoded><![CDATA[<p>The framework&#8217;s PDF engine has largely been rewritten. This adds a lot of new abilities which are quite exciting (and, in the meantime, we even changed a couple of unrelated things).</p>

<p>Here&#8217;s a list of changes:</p>

<ul>
<li><strong>Page Trees. </strong> We used to write one PDF array of pages. Now, we write trees of pages, allowing us to keep only a small number of page nodes in memory at a time.</li>
<li><strong>Compression. </strong> Content streams in PDF files are now compressed. Why did we implement this now? Well, that&#8217;s a funny story&#8230;</li>
<li><strong>Decompression. </strong> It turns out that, in our effort to embed one PDF inside of another, we may have to deal with multiple content streams. It further turns out that they still represent one long stream (as opposed to several individual segments) and as such cannot be used separately from each other. So, to put them in one object in the PDF file that may be reused you have to decompress and concatenate them. And, since we&#8217;re decompressing, why not compress as well?</li>
<li><strong>PDF Parsing. </strong> After the near-rewrite of the PDF component, it was actually quite easy to allow PDF parsing. It only took us around a week or so. Now, we are able to open a PDF file and rip contents out of it.</li>
<li><strong>PDF Embedding. </strong> It has, for awhile, been possible to embed PDFs inside PPML. However, to embed PDFs inside other PDF files, you need to actually deconstruct the PDF to be embedded. That&#8217;s why we implemented parsing. Amazingly, it all appears to work &mdash; although, unfortunately, it does not (currently) work for PDFs with compressed cross-reference streams or compressed object streams.</li>
<li><strong>Better PDF Embedding.</strong> Not only does PDF-in-PDF embedding work, but PDF-in-PPML embedding has been improved nicely. The width and height of any embedded PDF are read in, so it is now possible to do lots of fancy stuff. Now, PDFs are treated almost exactly like images. You can make them fill a frame, you can make them fit in a frame, you can make them centered in a frame&#8230; basically, you can do anything you can do with an image with a PDF &mdash; in both PPML and PDF outputs.</li>
<li><strong>Text Processing Bug Fixed. </strong> Imagine the words &#8220;Hello World.&#8221; What if both cannot fit on the same line? They should, then, naturally be put on separate lines. But what if it was just the space between the words making the difference? Still, they need to be on separate lines. Unfortunately, the framework had a bug here &mdash; it was determining that it needed to break, but although it split at the right point, it did not actually go to the new line. This has been fixed!</li>
<li><strong>Line Height = 1.2.</strong> The framework now supports line heights for runs of text. This is, basically, the amount of spacing there should be between lines. Because we use InDesign quite often here, we made the framework default to line spacing of 1.2 &mdash; like InDesign&#8217;s &mdash; which changes how text flows in any application that has text boxes with more than one line of text.</li>
</ul>

<p><strong>Where Are We Going</strong>
So what&#8217;s left? Well, there could be some memory usage issues; the engine was using a suspiciously large amount of memory the other day when processing a set of a few thousand records. It may or may not have been a small (or large) leak. We will get around to fixing this problem (if it exists) when it starts to bother us.</p>

<p>We want to implement scripting support for PDF, and by that, I mean that we want to be able to open a PDF using Script, determine things such the size of a page, and so on. It does not necessarily need to talk directly to PDF &mdash; it could talk to PDFLink &mdash; but we want a tool we can use to automate things such as imposition.</p>

<p>Of course, scripting of views could allow this, and this is an eventual goal. In the meantime, however, we may see some form of compiled dC, where dC is generated (compiled) live through some script, allowing forms of meta-programming.</p>

<p>A big part of all of this will be the conversion from the Engine to the Shell, which is a JavaScript based platform. The Shell will be able to simply run scripts, or do Create Framework related things. This will make it much easier to maintain the current Shell, which is used for running some current scripts here at TPSi.</p>

<p>Finally, dC namespaces need a rewrite, and that will happen eventually.</p>

<p>We have another project we will be working on for a little while. It is related to the Create Framework, but a bit too experimental to announce quite yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://create.tpsitulsa.com/blog/2009/06/12/pdf-embedding-and-so-so-much-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PDF Parsing</title>
		<link>http://create.tpsitulsa.com/blog/2009/05/19/pdf-parsing/</link>
		<comments>http://create.tpsitulsa.com/blog/2009/05/19/pdf-parsing/#comments</comments>
		<pubDate>Tue, 19 May 2009 21:17:02 +0000</pubDate>
		<dc:creator>Alex Iskander</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://create.tpsitulsa.com/blog/?p=143</guid>
		<description><![CDATA[Just a little status update: yesterday, I finally managed to make the new PDF engine pass all PDF-related tests in the Create Framework. It is revision 100 in the pdf-parsing branch on Launchpad. Yes, all of the tests have been updated, but they were hand-checked first. As the new engine handles the timing of the [...]]]></description>
			<content:encoded><![CDATA[<p>Just a little status update: yesterday, I finally managed to make the new PDF engine pass all PDF-related tests in the Create Framework. It is revision 100 in the <a href="https://code.launchpad.net/~alex.iskander/create/create-pdf-parsing">pdf-parsing branch</a> on Launchpad.</p>

<p>Yes, all of the tests have been updated, but they were hand-checked first. As the new engine handles the timing of the writing of objects differently, the tests will work differently. They will change further, in fact, because I just realized that the maximum size for a page tree node is still set to 3 (for debugging purposes) &mdash; which is not at all what the final size should be &mdash; so the tests that have more than three pages are, unfortunately, <em>wrong</em>. Further, it is possible that some areas of the Create Framework may even have some leaks regarding PDF, so fixes to those could cause problems. This is not a <em>stable</em> branch, is not <em>meant</em> to be a stable branch, and is not guaranteed to even be in a compilable state. I&#8217;ve disclaimed, so if your computer blows up, it is not my fault.</p>

<p>Now, I&#8217;ve finally started PDF parsing. Currently, I&#8217;ve got the first XRef table being read in. I&#8217;m excited. Hopefully, by the end of the week, I&#8217;ll have some form of PDF-in-PDF embedding working. Currently, I&#8217;m aiming to support only PDF 1.4 &#8212; before all of that cross-reference stream and object stream business came about that would require the ability to handle compression (which, while on the eventual to-do list, is not currently a priority).</p>
]]></content:encoded>
			<wfw:commentRss>http://create.tpsitulsa.com/blog/2009/05/19/pdf-parsing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DOM-Dependence in JavaScript Libraries</title>
		<link>http://create.tpsitulsa.com/blog/2009/05/06/dom-dependence-in-javascript-libraries/</link>
		<comments>http://create.tpsitulsa.com/blog/2009/05/06/dom-dependence-in-javascript-libraries/#comments</comments>
		<pubDate>Thu, 07 May 2009 03:12:08 +0000</pubDate>
		<dc:creator>Alex Iskander</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://create.tpsitulsa.com/blog/?p=132</guid>
		<description><![CDATA[The Create Framework supports JavaScript to a growing extent. When using JavaScript in the Create framework, I&#8217;ve often wanted functions that I&#8217;ve used or seen in libraries like Prototype. It is often easy enough to copy-and-paste the functions I want from the library into my own code. However, I cannot simply import the entire library, [...]]]></description>
			<content:encoded><![CDATA[<p>The Create Framework supports JavaScript to a growing extent. When using JavaScript in the Create framework, I&#8217;ve often wanted functions that I&#8217;ve used or seen in libraries like <a href="http://www.prototypejs.org/">Prototype</a>. It is often easy enough to copy-and-paste the functions I want from the library into my own code. However, I cannot simply import the entire library, or include it in the Framework, because there are several functions which have direct dependence on the DOM (the HTML Document Object Model which describes web pages). This is a bit annoying, especially as JavaScript is becoming useful <em>outside</em> of the web. Obviously, these libraries were meant for the web, and they fulfill their purpose wonderfully. It would be nice, however, to have libraries for non-web scenarios (perhaps some already exist, and I just haven&#8217;t stumbled across them). The Create Framework will, undoubtedly, eventually get such a library of its own.</p>

<p>At some point, I hope to port <a href="http://vis.stanford.edu/protovis/">Protovis</a> to the framework. It seems to be made in such a way that it should be relatively easy to port: almost all of the work is done in Canvas, so if I just implement a canvas act-alike in the Create Framework, everything should work fine.</p>
]]></content:encoded>
			<wfw:commentRss>http://create.tpsitulsa.com/blog/2009/05/06/dom-dependence-in-javascript-libraries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto-Configuring, the Build, and the Barcode</title>
		<link>http://create.tpsitulsa.com/blog/2009/03/17/auto-configuring-the-build-and-the-barcode/</link>
		<comments>http://create.tpsitulsa.com/blog/2009/03/17/auto-configuring-the-build-and-the-barcode/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 03:21:46 +0000</pubDate>
		<dc:creator>Alex Iskander</dc:creator>
				<category><![CDATA[Barcode]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[USPS]]></category>

		<guid isPermaLink="false">http://create.tpsitulsa.com/blog/?p=111</guid>
		<description><![CDATA[Last night, I wrote about how I could not easily add the barcode functionality to the build because it was not guaranteed that the library would be on every computer compiling it. I did two main things: Added ENABLE() and HAVE() macros. Inspired by WebKit&#8217;s, here. This allows enabling and disabling the capabilities through a [...]]]></description>
			<content:encoded><![CDATA[<p>Last night, I wrote about how <a href="http://create.tpsitulsa.com/blog/2009/03/16/script-the-usps-intelligent-mail-barcode/">I could not easily add the barcode functionality to the build</a> because it was not guaranteed that the library would be on every computer compiling it.</p>

<p>I did two main things:</p>

<ol>
    <li><strong>Added ENABLE() and HAVE() macros.</strong> Inspired by WebKit&#8217;s, <a href="http://trac.webkit.org/browser/trunk/JavaScriptCore/wtf/Platform.h">here.</a> This allows enabling and disabling the capabilities through a configuration header file (<em>now located in config/config.h</em>).</li>
    <li><strong>Added a simple <em>generate-config</em> script.</strong> I know there are existing tools for this &mdash; I think GNU&#8217;s Autoconf does it &mdash; but I didn&#8217;t have time to learn something new, and I also didn&#8217;t want to invest in such complexity for a system which would not work in Windows. The Windows script is a command file; the Mac one is a shell script.</li>
</ol>

<p>I like how the scripts have no prerequisites on Mac and Windows. Unfortunately, I will probably have to rewrite them later in a consolidated form, so that I only have on script; at this point, it will likely cease to have <em>no</em> prerequisites.</p>

<p>So, how do compile with support for the barcode? On Mac, you have to put the libUSPS4CB.dylib in /usr/local/lib/. On Windows, you have to put in in your WINDOWS folder. And that&#8217;s it.</p>
]]></content:encoded>
			<wfw:commentRss>http://create.tpsitulsa.com/blog/2009/03/17/auto-configuring-the-build-and-the-barcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script &amp; the USPS Intelligent Mail Barcode</title>
		<link>http://create.tpsitulsa.com/blog/2009/03/16/script-the-usps-intelligent-mail-barcode/</link>
		<comments>http://create.tpsitulsa.com/blog/2009/03/16/script-the-usps-intelligent-mail-barcode/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 04:08:28 +0000</pubDate>
		<dc:creator>Alex Iskander</dc:creator>
				<category><![CDATA[Barcode]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[USPS]]></category>
		<category><![CDATA[V8]]></category>

		<guid isPermaLink="false">http://create.tpsitulsa.com/blog/?p=105</guid>
		<description><![CDATA[We need a way to integrate the new USPS Intelligent Mail Barcode nicely into our existing workflow. The software we use for most of our composition seems to have some&#8230; disagreements (or something)&#8230; with it at times, even though it officially supports it. Other people using the same software recommend using the USPS&#8217;s library. That&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>We need a way to integrate the new USPS Intelligent Mail Barcode nicely into our existing workflow. The software we use for most of our composition seems to have some&#8230; <em>disagreements (or something)</em>&#8230; with it at times, even though it officially supports it.</p>

<p>Other people using the same software recommend using the USPS&#8217;s library. That&#8217;s fine and all, but we don&#8217;t want to write a C program for each job &mdash; writing in C or C++ can be quite time consuming. And it requires compiling, creating projects, etc. In short, a lot of hassle.</p>

<p>While this may not be the course we end up following, I decided, tonight, that although I was half-asleep, I&#8217;d attempt to add scripting support for USPS&#8217;s library. At around 10:00, I downloaded the software from USPS. Now, roughly fifty minutes later, I have managed to write a script that uses the USPS barcode.</p>

<p><span id="more-105"></span></p>

<p>Here&#8217;s the script:</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> main<span style="color: #009900;">&#40;</span>input<span style="color: #339933;">,</span> output<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> inputFile <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> InputStream<span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> outputFile <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> OutputStream<span style="color: #009900;">&#40;</span>output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>inputFile.<span style="color: #660066;">ok</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">//get line</span>
		<span style="color: #003366; font-weight: bold;">var</span> line <span style="color: #339933;">=</span> inputFile.<span style="color: #660066;">getLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//split</span>
		<span style="color: #003366; font-weight: bold;">var</span> fields <span style="color: #339933;">=</span> line.<span style="color: #660066;">splitQuoted</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//if there aren't the required amount of fields, continue to next line (if any)</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>fields.<span style="color: #660066;">length</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			outputFile.<span style="color: #660066;">writeLine</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//get needed fields</span>
		<span style="color: #003366; font-weight: bold;">var</span> track <span style="color: #339933;">=</span> fields<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> route <span style="color: #339933;">=</span> fields<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//set output</span>
		line <span style="color: #339933;">=</span> line <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;,<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">+</span> USPSBarcode.<span style="color: #660066;">encode</span><span style="color: #009900;">&#40;</span>track<span style="color: #339933;">,</span> route<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//write</span>
		outputFile.<span style="color: #660066;">writeLine</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">&lt;!--</span> snipped<span style="color: #339933;">:</span> the splitQuoted string <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #339933;">--&gt;</span></pre></div></div>


<p>The Framework&#8217;s Script Engine made adding this to the Shell very easy (really, it should be moved into Spec, and Shell should get it from there, but for now&#8230;).</p>

<p>I will, over the course of the next couple of days, figure out a workflow for how I can get this code online without breaking the build for compiles without the library. Perhaps a command line switch? I will probably also move it to where it belongs: in Spec.</p>

<p>I will, however, go ahead and post the majority of the code here. I could have done it much quicker with a single function in global scope, but I prefer the cleanliness of using a JavaScript object (I could have still used an empty dummy object, but that wouldn&#8217;t have been proper).</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">#ifndef SHELL_WRAPPERS_USPSBARCODEWRAPPER_H_
#define SHELL_WRAPPERS_USPSBARCODEWRAPPER_H_
&nbsp;
#ifdef SHELL_WITH_USPS_BARCODE
&nbsp;
#include <span style="color: #339933;">&lt;</span>string<span style="color: #339933;">&gt;</span>
&nbsp;
extern <span style="color: #3366CC;">&quot;C&quot;</span> <span style="color: #009900;">&#123;</span>
	int USPS4CB<span style="color: #009900;">&#40;</span> char <span style="color: #339933;">*</span>TrackPtr<span style="color: #339933;">,</span> char <span style="color: #339933;">*</span>RoutePtr<span style="color: #339933;">,</span> char <span style="color: #339933;">*</span>BarPtr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">namespace</span> Shell
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">class</span> USPSBarcodeProvider
	<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">public</span><span style="color: #339933;">:</span>
		USPSBarcodeProvider<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		std<span style="color: #339933;">::</span>string encode<span style="color: #009900;">&#40;</span>std<span style="color: #339933;">::</span>string tracker<span style="color: #339933;">,</span> std<span style="color: #339933;">::</span>string route<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tracker.<span style="color: #660066;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>
				route.<span style="color: #660066;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">11</span> <span style="color: #339933;">&amp;&amp;</span> 
				route.<span style="color: #660066;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">5</span> <span style="color: #339933;">&amp;&amp;</span> 
				route.<span style="color: #660066;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">9</span> <span style="color: #339933;">&amp;&amp;</span>
				route.<span style="color: #660066;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			char res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">66</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			int result <span style="color: #339933;">=</span> USPS4CB<span style="color: #009900;">&#40;</span>
								 const_cast<span style="color: #339933;">&lt;</span>char <span style="color: #339933;">*&gt;</span> <span style="color: #009900;">&#40;</span>tracker.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
								 const_cast<span style="color: #339933;">&lt;</span>char <span style="color: #339933;">*&gt;</span> <span style="color: #009900;">&#40;</span>route.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
								 res
			<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>result <span style="color: #339933;">!=</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
			res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">65</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">return</span> res<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
ScriptBaseNative<span style="color: #009900;">&#40;</span>Shell<span style="color: #339933;">::</span>USPSBarcodeProvider<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">namespace</span> Shell
<span style="color: #009900;">&#123;</span>
	SWrap<span style="color: #009900;">&#40;</span>USPSBarcodeWrapper<span style="color: #339933;">,</span> USPSBarcodeProvider<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">public</span><span style="color: #339933;">:</span>
		USPSBarcodeWrapper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			set<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;encode&quot;</span><span style="color: #339933;">,</span> $<span style="color: #009900;">&#40;</span>encode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			className <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;USPSBarcodeProvider&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		SMember<span style="color: #009900;">&#40;</span>encode<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>extract<span style="color: #009900;">&#40;</span>self<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span>extract<span style="color: #009900;">&#40;</span>self<span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>encode<span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span>stringValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span>stringValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
#endif
&nbsp;
#endif</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://create.tpsitulsa.com/blog/2009/03/16/script-the-usps-intelligent-mail-barcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regression Tests</title>
		<link>http://create.tpsitulsa.com/blog/2009/02/17/regression-tests/</link>
		<comments>http://create.tpsitulsa.com/blog/2009/02/17/regression-tests/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 20:06:08 +0000</pubDate>
		<dc:creator>Alex Iskander</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://create.tpsitulsa.com/blog/?p=91</guid>
		<description><![CDATA[The framework finally became complete enough to where I felt like I could add tests. Perhaps I should have started with tests, but the tests themselves require a composition of many of the components, so it would have been impractical. Implementing tests had a very nice side-effect. Tests are meant to test expected behavior. As [...]]]></description>
			<content:encoded><![CDATA[<p>The framework finally became complete enough to where I felt like I could add tests. Perhaps I should have started with tests, but the tests themselves require a composition of many of the components, so it would have been impractical.</p>

<p>Implementing tests had a very nice side-effect. Tests are meant to test expected behavior. As it turns out, there were a lot of areas where the framework did not behave as expected. I fixed at least seven bugs over the course of the two days when I wrote the current four tests. I say &#8220;at least&#8221; because I often fix bugs as I see them and promptly forget about them, or group them into larger categories when I write the revision release notes.</p>

<p>In short, just by writing a few tests, I drastically increased the system&#8217;s stability. And, since they will run often, they will ensure continued stability as well. Short term and long term, testing can be great.</p>
]]></content:encoded>
			<wfw:commentRss>http://create.tpsitulsa.com/blog/2009/02/17/regression-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Script Engine</title>
		<link>http://create.tpsitulsa.com/blog/2009/01/31/the-script-engine/</link>
		<comments>http://create.tpsitulsa.com/blog/2009/01/31/the-script-engine/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 20:31:30 +0000</pubDate>
		<dc:creator>Alex Iskander</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[Script]]></category>

		<guid isPermaLink="false">http://create.tpsitulsa.com/blog/?p=64</guid>
		<description><![CDATA[One of the components of the framework on which I have been working particularly hard in the past week is the Script Engine. It is what it sounds like: a module designed to allow scripting to work inside the framework. Although most definitely still a work-in-progress, it now has a lot of the features I [...]]]></description>
			<content:encoded><![CDATA[<p>One of the components of the framework on which I have been working particularly hard in the past week is the <strong>Script Engine</strong>.</p>

<p>It is what it sounds like: a module designed to allow scripting to work inside the framework. Although most definitely still a work-in-progress, it now has a lot of the features I want it to have.</p>

<p>My goals were:</p>

<ul>
    <li>It should be extremely easy to make an object scriptable (less than ten minutes)</li>
    <li>It should be extremely easy to pass objects to JavaScript</li>
    <li>It should be extremely easy to retrieve objects from JavaScript</li>
    <li>It should be possible to implement other scripting languages in future</li>
</ul>

<p>I don&#8217;t know about the last, as I haven&#8217;t tried it yet, but the first three I think I may have succeeded in to some extent.</p>

<p>Basically, to give you the idea of what it does, I&#8217;m going to give a code dump showing how the script engine works. You very likely will not be interested. On the other hand, you could. So, I am posting it.</p>

<p><span id="more-64"></span></p>


<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/* Create a point class */</span>
<span style="color: #666666;">//Mem is a base class which allows reference counting.</span>
<span style="color: #0000ff;">class</span> Point <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> Mem
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
	Point<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>x <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>y <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	Point<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">double</span> x, <span style="color: #0000ff;">double</span> y<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>x <span style="color: #000080;">=</span> x<span style="color: #008080;">;</span> this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>y <span style="color: #000080;">=</span> y<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">double</span> x, y<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* register Point as a type that might be scripted */</span>
ScriptBaseNative<span style="color: #008000;">&#40;</span>Point<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* Create a wrapper named Point Wrapper for point */</span>
SWrap<span style="color: #008000;">&#40;</span>Point, PointWrapper<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
	PointWrapper<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #666666;">//add the x and y fields</span>
		this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>set<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;x&quot;</span>, $<span style="color: #008000;">&#40;</span>getX, setX<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		this<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>set<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;y&quot;</span>, $<span style="color: #008000;">&#40;</span>getY, setY<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #666666;">//specify that it is constructable</span>
		constructable <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #666666;">//set the class name</span>
		className <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;Point&quot;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	SGet<span style="color: #008000;">&#40;</span>getX<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #666666;">//&quot;self&quot; was passed as an argument, so get the point out of it</span>
		Point <span style="color: #000040;">*</span>point <span style="color: #000080;">=</span> self<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>as<span style="color: #000080;">&lt;</span>Point<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #666666;">//if it is not null, return x</span>
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>point<span style="color: #008000;">&#41;</span>
			<span style="color: #666666;">//wrapping it for Script</span>
			<span style="color: #0000ff;">return</span> $<span style="color: #008000;">&#40;</span>point<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>x<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #666666;">//otherwise, return undefined</span>
		<span style="color: #0000ff;">return</span> Script<span style="color: #008080;">::</span><span style="color: #007788;">Undefined</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	SSet<span style="color: #008000;">&#40;</span>setX<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #666666;">//&quot;self&quot; was passed as an argument, so get the point out of it</span>
		<span style="color: #666666;">//the easy way this time</span>
		Point <span style="color: #000040;">*</span>point <span style="color: #000080;">=</span> extract<span style="color: #008000;">&#40;</span>self<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #666666;">//if not null, set to value, the other argument</span>
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>point<span style="color: #008000;">&#41;</span>
			point<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>x <span style="color: #000080;">=</span> value<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>numberValue<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #ff0000; font-style: italic;">/* Almost identical Y functions go here... */</span>
&nbsp;
	<span style="color: #666666;">//called when a script wrapper is created</span>
	<span style="color: #666666;">//not when a new point needs creating</span>
	SConstruct
	<span style="color: #008000;">&#123;</span>
		Point <span style="color: #000040;">*</span>point <span style="color: #000080;">=</span> extract<span style="color: #008000;">&#40;</span>self<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #666666;">//add a reference count</span>
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>point<span style="color: #008000;">&#41;</span>
			point<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>ref<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #666666;">//called when the script wrapper is destroyed</span>
	SDestruct
	<span style="color: #008000;">&#123;</span>
		Point <span style="color: #000040;">*</span>point <span style="color: #000080;">=</span> extract<span style="color: #008000;">&#40;</span>self<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #666666;">//return if nothing</span>
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>point<span style="color: #008000;">&#41;</span>
			<span style="color: #0000ff;">return</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #666666;">//deref and delete if needed</span>
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>point<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>deref<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
			<span style="color: #0000dd;">delete</span> point<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #666666;">//called when new Point is called in JavaScript</span>
	SCreate
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">double</span> x <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span>, y <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>arguments.<span style="color: #007788;">length</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
			x <span style="color: #000080;">=</span> arguments<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>numberValue<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>arguments.<span style="color: #007788;">length</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span>
			y <span style="color: #000080;">=</span> arguments<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>numberValue<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		<span style="color: #0000ff;">return</span> $<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">new</span> Point<span style="color: #008000;">&#40;</span>x, y<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* Elsewhere */</span>
<span style="color: #666666;">//create contexts</span>
R<span style="color: #000080;">&lt;</span>GlobalContext<span style="color: #000080;">&gt;</span> myContext <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> GlobalContext<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
R<span style="color: #000080;">&lt;</span>V8Context<span style="color: #000080;">&gt;</span> v8Context <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> V8Context<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">//register type</span>
myContext<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>registerType<span style="color: #000080;">&lt;</span>Point<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">new</span> PointWrapper<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">//test constructor using v8</span>
v8Context<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>runScript<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;var jsPoint = new Point(42, 42);&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">//load a function using v8</span>
v8Context<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>runScript<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;function something(point){ return point.x; }&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">//get the function</span>
SFunction f <span style="color: #000080;">=</span>  myContext<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>get<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;something&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>functionValue<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">//prepare arguments</span>
SArguments args<span style="color: #008080;">;</span>
args.<span style="color: #007788;">add</span><span style="color: #008000;">&#40;</span>$<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">new</span> Point<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">4</span>, <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">//call function</span>
<span style="color: #0000ff;">double</span> x <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>f<span style="color: #008000;">&#41;</span> x <span style="color: #000080;">=</span> f<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>apply<span style="color: #008000;">&#40;</span>Script<span style="color: #008080;">::</span><span style="color: #007788;">SUndefined</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, args<span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>numberValue<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;The X value of the point is: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> x<span style="color: #008080;">;</span> <span style="color: #666666;">//should be 4</span></pre></div></div>


<p>It has been a bit difficult to make all of this work, and it is still <em>very much</em> a work-in-progress. One of the largest sources of difficulty was V8. I originally picked it because its <a href = "http://code.google.com/apis/v8/embed.html">Embedder&#8217;s Guide</a> looked friendly, but I discovered that there was actually quite a bit that was very poorly documented. The code in <em>v8.h</em> had somewhat more thorough documentation, but I found it lacking as well. What is really needed is several examples, showing the <em>best way</em> to do everything one might want to do.</p>

<p>If you are curious and want to see the code, it is <a href = "http://bazaar.launchpad.net/%7Ealex.iskander/create/trunk/files/head%3A/Script/">hosted on Launchpad</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://create.tpsitulsa.com/blog/2009/01/31/the-script-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

