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

World: r4wp

[#Red] Red language group

Endo
22-Mar-2013
[6431]
I use 'q A LOT on R2 console. In scripts no need that shortcut but 
on console it is a MUST for me :) I open/close R2 console every 30 
seconds to do something like english-turkish translation, to see 
NOW, to use functions manipulating clipboard etc. then Q-it..
Arnold
22-Mar-2013
[6432]
Hi do not recall it exactly but I think it was when I was developing 
the checkersgame program and somehow I had a variable q and when 
the code was executed the program and the console closed forcing 
me to restart REBOL.  

The solution you have chosen now will pretty wel have prevented this 
behaviour, still offering a shorthand for quit in console mode is 
welcomed by many. Good thinking again!
Oldes
22-Mar-2013
[6433]
Just playing for a while after some time.. What steps are required 
to add a new native!? I was trying to duplicate stats native as is 
in this commit, but maybe it's not complete as now the console quits 
immediately.

https://github.com/dockimbel/Red/commit/1836a0cd04f703bdd28bfb177e99c317340be5d1
DocKimbel
22-Mar-2013
[6434x2]
I plan to write an HOW-TO guide for that someday, but in the meantime 
and in a nutshell, this is what is required:

1) NAT_<name> enum entry in %macros.reds (order matters!)


2) pointer entry in REGISTER argument block (same order as in macros) 
in %natives.reds


3) an entry point implementation in %natives.reds (if the code is 
too big you can move it elsewhere as long as the entry point is in 
natives.
Of course, you'll need to use the internal Red runtime API and stack. 
No docs for now, as it is not stabilized fully, but you can guess 
a lot of it from other natives and actions implementation.
Oldes
22-Mar-2013
[6436x4]
hmm.. that's what I was doing.. but have:
*** Runtime Error 1: access violation
*** at: 004188CEh
In boot.red
foo: make native! [
	[]
	#get-definition NAT_FOO
]
in natives
foo*: does [halt]
and registered as :foo*

in macros enum added NAT_FOO
when I change #get-definition NAT_FOO  --> #get-definition NAT_HALT 
=== it's working again
Ach... it looks there is some confilct with the name FOO for my native
DocKimbel
22-Mar-2013
[6440]
Tested here, works well.
Oldes
22-Mar-2013
[6441x2]
hm.. now it works here as well even with the name foo... maybe I 
just fooled the compiler as I compile from REBOL console using:

do/args %red.r "-v 0 %red/tests/console.red -o %../builds/console"

so possibly if there was some error before, the compiler state was 
not cleared
so now I have my first native which halts console:)
DocKimbel
22-Mar-2013
[6443x2]
That's possible, the %boot.red extraction routine do not refresh 
their data structures IIRC.
BTW, you can add also new natives using the routine! type. Routine 
body are coded in Red/System too, so they are equally efficient as 
natives. Routines are easier to define (no need to mess around with 
runtime internals). Their only drawback so far is that they don't 
support refinements (we might add that later).
Oldes
22-Mar-2013
[6445]
I would like to access stdout, is it possible from routine?
DocKimbel
22-Mar-2013
[6446]
Sure, use one of Red/System output function: print, print-line, print-wide...
Gregg
22-Mar-2013
[6447]
Congratulations Oldes!
DocKimbel
22-Mar-2013
[6448]
Routine == Red/System + automatic argument/return-value marshalling.
Pekr
22-Mar-2013
[6449]
Refinements would come in handy at some point in future, no?
Oldes
22-Mar-2013
[6450x2]
What if I want native, which takes one integer! argument? stack/arguments 
seems to return pointer
found it... using:
code: as red-integer! stack/arguments
int: code/value


so now I can change colors in console... will clean it later and 
upload:) now back to work
DocKimbel
22-Mar-2013
[6452x3]
stack/arguments will return you a pointer on a series slot in stack. 
If you want to access it's data value, you need:

    int: as red-integer! stack/arguments
    print int/value

Modifying is straightforward:
    int/value: int/value + 1		;-- incrementing example.


Last return value should be at stack/arguments position, in this 
case, it is already.
Great! :-)
Will be back later.
Oldes
22-Mar-2013
[6455]
I wanted to try the console on MacOS, but got missing /usr/lib/libhistory.dylib 
.. is it supposed to be working?
Kaj
22-Mar-2013
[6456]
Only theoretically, if you install GNU ReadLine (including LibHistory) 
on Mac. I don't know if it's available, but you would probably have 
to install one of the porting package projects
Oldes
22-Mar-2013
[6457]
ah.. I see.. there is a TODO in the code
Kaj
22-Mar-2013
[6458x3]
Yes, and nobody has confirmed the proper library names on OS X
Do you know if any other ReadLine comes with OS X?
Is there ldd or something, to see which libraries are missing that 
the executable wants?
Oldes
22-Mar-2013
[6461]
libreadline is available, libhistory not
Kaj
22-Mar-2013
[6462]
Is it a BSD version, or GNU?
MarcS
22-Mar-2013
[6463]
Here /usr/lib/libreadline.dylib is a symlink to the editline library 
(it's not GNU readline)
Kaj
22-Mar-2013
[6464x2]
Thanks. I would expect LibReadLine to be loaded before LibHistory, 
so the fact it errored on the latter may mean that it has loaded 
ReadLine successfully. Others often try to have a compatible interface
If so, you can try to comment out the #import of History-library, 
and in INPUT, "add-history line"
Oldes
22-Mar-2013
[6466x2]
that's what I did now and the console is working.. just without history:)
just my colors are different.. instead of red color it's blue and 
underlined
Kaj
22-Mar-2013
[6468x4]
Cool, thanks! The release will have OS X console support :-)
Doc wants to implement history in Red. I guess he will also want 
to fix the red colour :-)
Is that in the demo.red? EditLine should just give input the Mac 
way
While we're at it, I would really like you to confirm the availability 
and name of the cURL library, which I have penciled in as libcurl.dylib
Oldes
22-Mar-2013
[6472x2]
libcurl is there
also libcurl1.3 and libcurl1.4
Kaj
22-Mar-2013
[6474x2]
Great, thanks. So libcurl.dylib exists?
And OpenGL? I have it penciled in as libGL.dylib
Oldes
22-Mar-2013
[6476x2]
/opt/X11/lib/libGL.dylib, so probably ok
Another small bug in OSX console.. I can delete even the prompt.. 
is it same on Linux?
Kaj
22-Mar-2013
[6478x2]
Thanks!
It's because the new Red console tries to handle the prompt. It should 
leave it to ReadLine, until it's reimplemented in Curses
Oldes
23-Mar-2013
[6480]
I wanted to add colors into the console, but I'm not sure how... 
exactly the color codes are different in Windows from rest of the 
world. What would be the best way how to declare global constants 
per OS?