Lua Data Formats |
|
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:
Editor.com (Lua Workshop 2011 Talk) - discusses a good strategy for implementing declarative DSLs in Lua ([summary]).