string.sub with null char is a problem

I am trying to get an rfxcom device to speak to vera. Progress is slowing quickly because problem after problem keeps me from making steps forward.

I finally have a message and am trying to interpret the message. The data is coming in very quickly, and in the RAW format I have to split the buffer into the separate messages. There are however null characters in the buffer. Now even string.sub is playing up.

string.sub(“abc\000defghi”, 2, 6) should give “bc\000de” but instead it gives “bc”

this is very unfortunate on RAW data processing.

I have written my own string.sub function in the mean time.

In the last few days I have stumbled upon missing bit operations, no support for millisecond timing (socket.gettime() does not work) and now I have to create my own string manipulation routines.

My development cycle has slowed down a great deal.

Am I missing something? Or is the Lua language very cramped for the job at hand?

before going much further, you might want to check/print [tt]type(lul_data)[/tt] in your [tt]incoming[/tt] block. I’ve always done a [tt]tostring[/tt] on it, to force it to string, since I’ve assumed it’s actually binary/byte-oriented data.

If it’s binary, and you have true binary data going through it (including 0’s), then you should buffer it into a byte buffer instead. If it’s coming in as “string”, and you’re processing as RAW, then you can convert the single byte at that point also.

This should avoid the zero-terminated-string problem you’re currently seeing.

Also note that zero-term strings are referenced in the programming manual:
Programming in Lua : 21.2.2

since Lua uses zero-term strings, which is presumably why it’ll be difficult to do translations (etc).

In the last few days I have stumbled upon missing bit operations, no support for millisecond timing (socket.gettime() does not work) and now I have to create my own string manipulation routines.
The Lua folks, for better or worse, think they only "own" the core. Virtually everything is an add-on. You get used to it eventually, and your productivity will speed up, but it'll test your CompSci 101 in the meantime ;)
socket.gettime() does not work
It's been a while since I checked it, but last time I used gettime() it was functioning for me. I used it in this slice of code to get some timing data: http://code.mios.com/trac/mios_sqblaster/browser/trunk/I_SQBlaster1.xml#L52