--- Log opened Sat Feb 25 00:00:14 2006 00:09 -!- nazgul` [n=d47f5f7d@lilith.ii.uni.wroc.pl] has quit ["CGI:IRC (EOF)"] 03:35 -!- m3ga [n=erikd@adsl-64-136.swiftdsl.com.au] has joined #nemerle 06:02 -!- m3ga [n=erikd@adsl-64-136.swiftdsl.com.au] has quit ["disappearing into the sunset"] 06:19 < user317> how would i write .net bindings to a C library? 09:28 < user317> how do i convert a list into an array? 09:58 -!- nazgul` [n=d47f5f7d@lilith.ii.uni.wroc.pl] has joined #nemerle 09:58 -!- mode/#nemerle [+o nazgul`] by ChanServ 09:58 -!- nazgul` [n=d47f5f7d@lilith.ii.uni.wroc.pl] has quit [Client Quit] 09:58 -!- nazgul` [n=d47f5f7d@lilith.ii.uni.wroc.pl] has joined #nemerle 09:58 -!- mode/#nemerle [+o nazgul`] by ChanServ 09:58 <@nazgul`> [1,2,3].ToArray() 10:00 <@nazgul`> http://nemerle.org/PInvoke_(tutorial) 10:01 <@nazgul`> you can generally search for pinvoke on .NET and it should give you good results 10:10 < user317> it seems to work, except i have a function that returns an array of floats 10:10 < user317> and the value in mono is screwed up 10:14 <@nazgul`> hm, array[float] should work (I was using array[byte] in my app) 10:15 < user317> FANN_EXTERNAL fann_type* FANN_API fann_run(struct fann *ann, fann_type *input); //fann_type is float 10:15 < user317> how would .net know the size of the array? 10:16 <@nazgul`> ok, so you should use fann_type : ref float 10:17 <@nazgul`> as for structures, I don't have much experience with them, see http://www.mono-project.com/Interop_with_Native_Libraries 10:17 < user317> fann_run(fann : System.IntPtr, input : array[float]) : ref float; ? 10:17 < user317> the intptr works fine 10:17 <@nazgul`> probably you will need to create a "copy" of struct definition in .NET 10:17 < user317> because i dont really care about its internals 10:18 <@nazgul`> fann_run(fann : System.IntPtr, input : ref float) : IntPtr I would try this at first 10:18 <@nazgul`> IntPtr should be ok for any pointer type 10:18 < user317> how do I change it to a float array? 10:19 <@nazgul`> ah, if it is treated as buffer in C, then array[float] shoud be also ok :) 10:19 < user317> hehe 10:19 < user317> yea, it doesn't seem like it is 10:19 < user317> i get some random length array back with junk in it 10:20 <@nazgul`> hm, you mean the retrun value of "input" parameter? 10:20 < user317> i mean what i get back as the return of fann_run 10:20 < user317> input is fine 10:20 <@nazgul`> also, I wonder what FANN_EXTERNAL and FANN_API is, maybe some macros? 10:21 < user317> i think they are just macros for static 10:21 < user317> a similar function that returns just a float from this library works fine 10:21 <@nazgul`> hm, I guess this is the problem, .NET can't know what should be the length of array 10:21 < user317> yea, thats what i think too 10:21 <@nazgul`> there probably is some way of specifying this... 10:21 < user317> but then at least the first part of the array should contain something that makes sense 10:22 <@nazgul`> but I don't know what :/ 10:22 < user317> which it doesnt, its just junk 10:23 <@nazgul`> maybe you need IntPtr and then convert it manually 10:23 < user317> how would I do that? 10:23 <@nazgul`> specifying the length and using some Marshal magic 10:24 <@nazgul`> // convert native pointer to System::IntPtr with C-Style cast 10:25 <@nazgul`> Marshal::Copy((IntPtr)buf,byteArray, 0, len); 10:25 <@nazgul`> just found this :) 10:27 < user317> hmm 10:27 < user317> so i would pass hte return value int othat? 10:28 < user317> how do i get floats out of it 10:29 <@nazgul`> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeinteropservicesmarshalclasscopytopic.asp 10:29 <@nazgul`> but now you need to explicitly know the amount of elements you have there 10:30 < user317> i know that part 10:32 < user317> cool, i think this might work 10:32 <@nazgul`> so def result = fann_run (...); def output = array (amount_of_returned); Marshal.Copy (result, output, 0, amount_of_returned); output [0] == 0.0 :) 10:35 < user317> you are a genious 10:35 < user317> it worked perfectly 10:35 < user317> thanks a lot for your help 10:39 <@nazgul`> np :D 19:27 < user317> i need something that I can push and pop from both tail and head, is arraylist fast? 19:31 <@nazgul`> yes, I think manipulating end of arraylist is fast, the head should be also fast, though I'm not sure 19:32 <@nazgul`> this is implemented by a reallocated array, and push, pop operations are simply assign and move the current index (except the reallocation step) 19:34 < user317> ok, cool 23:44 -!- nazgul` [n=d47f5f7d@lilith.ii.uni.wroc.pl] has quit ["CGI:IRC (EOF)"] --- Log closed Sun Feb 26 00:00:16 2006