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

World: r3wp

[!REBOL3 Extensions] REBOL 3 Extensions discussions

Kaj
26-Jan-2011
[2115]
The common use case is a modular operating system. You have a standard 
R3 installed. During the life of the system, you install new extensions 
and programs. R3 makes the extensions be operating system dynamic 
libraries and lets the OS look for them, so they must be installed 
in the OS. You don't want to also have to embed each new extension 
in a new R3 binary. You want to install and write separate REBOL 
scripts that load these extensions, and you want those scripts to 
be cross-platform, because they easily can be
BrianH
26-Jan-2011
[2116x2]
So, you want to make a modular OS that has all dynamic libraries 
be R3 extensions natively - LOAD-EXTENSION won't load arbitrary libraries, 
just extensions - and you want the library filename suffix to be 
something other than .rx. OK.
LOAD-EXTENSION doesn't do lookup beyond the current directory, so 
if you want to have it use some library path you have to add that 
in the host code, or %rebol.r. Either way you can add extensions 
and modules programmatically to the R3 runtime before the script 
you're running starts. If you want your scripts to be cross-platform 
then you probably shouldn't use a platform-specific file extension 
for the files, but if they are loaded or delayed in the host code 
or %rebol.r then it wouldn't matter.
Oldes
26-Jan-2011
[2118]
What's the problem? Even in R2 I was using code like:
	lib_ImageMagickWand: load/library either system/version/4 = 3 [
		%/c/utils/ImageMagick/CORE_RL_wand_.dll
	][	%/usr/lib/libMagickWand.so ]

I prefere to have this under control. The location may differ on 
different platforms.
BrianH
26-Jan-2011
[2119]
For that matter, code like that can go in %rebol.r and then scripts 
won't have to even know that an extension isn't a regular module, 
as long as the API matches what they expect.
Kaj
26-Jan-2011
[2120]
Oldes, R3 has decided to let the OS find an extension as a native 
library. I really don't want to override that and write my own loader 
in every script
BrianH
26-Jan-2011
[2121]
Are you saying that on Linux and/or Syllable LOAD-EXTENSION looks 
up the extensions in the system library path? Weird.
Kaj
26-Jan-2011
[2122x2]
Not weird, nice :-)
You may want to review my documentation for the cURL binding
BrianH
26-Jan-2011
[2124]
Too late at night for me to read documentation :(
Kaj
26-Jan-2011
[2125]
It's the logical effect of using the system's loader
Oldes
26-Jan-2011
[2126]
https://github.com/Oldes/R3A110/blob/master/extensions/zlib/zlib.r3
Kaj
26-Jan-2011
[2127]
I'm going to sleep, too
BrianH
26-Jan-2011
[2128]
That sounds really dangerous with security turned off. Be careful.
Kaj
26-Jan-2011
[2129]
Don't worry, I am the master of my systems
BrianH
26-Jan-2011
[2130]
I don't get it Oldes. Why is it called %zlib-rxt.dll, when it could 
just as easily be called %zlib.rx and not have the platform-specific 
code?
Kaj
26-Jan-2011
[2131]
Yes
BrianH
26-Jan-2011
[2132]
But either way, that works.
Oldes
26-Jan-2011
[2133]
I'm a newbie.. I expect that when I build DLL against windows version 
of the lib, it will not work on Linux.. or maybe I'm wrong.
Kaj
26-Jan-2011
[2134]
That's true, but it's not tied to the name, Brian tells us
BrianH
26-Jan-2011
[2135]
True. You would use a different file for Linux, though it could also 
be called %zlib.rx :)
Kaj
26-Jan-2011
[2136]
I admit I confuse people by violating this truth and running the 
Linux binary on Syllable :-)
Oldes
26-Jan-2011
[2137]
But than I need zlib.dll and zlib.so in the folder.. and what if 
I don't have zlib.so yet?
Kaj
26-Jan-2011
[2138]
Since they don't work on both OSes, you wouldn't install them both. 
You install the matching one under the same name
BrianH
26-Jan-2011
[2139]
Then don't have zlib.rx in that directory either :)
Oldes
26-Jan-2011
[2140]
What is content of zlib.rx?
BrianH
26-Jan-2011
[2141]
The R3 extension wrapper for ZLib.
Oldes
26-Jan-2011
[2142]
that's the zlib.r3 for me.
BrianH
26-Jan-2011
[2143]
Or the R3 extension that statically links ZLib if you like.
Oldes
26-Jan-2011
[2144]
I don't get it.. I will wait for real life example..I'm fine how 
I have it now.
BrianH
26-Jan-2011
[2145]
In your case you could just rename zlib-rxt.dll to zlib.rx and it 
would work.
Oldes
26-Jan-2011
[2146]
And it will work on Linux?
BrianH
26-Jan-2011
[2147]
You would then import %zlib.rx instead of %zlib.r3. It would work 
on Linux if you made a Linux build of zlib as a R3 extension and 
also called it zlib.rx.
Oldes
26-Jan-2011
[2148x2]
But I want to make clear that the file is DLL, not SO.
maybe I will need my extension on linux later so I will make the 
SO, and I want both in the same directory, not just one, which I 
use at this moment. I want to have my files structure platform independent.
BrianH
26-Jan-2011
[2150]
Why? Don't you put other platforms' extensions in different directories? 
There are multiple platforms that use .dll and .so, remember.
Oldes
26-Jan-2011
[2151]
no... I use same structure.
BrianH
26-Jan-2011
[2152]
And when you install it you don't need to install other platforms, 
just the platform you're on. So you only install the zlib.rx for 
your platform.
Oldes
26-Jan-2011
[2153x4]
I do not install... I just copy folders. the true is, that now it 
can be more complicated as I have also the C sources in the same 
dir.
never mind... this is just a minor detail. Form me is important I 
can decompress zlib data as I could with R2. That's all.
If I had more time, it would be good to try some zlib/gz scheme.. 
but that's not important for me at this moment.
What is more important - can we UNLOAD the extension?
Kaj
26-Jan-2011
[2157]
I thought that was included in R3 now?
BrianH
26-Jan-2011
[2158x2]
You can't unload extensions.
Zlib in R3 doesn't work.
Oldes
26-Jan-2011
[2160]
http://issue.cc/r3/1667
BrianH
26-Jan-2011
[2161]
Kaj, here's an example %rebol.r for your scenario:

REBOL []
use [sys-path] [
sys-path:  %/some/safe/directory/full/of/extensions/
sys/load-module/delay map-each x read sys-path [sys-path/:x]
]
Oldes
26-Jan-2011
[2162]
I have no time to wai for built in zlibt. But for me is every small 
extension a good C exercise
BrianH
26-Jan-2011
[2163]
Then you make sure that your extensions can survive being delayed 
:-/
Kaj
26-Jan-2011
[2164]
How much time and memory do delayed modules take? In any case, it 
will be too much on for example CGI scripts