Testing Ruby VALUES in C-extension.
-
I can't speak for WXwidgets, not familiar with it. Though I seem to recall some issues where they changed the order the window hierarchy - but maybe that was just the Ruby wrapper, I don't know.
But in general you can use whatever C/C++ lib you want. Native dialogs, knock yourself out. I haven't done so myself yet, but I wanted to try out a simple hello world window once.
I have done some code that calls the system folder picking dialogs though. Works very well. -
@unknownuser said:
I can't speak for WXwidgets, not familiar with it. Though I seem to recall some issues where they changed the order the window hierarchy - but maybe that was just the Ruby wrapper, I don't know.
I think it was the Ruby wrapper that was causing problems.
The posts touching the subjects are very old, as mentioned..@unknownuser said:
But in general you can use whatever C/C++ lib you want. Native dialogs, knock yourself out. I haven't done so myself yet, but I wanted to try out a simple hello world window once.
I have done some code that calls the system folder picking dialogs though. Works very well.I thought it was a no go on that! I'll peek around a little then.
Report back if I find something exiting.Thanks
-
I've just read all of this - very helpful and interesting.
Years ago I had a project that had to work with 3 compilers, CE, Visual C++ and C++Builder and I had a single code base.
I ended up learning new optimization procedures which when used right from the start created no extra work. For CE and risc processors you must design data structures that are memory aligned. This not only runs fine on cisc - it is automatically optimized. The key bit here is that if a 4 byte int crosses a memory boundary then cisc does 2 fetches and stitches it together, risc simply crashes.
I created a tList object that works with all 3 compilers. You can treat a tList as an array or a hash or a set. You can pass in objects and perform binary tree searches on any member of the object by simply passing it a function pointer to your own custom compare function. This is useful when you want many sort combinations on a single collection. This is a quicksort implementation.
How the tList works is it is essentially an array of pointers. The array is in contiguous memory. The array grows in a very specific way and is moved if you run out of free contiguous memory. When the tList object is first created you can provide an initial number of elements that you want thus avoiding repeated calls to malloc and avoiding moving memory. When sorting just the list of pointers sort - the collected objects stay where they are.
Here is a compare function that sorts on 2 fields. If first field is a tie then sort on second field
The void pointer is cast as the type of object that you collect in the tList.
fIndex is 1 or -1 which changes the sort from ascending to descendingint __fastcall CompareCabsCabinet( void * Item1, void * Item2 ) { int res; tCab *v1 = ( tCab *) Item1; tCab *v2 = ( tCab *) Item2; res = strcmp( v1->Description.c_str(), v2->Description.c_str() ); if ( res == 0 ) res = v1->CabNumber - v2->CabNumber; return fIndex * res; } //---------------------------------------------------------------------------
When I wrote a GIS rendering engine I used a tList for all the points. I added a quad tree for static map data and an rtree for dynamic gps points.
I ended up with virtually instant renderings with a million points.
-
Came across this article today: http://silverhammermba.github.io/emberb/c/#exceptions
Nice little overview over the Ruby C API.
-
good article - it has already answered some of my questions.
-
It explains the important parts better than the Ruby C API readme:
https://github.com/ruby/ruby/blob/trunk/README.EXT -
I just came accross an issue you guys should know about (if you don't already) : We can't pass more than 15 arguments in a single function from ruby to C++.
-
It looks like I'll have to use the visual studio compiler for c extensions in sketchup.
There is an MS specific config file and no other counterparts for borland etc.ThirdParty\include\ruby\2.0\win32\i386-mswin32_100\ruby\config.h
-
@jiminy-billy-bob said:
I just came accross an issue you guys should know about (if you don't already) : We can't pass more than 15 arguments in a single function from ruby to C++.
You actually hit that limit?
-
@garry k said:
It looks like I'll have to use the visual studio compiler for c extensions in sketchup.
There is an MS specific config file and no other counterparts for borland etc.ThirdParty\include\ruby\2.0\win32\i386-mswin32_100\ruby\config.h
For the examples we provided projects only for Visual Studio on Windows and Xcode on OSX. If you want to compile with another compiler you are free to do so - but we don't provide examples for all compilers.
-
@tt_su said:
@jiminy-billy-bob said:
I just came accross an issue you guys should know about (if you don't already) : We can't pass more than 15 arguments in a single function from ruby to C++.
You actually hit that limit?
Well... I try to limit the back-and-forth between ruby and C++, so I pass all the information in one go, and treat everything in C++.
-
@jiminy-billy-bob said:
@tt_su said:
@jiminy-billy-bob said:
I just came accross an issue you guys should know about (if you don't already) : We can't pass more than 15 arguments in a single function from ruby to C++.
You actually hit that limit?
Well... I try to limit the back-and-forth between ruby and C++, so I pass all the information in one go, and treat everything in C++.
A Hash would be good to pass instead - much easier to manage whenever you change some of the data you pass. No need to worry about changing argument order etc.
-
I have a good start on SUEX_HelloWorld using C++Builder 6
I've added cbuilder folder at the same level as the i386-mswin32_100 folder. Then I added a ruby folder and copied over the config.h files. Then I've edited the config files. I'm happy to say that I didn't have to edit any other 3rd party file.
Then I ran implib.exe -a msvcrt-ruby200.lib msvcrt-ruby200.dll and created Borland's flavor of each lib file.
After that I set up a couple of include file paths and added msvcrt-ruby200.lib to the probject.
Turned off precompiled headers and unchecked use dynamic rtlI now have it compiling - but currently just for the win32 flavor for SU 2014
Now for a bit of testing.Hopefully I'm on the right path. I'm pretty sure I need to export the function as cdecl for this to work.
-
Turns out it's a stdcall which has no mangling.
I can debug the c extension in CBuilder. Very fast.
Now I need to experiment with arguments etc. That will be the acid test for stdcall
If anyone is interested I can post the files and the steps.Once I get a real good handle on this I'll try it out with XE7 which is a compiler that compiles Win32, Win64 and OSX.
I will also test this on my lap top where Borland memory manager (a dll) doesn't exist. It will tell me if I need to include any of these files or not.
Advertisement