r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Red] Red language group

Kaj
18-Jun-2011
[2148]
But the more tangible problem is that currently, you don't have to 
cast when you allocate a string, and that will change when a proper 
byte pointer is introduced
Dockimbel
18-Jun-2011
[2149]
Right, but this is an alpha, not a v1. Maybe I should postpone the 
beta announcement by a month or two?
Kaj
18-Jun-2011
[2150x2]
You don't have to, because the fix is only half a line, and I don't 
need it before Monday
Anyway, I've brought forward my concerns; that's all I can do
Dockimbel
18-Jun-2011
[2152]
Well, thanks for the feedback, I will think about all the possible 
options.
Kaj
18-Jun-2011
[2153x2]
OK, thanks
I see you're using byte! definitions for C functions that take integer! 
parameters. Is that guaranteed to be interpreted as an integer?
Dockimbel
18-Jun-2011
[2155]
Are you referring to memset() wrapper?
Kaj
18-Jun-2011
[2156]
Yes. What's the conversion applied there?
Dockimbel
18-Jun-2011
[2157x2]
No conversion at all. The memset case is a old C oddity that never 
got fixed. It should have a byte in the declaration instead of int. 
The algorithm in memset uses a byte and not an int, so the Red/System 
binding is not only safe, but also cleaner than the C one. The memset 
oddity is explained there: http://stackoverflow.com/questions/5919735/why-does-memset-take-an-int-instead-of-a-char
Jocko, answering your questions:
- is this correct ?
    Yes, I tested it here, works flawlessly.

- how and where de-allocate the c-string ?

    Same as in C, when you don't need it anymore. So in your code example, 
    it would be after "print res".

- why the end-string symbol is not added automatically ?

    Red/System is a low-level language, it treats c-string! as C does 
    with string, the trailing zero is only a convention. If ReadConsole() 
    doesn't add a trailing zero, only the programmer knows if and where 
    it should be added. Red/System can only add automatically trailing 
    zero on literal c-string! because, in that case, it can easily guess 
    where the c-string! ends.
Kaj
18-Jun-2011
[2159x7]
Doc, thanks for the link; that's informative
I've updated both my C library binding and my 0MQ binding to work 
with the latest Red
A lot of changes were needed, most of them for the stricter checking
Callbacks can now be passed to imported functions with fully defined 
specs. However, function specs can not be defined as the return value 
of an imported function:
on-signal: "signal" [  ; Register handlers for receiving system signals.
			signal		[integer!]
			handler		[function! [signal [integer!]]]  ; Flag or callback
;			return:		[function! [signal [integer!]]]
			return:		[handle!]
		]
Also, callbacks can't be passed as such to native functions. In some 
cases they can still be passed as unspecified handles, but those 
can't be cast to callback functions. I have a wrapper for atexit() 
that is now impossible to define:
on-quit: func [  ; Register handler for normal program termination.
;	handler		[function! []]  ; Callback
	handler		[handle!]  ; Callback
	return:		[logic!]
][
	not as-logic _on-quit handler
]
jocko
19-Jun-2011
[2166]
Doc, thanks for yor answers
Dockimbel
19-Jun-2011
[2167x4]
Kaj: function! is just a pseudo-type (not a first-class type) that 
was introduced just to be able to verify callback signatures when 
passed to an external library.
I will have a look today on your issue and see if allowing function! 
to be passed as argument and returned as value is safe and side-effect 
free in the current state of the implementation.
Kaj: on Windows, it is possible to use _get_osfhandle() to retrieve 
the file handle for stdin/out/err (http://msdn.microsoft.com/en-us/library/ks2530z6.aspx)
I can't find an equivalent in UNIX world.
Kaj
19-Jun-2011
[2171]
I know, you have to import it as a symbol as far as I can see
Dockimbel
20-Jun-2011
[2172]
Kaj: you have now a polymorphic NULL for all pointers (struct, pointer, 
c-string) and a new pointer! [byte!] type. byte-ptr! has been redefined 
to pointer! [byte!] instead of c-string!.
Oldes
20-Jun-2011
[2173]
Is it possible to specify a build target per file? If I don't want 
to use %builds/ folder, but for example %builds/project/ and specify 
it in the project.reds file header.
Dockimbel
20-Jun-2011
[2174]
Not yet, but Andreas should add it soon. Taking the output path/name 
from script header is a good idea.
Oldes
20-Jun-2011
[2175]
Cool... I'm able to obtain image size from red using iMagick
Dockimbel
20-Jun-2011
[2176]
Nice, let us know if you hit any issue.
Oldes
20-Jun-2011
[2177x5]
the main issue is that I had to find out, how to print integers:) 
Kaj's C-library is not working on windows.
*** Compilation Error: multiple type casting not allowed
*** in file: %runtime/../library/C-library.reds
*** in function: temporary-name
*** at:  [as c-string! null]
here is a fix:
-- 	_temporary-name as-c-string none
++	_temporary-name none
for a real work with iMagick, the decimal numbers are required.
Dockimbel
20-Jun-2011
[2182x2]
Kaj has not yet updated the C library binding to the latest Red/System 
version.
Float support will either be added at Red level or at Red/System 
level, depending on how the Red compiler will be built.
Kaj
20-Jun-2011
[2184x4]
A bit hard to update my binding to a Red version that is released 
while I sleep, but I will have a look
By the way, my C binding was developed for Windows so far, and the 
only thing I've really used it for is printing integers :-)
I've just tested it for the the first time on Linux last night, and 
printing worked there, as well
The new pointers sound good, Doc
Dockimbel
20-Jun-2011
[2188x3]
Glad you like it.
Kaj: sorry if my sentence sounded bad, I was just trying to be informative. 
That is a typical case of impedance mismatch between a thought and 
how it ends up being written. :-)
Btw, about function! extended support: after making a few tests in 
the compiler to extend it, I can't support it for argument passing 
and as return value for native functions without making function! 
type fully first class. The changes required for that are too deep 
and too numerous to be made now.
Kaj
20-Jun-2011
[2191x7]
No problem, I know all about it :-)
I've left the alternative function! uses commented out in my code, 
so they'll be there awaiting a future version
Updated the C and 0MQ bindings to the latest changes
Jocko, input-line works on Linux. I'll test it on WINE later tonight
When I compile this:
either as-logic 0 [
	no
][
	yes
]
I get