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

World: r3wp

[!REBOL3 Extensions] REBOL 3 Extensions discussions

jocko
18-Aug-2010
[1465]
yes
Gregg
18-Aug-2010
[1466]
Good to know. Thank for posting!
Robert
18-Aug-2010
[1467x2]
Yes, that's a good note. Should be used. I forward it to Carl.
Done.
ChristianE
21-Aug-2010
[1469]
http://www.rebol.com/r3/docs/concepts/extensions-making.html#section-17
says it's out of date and I'm really having trouble including words 
as symbols in a result block of an extension command. 

It works fine with an *INIT_BLOCK defined as


 const char *init_block = "REBOL [\nTitle: {Power Management}\nName: 
 power\nType: extension\nExports: [power-status]\n]\n"

     "lib-boot:           does [map-words words] ;-- Is that a good idea?\n"

     "words:             [ac-line battery remains of high low critical 
     charging]\n"
	    "map-words:    command [words [block!]]\n"
	    "power-status: command []\n"
;

if after IMPORT %power.dll I call SYSTEM/MODULES/POWER/LIB-BOOT.


Is there a way to have IMPORT automatically execute the LIB-BOOT 
code with a simple extension not included into the host code with 
host-kit?
Robert
21-Aug-2010
[1470]
Sorry, don't get what you want to do. You can run some init code 
when the extension is loaded.
ChristianE
21-Aug-2010
[1471x2]
I'm trying to return a block containg a word not taken from a commands 
arguments. Say, I want to return a block like [BATTERY CHARGING]: 

That works with

	u32 *word_ids = 0; // used to hold word identifiers
	enum power_words {W_POWER_BATTERY = 1, W_POWER_CHARGING};

	RXIEXT int RX_Call(int cmd, RXIFRM *frm, void *data) {
		/* .... */

		v.int32a = word_ids[W_POWER_BATTERY];
		RXI_SET_VALUE(s, pos++, v, RXT_WORD); 
		v.int32a = word_ids[W_POWER_CHARGING];
		RXI_SET_VALUE(s, pos++, v, RXT_WORD);
	
		/* .... */
   	}


only after importing the DLL I "manually" init the words with a MAP-WORDS 
command. I was thinking that IMPORT eventually triggers LIB-BOOT 
init-code from the INIT_BLOCK. It seems like the init code is not 
executed.
That MAP-WORDS command only does:

	word_ids = RXI_MAP_WORDS(RXA_SERIES(frm, 1));
	return RXR_TRUE;
Robert
21-Aug-2010
[1473]
How does your RX_Init look like?
ChristianE
21-Aug-2010
[1474x2]
RXIEXT const char *RX_Init(int opts, RXILIB *lib) {
    RXI = lib;
    if (lib->version == RXI_VERSION) return init_block;
    return 0;
}
Straight from the samples, since I have about zero knowledge of C 
and only am exploring how extensions work.
Robert
21-Aug-2010
[1476]
Ok, you need to make a call to your lob-boot function out of this 
init function.
ChristianE
22-Aug-2010
[1477]
Ouch! Now that problem above has a really simple solution: Just putting 
the module init code in the CONST CHAR *INIT_BLOCK works great:

	const char *init_block =
	    "REBOL [\n"
	        "Title:   {Power Management}\n"
	        "Name:    power\n"
	        "Type:    extension\n"
	        "Exports: [power-status capture-screen]\n"
	    "]\n"

     "words:          [ac-line battery remains of high low critical charging]\n"
	    "map-words:      command [words [block!]]\n"

     "power-status:   command [{Returns ac-line and battery status information.}]\n"

     "capture-screen: command [{Returns screenshot as an image.}]\n"
	    "map-words words\n";


The "magic" is the last line, where MAP_WORDS WORDS is evaluated 
ofter loading the module, that command inits the dll with the word 
ids used by the extension.
ChristianE
26-Aug-2010
[1478]
I have built a simple R3 extension for ODBC database access. Although 
more work needs to be done in the unicode area and configurable rowset 
max-rows retrieval as well as catching some GC-related bugs, basic 
functionality like selects, inserts, updates and statement parameters 
is there and working for most major types like LOGIC!, INTEGER!, 
DECIMAL!, TIME! and STRING! I have to test with more databases / 
odbc database drivers. 


I have, however, major problems in working with date values. I just 
don't manage to retrieve date values passed to a command or to return 
a proper date value. So, has anybody succeeded in working with date 
values and probably knows how to create, access and calculate them? 
Sadly, I've found no example code related to date values and there 
isn't much documentation too. Any info is greatly appreciated!
Pekr
26-Aug-2010
[1479]
absolutly cool :-)
Chris
26-Aug-2010
[1480]
Do you have some examples of the date values you get back with their 
actual value?
Anton
26-Aug-2010
[1481x2]
I would say it's absolutely necessary to find the definitions of 
the date values. Reverse engineering can work, but may hide subtle 
bugs, and take much longer before you're sure about the correctness 
of the implementation.
Where have you looked so far?
Pekr
26-Aug-2010
[1483]
If you mean that it is difficult or impossible to work with date 
values in extensions, bring the issue to Robert, who can communicate 
it with Carl, to get the answer ASAP imo ....
Anton
26-Aug-2010
[1484x2]
Ah, good question, now I think Christian meant the binary format 
of rebol's date! values, not any database's date format, which should 
be available as a string at least.
I suspect the passing of rebol date values may not have been implemented 
in R3 extensions yet (not that I've tried anything there yet).
ChristianE
26-Aug-2010
[1486x2]
I've looked in DevBase, but haven't asked questions there yet. I've 
scanned all the extensions documentation on DocBase and the header 
files in the host-lib/extension packages. 


I didn't even manage to read a date value in a simple command like 
   TEST-DATE: COMMAND [DATE [DATE!]]      About every member n the 
REBOL value c-union type seemed to only contain zero values.
I have no idea on how date values are stored in C, all that the docs 
say is that date values are 32 bit encoded date and time zone values, 
so I mainly tried with value.int32a but tried other members too. 
I have no idea about how the encoding is done and - as Anton said 
- I really don't want to reverse engineer it.
Anton
26-Aug-2010
[1488]
Hmm.. that doesn't look very promising.
ChristianE
26-Aug-2010
[1489]
Anton, yes, I can get date values from databases if I ask for string 
values, but I'd rather like DATE! results.
Anton
26-Aug-2010
[1490x3]
Yes, it should be faster performance.
But I suppose if you need it badly enough and can't find how to move 
dates then you parse and transform between the string formats.

On the rebol side, should just need a MOLD and a LOAD / TO-DATE...
Surely *someone* will illuminate the situation soon...
Pekr
26-Aug-2010
[1493]
ChristianE - either post on R3 Chat, or post to Robert - he might 
be the most direct channel to Carl, so I think you might get your 
answer faster that way ....
ChristianE
27-Aug-2010
[1494]
Hmm, I think I've to check this again. At least, a simple 

    RXIEXT int RX_Call(int cmd, RXIFRM *frm, void *data) {
        return RXR_VALUE
    }
    
returns a proper date value for

    test-date: command [date [date!]]
    
I'll see if I can find some time to work on this evening.
jocko
27-Aug-2010
[1495]
Using external extensions with a104, I get an error when using these 
series macros :

RL_SERIES_INFO(ser, RXI_SER_TAIL) ,  RL_GET_CHAR(ser, idx) , and 
RL_MAKE_STRING. Did someone noticed this ?
Graham
27-Aug-2010
[1496]
ChristianE, can we see your extension .. even if it is a WIP?
ChristianE
28-Aug-2010
[1497x2]
There are things that have to be cleaned up a bit first, Graham, 
but I hope I can publish it very soon (counting days, not weeks).
It really should only depend on the time I can piut aside to work 
on the driver.
ChristianE
27-Oct-2010
[1499]
Hmm, I somehow don't manage to compile my odbc extension with a109, 
on import I get the following error

>> import %../lib/odbc.dll
** Script error: make-scheme has no value
** Where: do -apply- make catch case case -apply- apply import
** Near: do body obj


I do understand that it's related to MAKE-SCHEME moving into SYS 
context,. Do I have to import SYS into my extension module's context 
first and, if so, how? NEEDS: [SYS] doesn't work, my extension is 
already declared with TYPE: MODULE OPTIONS: [EXTENSION DELAY], trying 
to access MAKE-SCHEME directly thru SYS/MAKE-SCHEME makes the intepreter 
crash.
Pekr
27-Oct-2010
[1500]
Maybe your extension is loaded faster than mezz-code?
ChristianE
27-Oct-2010
[1501]
That's why I'm trying to DELAY. Delaying doesn't seem to work for 
embedded extensions according to curecode, but here it's a simple 
dll import ...
Pekr
27-Oct-2010
[1502x2]
Yes, I saw the ticket ... maybe it gets fixed in a110, but not sure 
it is a cause. BrianH discussed it a bit today ...
See REBOL3 channel ... or wait for BrianH ....
Maxim
27-Oct-2010
[1504]
is make-scheme in the lib context?  cause that worked out for me 
using other mezzanines...
ChristianE
27-Oct-2010
[1505]
It never occured to me to try with LIB instead of SYS, it's in LIB, 
too, of course! But calling LIB/MAKE-SCHEME crashes, too, so I guess 
the problem is somewhere else.
BrianH
28-Oct-2010
[1506x2]
Both bugs 1723 and 1729 have been fixed, for alpha 110. The next 
release should fix your problems, Christian.
We have been discussing adding a header option to tell the system 
to put off loading an embedded extension until after the mezzanines 
have loaded (or have that be the default, and have an option to load 
before the mezzanines). I haven't looked over the startup code yet 
to see how to do this, but it shouldn't be too hard. I'm waiting 
for Carl to decide on the option (he seems to be the namer of that 
kind of thing right now, I'm just an implementor).
ChristianE
29-Oct-2010
[1508]
Thanks, Brian, for the status update, that's good news in more than 
one way. I con stop trying and just expect it to work next time. 
.'J
Oldes
5-Nov-2010
[1509]
Where to start when I would like to learn how to write own extension? 
This page is out -of-date:/
http://www.rebol.com/r3/docs/concepts/extensions-examples.html
Andreas
5-Nov-2010
[1510]
Here's a minimal example of an extension:
https://gist.github.com/0677266b8511d83ce76a
GrahamC
5-Nov-2010
[1511]
Also christian did an ODBC extension
Oldes
5-Nov-2010
[1512]
fine... I can compile the minimal example, have problems with the 
samples above. The ODBC source is where?
Andreas
5-Nov-2010
[1513]
don't think the odbc sources are published at the moment
GrahamC
5-Nov-2010
[1514]
see the announce group