• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[#Red] Red language group

DocKimbel
30-Apr-2013
[7465x3]
Mainly for external (from bindings) events propagation to Red level.
It will be also used in the Java and obj-c bridges.
Added new #call compilation directive to enable calling Red functions 
from Red/System.

Syntax:
    #call [<red-fun-name> <arg1> <arg2> ...]

Notes:
- it can be used only in routines body or #system body block.

- only function! value can be invoked (refinements not supported).

- arguments are either literal values or Red/System global/local 
variables.

- type casting (to a Red internal datatype) is allowed in arguments 
(avoids wasting an extra variable).
PeterWood
30-Apr-2013
[7468]
I think it is worth stressing that this is a feature of the Red compiler 
and is not available to Red/System programs compiled with the Red/System 
compiler.
Gregg
30-Apr-2013
[7469]
So you can call Red apps from Red/System, but you can't call Red/System 
apps from Red/System, correct?
DocKimbel
30-Apr-2013
[7470x3]
Peter: right, I've forgot to mention it.
Gregg: not sure what you mean by "Red/System app".
The #call directive invokes a Red function, it has nothing to do 
with Rebol's CALL native.
Gregg
30-Apr-2013
[7473]
R is a compiled Red app. RS and RS2 are compiled Red/System apps. 
From RS2, I can #call into R, but not RS, correct?
DocKimbel
30-Apr-2013
[7474]
No, it's not Rebol's CALL native.
Gregg
30-Apr-2013
[7475x2]
Because it invokes a Red function.
Right, I understand that. I don't mean CALL, I mean #call.
DocKimbel
30-Apr-2013
[7477x2]
There's no way you can call any function from one process to another.
#call is meant for calling Red code from Red/System in the same app.
Gregg
30-Apr-2013
[7479]
Ah, I see my confusion. I thought this was some tricky IPC thing, 
but it's just a callback def in Red, correct?
DocKimbel
30-Apr-2013
[7480]
Yes. :)
Gregg
30-Apr-2013
[7481]
Oh, I get it now. Thanks.
Kaj
30-Apr-2013
[7482]
Petr, in the currently available code, the GTK binding can't function 
without a callback from Red/System into Red; as Doc says, to pass 
GTK events into the Red GUI dialect engine. So far I constructed 
the callback the ugly way, but there's official support now
DocKimbel
30-Apr-2013
[7483]
BTW, I've hesitated to name it #callback instead of #call.
Gregg
30-Apr-2013
[7484x2]
It sounded like deep voodoo required for your bridging needs.
I guess it is still deep voodoo, just a different kind. :-)
DocKimbel
30-Apr-2013
[7486]
Actually, it's fairly simple, think about a GUI app that sends a 
click event to your Red/System binding, how do you pass the event 
to Red code if you can't call it from Red/System. ;-)
Gregg
30-Apr-2013
[7487x2]
Right, easy for people like me to use, but voodoo under the hood.
If you do voodoo, I can call you WitchDoc. ;-)
Kaj
30-Apr-2013
[7489x3]
It replaces this:
; Call back into Red
			stack/mark-func ~on-action
			integer/push as-integer face
			integer/push action
			f_on-action
			stack/unwind
			stack/reset
For a callback with two arguments
DocKimbel
30-Apr-2013
[7492]
It just pushes the Red/System arguments on a new Red stack frame 
and invokes the Red function. No black magic required. ;)
Gregg
30-Apr-2013
[7493]
Don't tell me that. I want to imagine that it's *reeeallly* hard 
and bad things will happen if I even try to understand it. :-)
Kaj
30-Apr-2013
[7494]
I was convinced about that for Unicode, and it didn't work out well 
;-)
DocKimbel
30-Apr-2013
[7495x2]
Ah, one thing to not, the type casting shortcuts like: as-integer, 
as-byte, etc.. won't work within #call because the Red/System preprocessor 
is invoked too late.
not => note
Gregg
30-Apr-2013
[7497]
That sounds important to document.
Pekr
30-Apr-2013
[7498]
I would probably prefer it being called #callback, or some ppl might 
relate it to REBOL's  CALL :-)
DocKimbel
30-Apr-2013
[7499]
Actually, it is related a bit, because in both cases, you are making 
an "external" call.
Kaj
30-Apr-2013
[7500]
#call is more generic; you're not necessarily calling back
DocKimbel
30-Apr-2013
[7501]
That's why I've opted finally for just #call.
Kaj
30-Apr-2013
[7502]
A Red/System logic! is stored as integer!, right, not byte!?
DocKimbel
30-Apr-2013
[7503]
Integer! yes.
Pekr
1-May-2013
[7504x3]
Just one question - I can see refeinements again mentioned. Is that 
technologically it is not easy achievable, or will we get refinement 
support for #call and routines later in the future?
Doc - strange thing on Trello - I I would not have my link in the 
cache, Search on Trello.com does not show any results for Red, or 
Red programming language ... strange ...
I I would = If I would ....
DocKimbel
1-May-2013
[7507]
Refinements: these are a matter of cost vs added value. It costs 
significantly to add refinements support to routines and #call, and 
the added value is small. So, it is possible to add them, but it 
falls in the "nice to have" feature list, not "must to have", so 
they are very low priority.
Henrik
1-May-2013
[7508x2]
Does Red attempt to answer Carl's old question of passing big options? 
Carl wrote a document on this once, but I can't find it.
Essentially it was the idea of doing something else, when a function 
grows to have too many refinements, as this is both not very user 
friendly and reduces performance.
DocKimbel
1-May-2013
[7510]
APPLY is there for that (not yet implemented in Red though).
Henrik
1-May-2013
[7511]
ok
DocKimbel
1-May-2013
[7512]
There's also the special /options (IIRC) refinement in Topaz that 
allows use to pass a block with set-words/value for each arguments 
(including refinements). That should be also a solution to consider.
Gregg
1-May-2013
[7513]
I've sometimes thought /WITH would be a good name for the arg block 
idea, though it would conflict with a few existing cases.
Kaj
1-May-2013
[7514]
Agreed, I'm using that when marshalling Red to Red/System parameters