librelist archives

« back to archive

Another Another tnetstrings implementation [Lua]

Another Another tnetstrings implementation [Lua]

From:
Josh Simmons
Date:
2011-06-05 @ 13:27
So I finally got around to whipping up a Lua version.

https://github.com/jsimmons/tnetstrings.lua

At the moment it's trivial to create invalid data though, I'm just
using Lua's tostring for number output which will output using quite a
few different formats depending on the contents of the number. I'm not
sure whether to floor any numbers before sending them or what. On that
token, was a floating point tag coined?

There's a reasonable test suite and should be pretty fast, although
I've not done any actual profiling.

Next up is a big mongrel2-lua tidy effort and finally getting
tnetstrings support in.

Cheers,
Josh.

Re: [mongrel2] Another Another tnetstrings implementation [Lua]

From:
Armando Singer
Date:
2011-06-05 @ 20:23
The float type marker ended up as '^'. The format should be (quoting Zed's
email):

    No leading zeroes except for the float I think, so:
    
    float:   "(-|+)?[0-9]+\.[0-9]+"
    integer: "(-|+)?[1-9][0-9]*"
    
    I think that's right?  So -00000 is invalid, but -0000.10 would be and if
    the receiver can't parse it with their float parsing then it's an error.
    
    That's another thing we can probably add:
    
    "For all formats, the receiver can use whatever built-in type parser they
    want and reject anything they don't like, the above regex are only a
    *minimum* format they have to accept."

My implementation is here:
https://github.com/asinger/tnetstringsj

The python impl should also have support for all of the types.

The tnetstrings.org spec should probably be updated w/ the latest info.

Mine also allows more input options but since the regex only defines the
minimum, we're good. But the dumping should produce only what's in the regex.
I had to do some decimal formatting gymnastics.

Cheers,
Armando

On Jun 5, 2011, at 6:27 AM, Josh Simmons wrote:

> So I finally got around to whipping up a Lua version.
> 
> https://github.com/jsimmons/tnetstrings.lua
> 
> At the moment it's trivial to create invalid data though, I'm just
> using Lua's tostring for number output which will output using quite a
> few different formats depending on the contents of the number. I'm not
> sure whether to floor any numbers before sending them or what. On that
> token, was a floating point tag coined?
> 
> There's a reasonable test suite and should be pretty fast, although
> I've not done any actual profiling.
> 
> Next up is a big mongrel2-lua tidy effort and finally getting
> tnetstrings support in.
> 
> Cheers,
> Josh.