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

World: r3wp

[Core] Discuss core issues

Cyphre
14-Jan-2005
[231x2]
ups: the 'GradientPen' should be  'PassDoubles'
but I hope you got it
shadwolf
14-Jan-2005
[233]
yes I understand i think
Cyphre
14-Jan-2005
[234]
...then you can either work on the array directly using C code or 
copy it into new array etc.
shadwolf
14-Jan-2005
[235x2]
but how to handle in rebol a C function of this kind void  my_func 
( int my_arg[25] ) { code... }
without adapting the C function argument type
Cyphre
14-Jan-2005
[237]
let me check...
shadwolf
14-Jan-2005
[238x6]
If I'm the conseptor of the external C lib i can do ma best for preprepare 
the data to be use to be teh easier to deal for rebol but I want 
to use a yet existant lib I will have to work pretty hard to be allowed 
to inteerface rebol code and this library
in PassDoule on C side you have a char * double argument that's not 
the same as handling a pre defined PassDoubles( unsigne double [4])
in PassDoule on C side you have a char * double argument that's not 
the same as handling a pre defined PassDoubles( unsigne double doubles 
[4])
I'm agree with you char * can feet every thing but this will need 
you on C side to make the spliting of the char content user << and 
&& maks to be able to retrieve your initial data passthue by rebol 
;)
it's impossible on C side  code to do without a spliting statement 
the direct exploitation of the data you pass to the lib
using rebol
Cyphre
14-Jan-2005
[244x9]
here is teh example of your case:
test: make routine! [
	arg [binary!]
	return: [int]
] my-lib "SumIt"

probe test #{0100000002000000030000000400000005000000}
==15
the C side:
extern "C"
MYDLL_API int SumIt(int my_arg[5])
{
	int result = 0;
	for(int i = 0;i<5;i++){
		result+=my_arg[i];
	}
   return result;
}
you can build the binary! array using this function
int-to-bin-array: func [blk /local result][
	result: make binary! []
	foreach int blk [
		insert tail result third make struct! [d [int]] reduce [int]
	]
	result
]
>> int-to-bin-array [1 2 3 4 5]
== #{0100000002000000030000000400000005000000}
>>
hope this helps you
shadwolf
14-Jan-2005
[253]
yes it helps me a lot
Cyphre
14-Jan-2005
[254]
so you can see everything is possible to do (except the callbacks 
;))
shadwolf
14-Jan-2005
[255]
to figure out in simle example this looks easy .... (hum not a lot 
in fact beacaus all the science is done by int-to-array reebol function 
witch is not pretty accessible to common or mortals )
Cyphre
14-Jan-2005
[256x3]
maybe one improvemet would be great for us:
have some faster way how to construct those binary! data from Rebol
I hope this could solve the REBIN feature or else we need some another 
native functionality for that
Gabriele
14-Jan-2005
[259x2]
you could makje it faster by reusing the same struct instead of creating 
a new one on each iteration
that would avoid a reduce too
shadwolf
14-Jan-2005
[261x3]
and if y have twenty array sized and typed  different kind for my 
external lib I will need to wirte and handle as many function to 
play with binary content
Cyphre you comming to my main point ;) giving to carl a premaid function 
that allow us to deal easyly with array (int, float, char what ever 
type) but for struct based array that's a challenge too and an horrible 
task to do
example: struct my-struct { int a[10], char *name, other-struct ptr-ostruct[20];}
Cyphre
14-Jan-2005
[264]
yes Gabriele this could help too....I wrote this function as a quick 
one so it can be optimized for sure
shadwolf
14-Jan-2005
[265]
in the current way to handle you need to be very sharp to can interact 
with it from rebol and that why Cyphre you have all my admiration 
for your quick made AGG external exploitation script ...
Cyphre
14-Jan-2005
[266]
shadwolf: I think you only need to write one global function which 
will convert you rebol block of chosen datatype into binary! form...this 
way you can pass any content to C side...
shadwolf
14-Jan-2005
[267]
that's the REBOLTo C way but how about the C to rebol way (that I 
provide  using the MD2 file example)
Cyphre
14-Jan-2005
[268x2]
As I said it is not so hard when yog get more experience...I spent 
hours when started to use DLLs from rebol. I had also bad luck I 
wanted to use very badly designed DLL in my first project so this 
was even bigger pain for me ;)
C to Rebol is very simmilar...have to leave now...bye for now
shadwolf
14-Jan-2005
[270x8]
bye and thank you cyphre for your contribution to thi discution.
it was a very good source of information
and kwoledge
knowledge sorry :)
well now i know better how to handle REBOL -> C and C-> REBOL the 
idéal thing could be a convert-reb-to-c multi type, multi size native! 
function in Command and in REbol/view Pro (I think it will be added 
to core any way than accessible if you have the licence.key file)
maybe idela convertion function could be c_convert/int ma_var  with 
ma_var : [ 1 4 5 10 ] if c_convert  workon a REBOL array then no 
need to specify manually the length we retrieve the info using lenght? 
type could be treat as rafinement and a switch could branch into 
c_convert function the adapted tranlation algorithm
improving this c_convert for int64 for example could be a very easy 
task ;)
to avoid to rewrite X time the same lind of code we just in the switch 
premaid a countainer adapter to the data we want to handle.
Terry
15-Jan-2005
[278x2]
Has anything changed with core regarding loading?  I'm trying to 
load a function using a URL, and it comes back as a block?
Has load become load/all ?
Sunanda
15-Jan-2005
[280]
For anything other than a simple value, you've always got a block 
back from load (as far as I remember)
>> load "1"
== 1               --- a value
>> load "1 2"
== [1 2]               --- a block
>> load mold :to-idate
== [func .....         -- a block


>>