Re: Just say 'YES' to strings
- Posted by "Kat" <gertie at visionsix.com> Jun 03, 2004
- 444 views
On 3 Jun 2004, at 4:07, Al Getz wrote: > > Hello there, > > Im not sure if you all are talking about strings in general or > what, but what i'd like to see in Eu is this... > > include cfunc_links.ew > include string.e > > atom x > string s > > s="Hello Mars"&0 > > x=c_func(xSetWindowTitle, {s}) > > Note in order for the above C function call to work properly > the variable s would have to point to a memory location where > the string is located. The string gets there via the 's' variable > assignment statement. > > The thing about strings is if you know your variable is always > a string then it not only makes calling C functions that require > string arguments a lot easier it also means you can have better > type checking. > > For those people who dont like using this they dont have to > of course, and can continue using allocate_string() instead. > > It would be also possible to handle the string as both as string > and a sequence. All the usual operators would still apply, > except an Eu error would trigger if a program attemps to store > a value greater then #FF or less then #00 to a string element. That still leaves out multi-byte unicode letters. > Examples: > > string s > > s="Hello there"&0 > ?s --Hello there > s=s[1..5]&0 > ?s --Hello > x=c_func(xMyCStringFunction,{s}) > > It may even be possible to set it up so that you dont have > to keep using a terminating zero: > > s="Hello" > x=c_func(xMyfunc,{s}) > > although there would probably have to be a way to prevent the > zero terminator in some cases. > > Note in the above: > x=c_func(xMyFunc,{s}) > > when the function name "xMyFunc" is linked the type 'string' > is registered internally, so trying to pass anything other > then a string would trigger a Eu type error. > Example: > xMyFunc=LinkFunc(MyDll,"MyFunc",{C_STRING},C_ULONG) > > When a variable (such as s) is passed to this function during > a function call, anything other then a string type passed > as an argument triggers an error, just as any other type > error would cause. > > > Of course there are alternatives too. A nice one would be > to have an 'address of' operator that could be used to > get the address of a string already in a sequence. I used "address of" whatever in pascal a lot, ditto "pointer to" whatever, but RDS wants neither in Eu. It's handy for retypecasting, and indexing. Catch is, Eu does garbage collection, so updating the pointers after a collection could be time consuming. Kat