Posted 25 November 2015 - 06:37 AM
I've looked around for quite a while and found a ton of information about splitting strings WITH delimiters in LUA, but I can't find a morsel about doing it without. Here's some relevant backstory about why I want to do it:
Just out of boredom I'm writing a rudimentary networking API with lua (just to see if I can). Info is sent in packets, like normal IP packet based networking. Different information is stored in different areas of the packet. For example,
1010100000110100001100101011011000110110001101111001000000111011101101111011100100110110001100100
The red first bit indicates the starting bit for the packet.
I plan to insert another category here between red and blue for routing bits.
The blue second through ninth bits indicate the length of the packet's contents (the green bits, or everything after what will be expanded upon as the routing bits).
The green bits are then the information, in binary, within the packet.
For example, that packet says:
start 80 HELLOWORLD.
Now, what I need to do is take that and break it up into an array/table I can reference by index so I can parse the packet. I just don't know how to do that without making a gigantic if/then program.
One solution I know of would be using a simple string.find based function to explode it and insert a comma after every single bit, but wouldn't that be extremely inefficient? It'd double the length of every packet. Is there another way? :angry:/>
Just out of boredom I'm writing a rudimentary networking API with lua (just to see if I can). Info is sent in packets, like normal IP packet based networking. Different information is stored in different areas of the packet. For example,
1010100000110100001100101011011000110110001101111001000000111011101101111011100100110110001100100
The red first bit indicates the starting bit for the packet.
I plan to insert another category here between red and blue for routing bits.
The blue second through ninth bits indicate the length of the packet's contents (the green bits, or everything after what will be expanded upon as the routing bits).
The green bits are then the information, in binary, within the packet.
For example, that packet says:
start 80 HELLOWORLD.
Now, what I need to do is take that and break it up into an array/table I can reference by index so I can parse the packet. I just don't know how to do that without making a gigantic if/then program.
One solution I know of would be using a simple string.find based function to explode it and insert a comma after every single bit, but wouldn't that be extremely inefficient? It'd double the length of every packet. Is there another way? :angry:/>