Changes

Jump to navigation Jump to search
529 bytes added ,  08:37, 28 March 2013
Finished page for xml in Lua
end
</pre></code>
What does this do? As you can see, we mostly use the <tt>context...</tt> commands which are described in the [http://www.pragma-ade.com/general/manuals/cld-mkiv.pdf cld manual]. They are Lua functions which print to ConTeXt. With the <tt>list</tt> function, we start a ConTeXt table and typeset a first row with the meta information. The functions for <tt>item</tt> and <tt>model</tt> do nothing more than print the argument of the connected elements as table rows and the first table column. Things get a bit more interesting for the <tt>price</tt> function: this is where we use the power of Lua to do some easy calculations and convert the Euros to other currencies. First, we extract the content of the <tt><price></tt> element. We need to tell Lua that this content is not a string, but a number, hence the use of the <tt>tonumber</tt> function. As you can seeWithin a ConTeXt environment, the equivalent of we would use <prett>\xmltext{#1}{./}</prett> in . The Lua equivalent is <prett>xml.text(t, "./")</prett>.Now that we have this content as number, we can perform all kinds of arithmetic operations on it. Likewise, if it were a string, we could use Lua string manipulations on it – that's the good thing about using Lua, you have the full power of the language at your disposal. And finally, we typeset the results of our arithmetic operations in table cells. This was just one example of what you can do with Lua. Good luck finding other fascinating use cases! --[[User:Thomas|Thomas]] 09:35, 28 March 2013 (CET)
gardener
111

edits

Navigation menu