lure

Summary

LURE is an attempt to implement a hybrid xml/html DOM parser and renderer for the Love2d game engine. The goal of LURE is to provide the following:

  • A non-validating xml/html parser which generates a (somewhat) W3C Standards complaint DOM Object for use with love.
  • A html renderer which will display html markup in the love window.

Although we have a working prototype of the xml/html parser and DOM Object, we do not yet have a working renderer. Given the sheer size of the W3C DOM specification, this area will serve to document and track the current status of DOM Interface implementations.

Lure's purpose will NOT be to implement a web browser in Love2d, that is just ridiculous :D Instead, Lure's purpose will be to provide the core xml/html DOM interfaces allowing Lovers the ability to to work with xml/html data structures and to render basic html to the love window for simple UI.

Parser Preview

The parser in its current state implements many of the core DOM node objects. Although the library is not yet ready for prototype release, below is an example of the current xml/html parser and some basic use of the resulting DOM Object.

Below is very simple xml/html markup:

<html>
	<head>
		<title>Lure Test Page</title>		
	</head>
	<body>
		<div id="div1">
			this is a sentence<br>separated by a break line.
			<div id="div2">Hello</div>
			<div id="div3">World</div>			
		</div>
	</body>
</html>

And to parse and work with the DOM in LURE:

require("lure.lua")

htmlDoc = Lure.load("test.html")
print(htmlDoc.getElementById("div1").childNodes[1].data)
--OUTPUT: this is a sentence

print(htmlDoc.childNodes[1].childNodes[2].childNodes[1].childNodes[3].data)
--OUTPUT: separated by a break line.

newElement = htmlDoc.createElement("div")
newElement.setAttribute("id", "myNewElement")
htmlDoc.childNodes[1].childNodes[2].appendChild(newElement)
print(htmlDoc.getElementById("myNewElement").getAttribute("id"))
--OUTPUT: myNewElement

Since the parser is non-validating (no docTypes, namespaces or other shenanigans), we can parse and produce a DOM object using arbitrary xml structures. Lets represent a list of players using XML:

<players>
	<player id="p1">
                <desc>I am player 1</desc>
		<item type="weapon" />
	</player>
	<player id="p2">
		<item type="weapon" />
	</player>
	<player id="p3">
		<item type="weapon" />
	</player>
	<player id="p4">
		<item type="weapon" />
	</player>
	<player id="p5">
		<item type="weapon" />
	</player>	
</players>

And to parse and work with the returned DOM in Lure:

require("lure.lua")

playersXML = lure.load("players.xml")

player1 = playersXML.documentElement.firstChild
print(player1.id)
--OUTPUT: p1

print(player1.childNodes[1].childNodes[1].data)
--OUTPUT: I am player 1

player1.childNodes[2].getAttribute("type")
--OUTPUT: weapon

Documentation

Lure Function Reference

Function Description Implemented
lure.load() Load function to handle loading xml/html data from various sources (ex: flatfile) Yes
lure.save() Saves a lure dom Object to flat file No
lure.update() Update function No
lure.draw() Draw function to render html to the lure window (if any html exists in the lure dom) No
lure.mousepressed() function to pass in mousepressed events to the lure dom No
lure.mousereleased() function to pass in mousereleased events to the lure dom No
lure.keypressed() function to pass in keypress events to the lure dom No
lure.keyreleased() function to pass in keyreleased events to the lure dom No

Lure DOM Reference

Objects present in this table are DOM objects currently planned for implementation. Not all W3C DOM objects will be implemented.

Object Description Implemented
DOM Node The Node object represents a single node in the document tree Yes
DOM NodeList The NodeList object represents an ordered list of nodes Yes
DOM NamedNodeMap The NamedNodeMap object represents an unordered list of nodes. Yes
DOM document The Document object represents the entire XML/HTML document. Yes
DOM Element The Element object represents an element in an XML/HTML document Yes
DOM Attribute The Attr object represents an attribute of an Element object. Yes
DOM Text The Text object represents the textual content of an element or attribute. Yes
DOM CDATA The CDATASection object represents a CDATA section in a document. Yes
DOM Comment The Comment object represents the content of comment nodes in a document. Yes
DOM Window The Window object represents Love window No

MORE TO COME!