Sunday, 23 December 2007

Moonshine


pa loved his ol' moonshine.

I've been working on a project to integrate Lua with the Firefox web browser, in the form of an extension which adds support for the language to write background services or on-demand applications to run directly in the browser.

I have yet to write more code to get the integration working. I will enter this project into the Mozilla Lab's extend Firefox Contest. So hopefully, I'll have enough implemented by the deadline.

For more information, please see the Google code project page.


Image courtesy of ladyphoenixx_1999 (CC-BY-NC-ND)

Digg This Story

Monday, 26 November 2007

XML parser demonstration




Video on YouTube.

I managed to get the parser to handle attributes and tags with attributes.
xml.stag is no longer necessary and has been replaced with the more vesatile xml.tag .
Above is an approximately 8 minute video demonstrating use of the parser within the Lua interpreter. I apologise for the poor quality.

The next step for the parser now is to implement handling a specific occurrence of tag for the specified functions.

This video is licenced under same licence as the rest of this blog contents, except third party stuff of course (such as featured images).

Digg This Story

Tuesday, 20 November 2007

Lua XML Parser - so far, so good.


California XML licence plate.

As mentioned in my last posting, I have been developing a simple XML parser for use with the Lua programming languge. It will most likely be a very basic parser, that is not one on terms with more advanced parsers.

So far I have implemented 2 basic functions for my parser:


  1. Loading XML documents

  2. Parsing short tags (e.g. Something like <tag>value</tag>)



To include the functionality of the parser (which is a Lua module) into a new Lua program, I include the line:


xml = require "xmlparser"



This gives the program access to the two functions (I have so far) provided by my parser.

These are:


xml.load(file as str)
xml.stag(xml as str, tag as str [, occur as int])


I have written this simple program to test my parser as it stands so far:


--------------------------------------------------
-- Example program using XML Parser
-- Copyright (c) 2007 Sam Saint-Pettersen
-- Released under the GNU General Public License
-- http://creativecommons.org/licenses/GPL/2.0/
--------------------------------------------------

-- include xmlparser module
xml = require "xmlparser"

-- load xml file
file = xml.load("employees.xml")

-- display name
print("Name: " .. xml.stag(file, "last") .. ", " ..
xml.stag(file, "first")) -- < this should be on above line
-- display position
print("Position: " .. xml.stag(file, "position"))
-- display e-mail addresss
print("E-mail: " .. xml.stag(file, "email"))
-- display home page
print("Home page: " .. xml.stag(file, "homepage"))



Below is my test XML file:

<employees>
<employee>
<first>Phoenix</first>
<last>Lightfoot</last>
<position>Lead Programmer</position>
<email>p.lightfoot@pathetecsys.com</email>
<homepage>http://www.pathetecsys.com/~lightfoot</homepage>
<telephone type="office">001 222 222</telephone>
<telephone type="mobile">777 222 333</telephone>
</employee>
<employee>
<first>Hugo</first>
<last>Jacob-Jones</last>
<position>Chief Executive Officer</position>
<email>h.jacobjones@pathetecsys.com</email>
<homepage>http://www.pathetecsys.com/~jacobjones</homepage>
<telephone type="office">001 222 200</telephone>
<telephone type="mobile">577 242 321</telephone>
</employee>
</employees>


Here is the console output from running my test program under the Lua interpreter:


Name: Lightfoot, Phoenix
Position: Lead Programmer
E-mail: p.lightfoot@pathetecsys.com
Home page: http://www.pathetecsys.com/~lightfoot


So far, so good. :)

I have yet to add the capability to specify an occurrence of a tag, based on its index and functions for parsing tags which contain attributes such as
<tag attribute="value">anothervalue</tag>


I should have that done soon enough.




Featured image courtesy of lambdageek (CC-BY-NC)



Digg This Story