Lua Data Formats

lua-users home
wiki

Lua can be used as a language to represent data, not just as a general programming language.

Different languages have been devised for different types of data representation in text format [1]:

Although markup languages have been implemented in Lua [6], the Lua syntax is not in itself that suitable as a markup language. However, it has some nice capabilities for data serialization and interchange.

A number of different data representation styles may be used in Lua:

-- JSON style

library = { books = { {name="PiL", author="roberto"},

                      {name="BLP", author="kurt,aaron"} } }



-- Lisp/s-expression style

return {'library', {'book', name="PiL", author="roberto"},

                   {'book', name="BLP", author="kurt,aaron"} }



-- Java property page / INI / Unix config style

library.books[1].name = 'PiL'

library.books[1].author = 'roberto'

library.books[2].name = 'BLP'

library.books[2].author = 'kurt,aaron'



-- XML / object constructor style

library { book {name="PiL", author="roberto"},

          book {name="BLP", author="kurt,aaron"} }



-- XML with namespaces style

local LIB = require "library"

LIB.library { LIB.book {name="PiL", author="roberto"},

              LIB.book {name="BLP", author="kurt,aaron"} }

Features of Lua:

See Also


RecentChanges · preferences
edit · history
Last edited September 11, 2011 2:29 am GMT (diff)