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

World: r3wp

[!REBOL3 Extensions] REBOL 3 Extensions discussions

Oldes
14-Dec-2010
[1877]
Or to return struct! from the C side?
Andreas
14-Dec-2010
[1878x2]
Passing around heap-allocated structs should work right now.
Ah, struct!, sorry, I misread.
Oldes
14-Dec-2010
[1880]
..because I somehow miss what is struct useful for in R3 without 
routines.
Andreas
14-Dec-2010
[1881]
I think struct! is just a datatype for future use. Not used at the 
moment.
Cyphre
14-Dec-2010
[1882]
yes, struct! is 'reserved' for now. It may be even removed later.
Oldes
14-Dec-2010
[1883]
What if I expect float on the C side, but still want to allow to 
use integer from REBOL (using number!).. what's the best way to do 
it?
Kaj
14-Dec-2010
[1884]
Maybe a wrapper interface function in the init block?
Oldes
14-Dec-2010
[1885]
That's possible, but I was more thinking how to do it on the C side 
and not end with wrapper for each extension command.
Kaj
14-Dec-2010
[1886]
Yeah, more elegant, but more work
Andreas
14-Dec-2010
[1887]
How about defining the command with `command [arg [integer! decimal!]]` 
and then detecting in C when you where passed an int and converting 
it to a float?
Oldes
14-Dec-2010
[1888x2]
Yes.. but how? Remember, I'm still C newbie:)
and the command can be just  [number!]
Andreas
14-Dec-2010
[1890]
Then you'll have to handle percent! as well :)
Oldes
14-Dec-2010
[1891x2]
oh.. right.. but that could be fine in some cases.. like volume.
also decimal! and percent! are both as RXA_DEC64
Kaj
14-Dec-2010
[1893]
In the extension examples in the docs are examples of detecting multiple 
types
Oldes
14-Dec-2010
[1894]
I guess I can use RXA_TYPE(f,n) to get the value type, but hot to 
convert the integer to decimal?
Kaj
14-Dec-2010
[1895]
I don't think it's very easy to get at the REBOL conversion functions
Andreas
14-Dec-2010
[1896]
float value = (float)RXA_DEC64(frm, 1);
if (RXA_TYPE(frm, 1) == RXT_INTEGER)
  value = (float)RXA_INT64(frm, 1);
}
Oldes
14-Dec-2010
[1897]
thanks, that looks good
Andreas
14-Dec-2010
[1898x3]
In fact, this is not really necessary, as both integer and decimal 
values are stored in a union anyway. But if you want to rely on as 
little implementation internals as possible, that's probably the 
way to go.
And your compile will quite possibly optimise the redundancy away 
for you behind your back :)
compiler*
Oldes
14-Dec-2010
[1901x2]
I was trying to do just  (float)RXA_DEC64(frm, 1) with integer value 
and it was not working.
Do you think it's better to export all commands in flat structure 
like:
	export System_GetNumDrivers: command[]
	export System_GetDriverInfo: command[id [integer!]]
	...
Or rather close them to contexts like:
	export system: context [
		GetNumDrivers: command[]
		GetDriverInfo: command[id [integer!]]
		...
	]
Kaj
14-Dec-2010
[1903]
Depends on the purpose of the module
BrianH
14-Dec-2010
[1904]
It depends on the situation, and how the commands are supposed to 
be used. In that case above, don't export 'system.
Kaj
14-Dec-2010
[1905]
I think that was just an example :-)
BrianH
14-Dec-2010
[1906]
Direct word access is faster than path access, but some words are 
logically grouped (like enums).
Oldes
14-Dec-2010
[1907]
You mean the name?
BrianH
14-Dec-2010
[1908]
Yes :)
Oldes
14-Dec-2010
[1909]
At this moment I have a flat structure, but problem is, that there 
is so much exported commands that I tender to froup them... I know 
it's slower, but how many times one need to know driver name like 
in the commands used in the example above?
BrianH
14-Dec-2010
[1910x2]
For instance, in the AGG wrapper the commands that are used to implement 
the Draw dialect are exported in their own context rathar than globally, 
because they aren't meant to be called directly as functions. Other 
APIs may need to do the same thing for similar reasons.
In a lot of cases you want to make commands at the marshaling boundary, 
and make REBOL wrapper code that you export. REBOL code can encapsuate 
a lot of functionality, whether you are doing so in an object type, 
a scheme or a dialect.
Oldes
14-Dec-2010
[1912]
Back to the name..  what if I export System extension context into 
main context, where is already System defined? Now it looks it just 
silently do not overwrites the existing one.. shouldn't it throw 
an error?
BrianH
14-Dec-2010
[1913x2]
If you are just exporting the native API then make the extension's 
module private rather than public, and just import the extension 
into the module that provides a simple REBOL-like public API for 
others to use.
The current build doesn't have most of the security protections implemented. 
We want to fix the *many* protection bugs first.
Oldes
14-Dec-2010
[1915]
So do you want me to add CC ticket?
BrianH
14-Dec-2010
[1916x2]
There already is one.
For that matter there is a message warning about this problem at 
startup of 109 and 110.
Oldes
14-Dec-2010
[1918]
ok.. fine... so do you think I can safely use 'system' like exported 
names and believe, that if someone want's to use the extension, he 
will imported like:
	fmod: import %ext-fmod.dll
to avoid conflicts and not:
	import %ext-fmod.dll
?
BrianH
14-Dec-2010
[1919x4]
fmod: import/no-user/no-lib %ext-fmod.dll
That combination was Carl's suggested replacement for the /only option. 
More fine-grained control.
Keep in mind that exported words that are predefined are not overriden 
by the export process. Your export of the word 'system will not change 
the setting of the word 'system in the user context. In order to 
change that you need to assign it manually. Word precedence is first-come-first-serve, 
so even if the 'system word in the user or lib contexts is protected, 
there will still be no error triggered because the export was going 
to just silently not work anyways.
The protection of the system words (that isn't working at the moment) 
only affects explicit assignment.
Oldes
14-Dec-2010
[1923]
Yes, but we should be warned when you are trying to import word into 
context where the word already exists.. it looks that now it just 
silently does nothing, which could lead to suprices later.
BrianH
14-Dec-2010
[1924]
It's only a surprise because the module system is not particularly 
well documented at the moment. The override policy is very consistent.
Oldes
14-Dec-2010
[1925]
Documentation will not help in cases where you have unexpected name 
conflict.
BrianH
14-Dec-2010
[1926]
There will always be a name conflict somewhere. That is why we have 
an override policy. Of course anything unexpected will be surprising, 
but in this case the unexpected thing is that there was a name conflict 
in the first place, not the behavior of the system in reaction to 
the conflict. That is of course assuming that the developer has read 
the docs, and that we have written them, neither of which I am really 
assuming at this point.