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

World: r3wp

[!REBOL3 Extensions] REBOL 3 Extensions discussions

Maxim
8-Nov-2010
[1539]
if you download the OpenGL demo, there is a complete working setup. 
 it has a makefile and a visual studio 2008 setup .  it should help 
you out.
Oldes
8-Nov-2010
[1540x3]
I'm completely C/C++ newbie, so I would like to know, how to make 
the extension, if I have precompiled DLL.
For example, In R2 I can simply download the DLL like this one:
http://zlib.net/zlib125-dll.zip

And simply do:

zlib.dll: load/library %zlib1.dll

zlib-version: make routine! [ return: [string!] ] zlib.dll "zlibVersion"
zlib-version
;== "1.2.5"


Is there someone who can write a simple tutorial - C extension with 
the zlib-version command?
I understand the REBOL part of it, but would like to see how to do 
the DLL trick part. Including the correct gcc command.
I would like to start with simple gcc instead of dealing with VS 
projects.
jocko
8-Nov-2010
[1543]
Oldes, I have uploaded an ImageMagick extension.
GrahamC
8-Nov-2010
[1544]
Nice
Andreas
8-Nov-2010
[1545]
Oldes, I've built you a simple "zlib-version" extension.
Oldes
8-Nov-2010
[1546x2]
Could you upload the C source as well? Btw.. I would rather use linkage 
to MagickWand.dll to be able use direct commands instead of command 
line like IM commands.
Great, I will check the zlib:) I'm looking forward to learn something.
Andreas
8-Nov-2010
[1548x5]
No tutorial yet, but see I hope it helps nevertheless:
http://bolka.at/2010/rebol3/ext-zlib-20101108.zip
Extract this into your hostkit folder, so that you'll have an ext-zlib/ 
folder in the hostkit.
Then run make, and you should see something like the following:
$ make

gcc -DTO_WIN32 -I ../src/include -I include -mdll -L . -lzlib1 -o 
zlib.dll zlib.c
Afterwards you should have a fresh "zlib.dll" which is the extension.
Now run the accompanying zlib.r, and you should get:
$ r3-a110-3-1 -q zlib.r
1.2.5
Oldes
8-Nov-2010
[1553x2]
it works.. thanks.. but I must say, that in R2 it was easier;-)
is there a reason why there is:
#include <stdio.h>
#include <string.h> 
?
Andreas
8-Nov-2010
[1555x2]
stdio.h is a leftover and not needed.
string.h is for strlen.
Oldes
8-Nov-2010
[1557]
And isn't the conversion to a REBOL string quite complicated?
Andreas
8-Nov-2010
[1558x3]
Yes, a bit. There may be a simpler way. Or we could bundle a few 
such helper functions into a support library (as Max did in his OpenGL 
work).
Also note that this is not really comparable to using dlls with the 
/Library stuff in R2.
This facility simply did not exist in R2. On the other hand, /Library 
does not yet exist for R3 (but only because no one has written it 
yet).
Oldes
8-Nov-2010
[1561]
I know. This is a good start for me:) btw. is it possible to create 
extzlib.dll which would contain the zlib1.dll? I don't need it, just 
asking.
Andreas
8-Nov-2010
[1562x4]
Yes and no.
Yes, you can create an extension which contains the zlib library.
No, you can't do that from zlib1.dll, you'd have to use the zdll.lib 
in lib/.
You'd use

gcc -DTO_WIN32 -I ../src/include -I include -mdll -o zlib.dll zlib.c 
lib/zdll.lib


to statically link zlib into your extension (still called zlib.dll 
in the above).
Oldes
8-Nov-2010
[1566]
are you sure? with this version the zlib1.dll is still required
Andreas
8-Nov-2010
[1567]
Hmm, then zdll.lib probably is an import dll. Let me check.
jocko
8-Nov-2010
[1568]
developing an extension to wrap MagickWand is a huge work, because 
of the large number of functions, and data formats. It's better, 
in this case, to develop a full dedicated application in c, or, at 
least a dll with higher level functions ... wihch is approximately 
the case of ImageMagickObject. In other words, I am not convinced 
of the interest to program in Rebol if you want to use the full set 
of low level image processing functions.
Maxim
8-Nov-2010
[1569]
yes, its VERY usefull... one doesn't want to have to compile applications 
and stuff... AFAIK there are binding to other languages which use 
the full IM suite.  

but yes its a lot of work.
Andreas
8-Nov-2010
[1570]
(Yes, lib/zdll.lib seems to be an import library. So no static linking 
against it. Sorry for the confusion.)
Oldes
8-Nov-2010
[1571x3]
Jocko, I don't think it's so much work. For example in R2 I use this: 
http://box.lebeda.ws/~hmm/rebol/im-min.r
Of course, better to use REBOL script to make the C code. Btw. your 
version is not working here. I get this result:
Error (null) (0x80040154)
Error (null) (0x80040154)
Error (null) (0x80040154)
Error (null) (0x80040154)
Error (null) (0x80040154)
Error (null) (0x80040154)
Also is it possible to use your version to for example load TIFF 
image into REBOL?
jocko
8-Nov-2010
[1574]
Have you installed ImageMagick , and ImageMagickObject ?
Oldes
8-Nov-2010
[1575]
I have ImageMagick instaled. If installing ImageMagickObject means: 
regsvr32 /c /s ImageMagickObject.dll than I have it as well.
jocko
8-Nov-2010
[1576]
With this version, all the inputs and outputs are files. I'm waiting 
for more specs before loading directly into memory. It's possible 
to convert many file formats (including tiff) into may others.
Oldes
8-Nov-2010
[1577x2]
hm.. but I don't see ImageMagickObject.dll in my Imagick folder.
btw.. what is difference between simple CALL with args and using 
the ImageMagickObject?
jocko
8-Nov-2010
[1579x2]
could you check again the installation of ImageMagickObject by doing 
regsvr32 ImageMagickObject.dll (without /c and /s, you will have 
the messages indicating that everything is ok)
That's also a question for me ...

Part of the answer is that using it in a cpp exe will allow to execute 
these functions without te burden of executing a c process while 
masking the dos window (which is a huge challenge here, and I do'nt 
know why). In the case of Rebol, yes, the interest is not so evident.
Oldes
8-Nov-2010
[1581x2]
not found. So I don't have it.
Andreas, so I must copy all series to REBOL's one as you did in the 
zlib example? I guess I will need to put images into REBOL in pure 
binaries at this moment, right?
jocko
8-Nov-2010
[1583]
Maxim, yes, I have seen bindings to other languages, but I am still 
not convinced that its much simpler than coding directly in C or 
C++

Oldes, I did not know im-min.r. It's a nice work. I have not enough 
experience in Extensions to do such work, as the input-output methods 
of R3 extensions are a little tricky.
Maxim
8-Nov-2010
[1584x3]
the images are pointers, so the data doesn't need to be copied if 
you are just manipulating it.   though it seems there was some image 
bugs in the A107 (not sure where) which AFAIK are fixed but not yet 
released in current host-kit (cyphre knows for sure).
the images are pointers
 ....   more precisely:  


R3 image! datatypes are pointers in the extension, so you can access 
them as arrays directly.
though it does require usually thread safety and might require GC 
protection depending on what you are doing.
Oldes
8-Nov-2010
[1587]
How to free the extension?
Maxim
8-Nov-2010
[1588]
AFAIK we can't currently unload extensions.  


The extension interface actually is designed to support it, but right 
now, I think its never called and there is no way to trigger it from 
the REBOL code AFAIK.