Sunday 6 January 2008

Moonshine core interpreter


xkcd rockband


Today I will show you a demonstration of the Mooshine core interpreter running two different Lua programs which utilise the Firefox browser.

The first program as outlined below tests the standard module:


-------------------------------
-- test standard module
-------------------------------
print("\n" .. std.version() .. "\n") -- print version
std.msg("Hello from Moonshine!") -- display message
local ans = std.prompt("Enter number:") -- display prompt

It does the following...

  1. Prints the version of the standard module in the interpreter

  2. Displays a message box in the browser

  3. Displays a prompt for user input


The second program retrieves the latest XKCD comic panel (a example of which is in this post) from the XKCD atom feed and displays it in a new browser window...

----------------------------------
-- display latest xkcd web
-- comic from the xkcd atom feed
-- in a new browser window
----------------------------------
-- make a request for xkcd comic feed
feed = net.httpreq("http://xkcd.com/atom.xml")
-- match comic panel
img = string.match(feed,
"http\:\/\/imgs.xkcd.com\/comics\/[%w%_]+.png")
-- display comic panel in a new window
std.window(img)

The current version of the Moonshine core interpreter is an executable written in C with embedded Lua. Most of the functionality itself comes from the included modules.

To properly work as part of my extension, I will rewrite the core intepreter in C++ as an XPCOM component (which use classes).


See the demonstration (animated GIF)

Image courtesy of xkcd (CC-BY-NC)

Digg This Story