[Gambas-devel] ideas for two new string functions

Benoît Minisini gambas at ...1...
Wed Nov 24 23:46:09 CET 2010


> On 11/23/2010 08:33 PM, Benoît Minisini wrote:
> > In revision #3318, you now have a function named Mem$() that returns a
> > string representation of a value.
> > 
> > For example:
> > 
> > Mem$(10) will return the 4 characters string "\x0A\x00\x00\x00".
> > 
> > Mem$(Pi) will return the 8 characters string representing the Pi number
> > as it is stored in memory.
> > 
> > And so on...
> > 
> > To do the contrary, you now must use the Int@(), Float@()... functions
> > that read a value directly into memory.
> > 
> > For example:
> > 
> > Dim sStr As String
> > sStr = Mem$(Pi)
> > Print Float@(VarPtr(sStr))
> > 
> > -->  3.14159265...
> 
> That is extremely awesome. Things like that are going to give GAMBAS a
> serious advantage over many languages, especially considering how
> friendly it is. Sending multiple datatypes as a single UDP packet and
> re-assembling them on the other end will be super easy now. There are
> probably a million other uses people will eventually discover as well.
> Thanks again Benoît.

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.

Regards,

-- 
Benoît Minisini




More information about the Devel mailing list