[Gambas-devel] ideas for two new string functions

Benoît Minisini gambas at ...1...
Sat Nov 27 01:09:38 CET 2010


> On 11/24/2010 05:46 PM, Benoît Minisini wrote:
> > I changed my mind.
> > 
> > I replaced Mem$() by specific Mk*$() functions: MkBool$(), MkByte$() -
> > stupid, as it is the same as Chr$()! - MkShort$()...
> > 
> > And now I notice a problem: these functions (and their counterpart,
> > Bool@, Byte at ...570...) use endianness, so you cannot use them to exchange data
> > between a big-endian computer and a little-endian computer.
> > 
> > I think the right solution would be using structures, and adding
> > something to convert a entire structure into a string. And, better,
> > allowing READ and WRITE to read/write structures directly to a stream.
> > 
> > That way, you will define your messages as structures, and just use READ
> > and WRITE to send them to your UDP sockets in a endianness-agnostic way.
> 
> That is a better solution. I'm still stuck in the old QB/VB mindset, but
> your solution is more elegant and requires less coding, maintenance and
> documentation. The efficient ability is what's important, so as long as
> the implementation is logical it will add a lot. I'll code using patched
> gb2 but am looking forward to gb3.

All that is now implemented in revision #3323.

By using a structure and the WRITE instruction on a UDP socket, you send the 
structure contents in one shot, and so in one UDP message.

To get the message on the other side, use the READ instruction with the As 
XXXX syntax, where XXXX is the structure name. READ will return you a newly 
allocated structure with the contents of the message.

But, of course, you can send a string build with the MkByte$(), MkShort$()... 
functions too.

One more reason to try Gambas 3 now! :-)

Regards,

-- 
Benoît Minisini




More information about the Devel mailing list