lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great steve donovan once stated:
> On Sat, Jan 5, 2013 at 12:03 PM, Marc Balmer <marc@msys.ch> wrote:
> 
> > One statement by a colleague is: "Now for the data transfer
> > representation, as in D.'s proposal, JSON is an option, but LUA is not,
> > simply because we have no (and there can not be any) small C binding to
> > it."
> 
> I have some sympathy with this, if one isn't already doing something
> non-trivial with Lua. JSON is nice and stupid, although personally I
> find Lua data easier to read.

  Another main difference between JSON and Lua is that Lua *is* a
programmimg langauge.  For instance, the blogging software I wrote [1] uses
Lua for configuration [2].  As such, I can do the following:

	process = require("org.conman.process") -- [5]
	os      = require("os")

	os.setlocale("en_SPC")

	process.limits.hard.cpu  = "10m"        -- 10 minutes
	process.limits.hard.core =  0           -- no core file
	process.limits.hard.data = "20m"        -- 20 MB

	name      = "The Boston Diaries"
	basedir   = "/home/spc/web/sites/boston.conman.org/journal"
	webdir    = "/home/spc/web/sites/boston.conman.org/htdocs"
	url       = "http://boston.conman.org/";
	author    = { name = "Sean Conner" , email = "sean@conman.org" }
	startdate = "1999/12/4"

	templates =
	{
	  {
	    template = "html/regular",
	    output   = webdir .. "/index.html",
	    items    = "7days",
	    reverse  = true
	  },

	  -- ... 
	}

  As a result, a bunch of code that used to exist to parse and set process
limits could be deleted.  *And* I get comments.  Now, had I used JSON [3] I
would still have to have code to parse and set process limits.  

  But on the other hand .. 

	local foo = require "non-existant-module"

  Yeah, you can exclude prebuilt functions to prevent this, but in order to
"parse" a Lua-based configuration, you'll need to support:

	expressions
	comments, both line and block
	strings, both line and block
	function creation (since you can still *define* them ... )

  In short, the Lua language.  The reason people choose JSON, besides
parsers written in a ton of languages [4], is that the resulting parsers are
*small* and pretty much straightforward to write (as I found).

  That said, I still prefer Lua over JSON myself.

  -spc

[1]	https://github.com/spc476/mod_blog

[2]	A relatively recent addition; the blogging software itself is about
	twelve years old now.

[3]	Which wouldn't be that much of an improvement over what I had.

[4]	My own implementation:
	https://github.com/spc476/LPeg-Parsers/blob/master/json.lpeg

[5]	Found here:
	https://github.com/spc476/lua-conmanorg