iamgreaser / iceball

Open-source rewrite of the VOXLAP version of Ace of Spades.
http://iceball.build
GNU General Public License v3.0
114 stars 32 forks source link

JSON writer #51

Closed iamgreaser closed 10 years ago

iamgreaser commented 11 years ago

This should theoretically be easier than the JSON parser, as instead of having to read char by char like it's nineteen-ninety-LL(1), a bit of printf() should do the trick... after discerning the types, of course.

Printing strings might be a bit tricky, as you need to deal with the escape codes, and we will almost certainly be using lua_tolstring to get them (\u0000 anyone?). Here it's probably best to read the string char-by-char, and feed the stuff into a switch statement.

We won't allow people to use a combination of numbers and strings for keys used in Lua lists. If there are numbers, it's an [ array ]. If there are strings, it's an { object }. If there are both, spew a lua_error(L, "THIS ISN'T RUBY"). If there are neither, it's an { object }, which from the Lua end is the same thing as an [ array ] so it doesn't matter - if it needs to be an [ array ], it will become an [ array ] once it has more stuff in it.

Make sure you have a tab-count variable in the json_write_object function (or whatever it's called). Yes, we will be using hard tabs, because soft tabs take up more room on the disk. Plus, soft tabs suck ass.

See http://json.org/ for more information on the syntax.

Ericson2314 commented 11 years ago

BTW Lua tables are actually created as arrays + hash tables if they contain string and integer keys, see http://www.tecgraf.puc-rio.br/~lhf/ftp/doc/hopl.pdf

rakiru commented 11 years ago

Why not use a 3rd party library? I know you'd prefer that everything was written in-house, but there is still quite a lot to do yet, so it seems a bit of a waste spending unnecessary time on stuff like this.

BR- commented 10 years ago

2ab3e8bad1e32b3d05477948354ca58 doesn't do "THIS ISN'T RUBY" checking and doesn't indent, but I think it's close enough to close this.