Wrap gem under own namespace
-
I don't know if its legal, but how do I set win32-api under my own module namespace (Anton::Win32::API). I have ruby 1.9.3, installed win32-api gem, modified the
ext/win32/api.c
to my own namespace, and don't know how to build outapi.so
files. How do I do it? -
@anton_s said:
I don't know if its legal, ...
You need to read the license. It's Artistic v2.0, I believe.
ThomThom and I, discussed this at length in another topic. He finally did do it, I believe for his TTLib2, perhaps?
Check the "Code Snippets" topic, last page, for info on compiling C extensions for Ruby.
-
This is the topic where we discussed the license issues.
http://forums.sketchucation.com/viewtopic.php?f=180&t=34124&p=301107 -
Aye, I made my own private copy of the Win32 API lib. There is a readme in my distribution. I did however use Ruby 1.8 to build it - since that's what SketchUp uses. Don't think you'll get it working with 1.9.
I uploaded a C Extension how-to to BitBucket: https://bitbucket.org/thomthom/sketchup-ruby-c-extension
-
Thanks Dan, now I see that I wasn't the only one confused with these gems compiling thing.
Thomthom, thanks, the example is excelent! And by the way, that idea of Win32::API, under own namespace came from that same TT_Lib2. Don't worry though, I'm not dismantling your TT_LIb to pieces.
To make sure, if I have Anton::Win32::API and Wi32::API, then the Anton::Win32::API::Callbacks.new limit would not count callbacks from standard Win32::API, right? So, If I create to callbaks on Win32::API and 10 on Anton::Win32::API, then it will work?
-
@unknownuser said:
- Navigate to the project folder
- Execute "ruby extconf.rb"
- Execute "make"
Need more info on these parts. I opened the Visual Studia 2010 Command Prompt via start menu, but then don't know the EXACT commands to write into the prompt; How do I navigate, and how do I execute, pls. I'm beginner!
-
@anton_s said:
So, If I create to callbaks on Win32::API and 10 on Anton::Win32::API, then it will work?
Would it not be better to adjust the limit of callbacks in your customized
Anton::Win32::API
instead of spreading across multiple API modules?@anton_s said:
How do I navigate, and how do I execute, pls. I'm beginner!
Ah, you've never used DOS, have you?
To navigate you use the
cd
command (change directory). To execute you just type the name of the executable - the bat file.So, something like this:
cd "C:\path\to\my\project"
(Return)
ruby extconf.rb
(Return)
make
-
@thomthom said:
Would it not be better to adjust the limit of callbacks in your customized Anton::Win32::API instead of spreading across multiple API modules?
Sure, I'll try to increase callbacks limit in api.c.
Got a little proplem here compiling thomthoms c-extention example:
Some probable cause:- Installed ruby 1.8.6 patchlevel 398.
- Did NOT find these lines in config.h.
#if _MSC_VER == 1200
#error MSC version unmatch
#endif - Have MSFT Visual Studio 10.0
-
Did you try with the one-click installer in the Readme?
http://rubyforge.org/frs/download.php/47082/ruby186-27_rc2.exeI'm not familiar with that error message. And it's odd that you did not find those lines.
-
@thomthom said:
Did you try with the one-click installer in the Readme?http://rubyforge.org/frs/download.php/4 ... 27_rc2.exe
Installed it, found and comment out the first 3 lines.
Now, after that I tried it again, everything worked!
Thankyou, Thankyou, thankyou!!! -
-
@thomthom said:
I uploaded a C Extension how-to to BitBucket:
Added your example link to the [ Code Snippets ] post:
[Info] C/C++ Ruby extensions & SketchUp plugins -
One thing to NOTE, when creating ur own extconf.rb
Lets, say you have an extension api.c and decide to create ur own extconf.rb, and so, you do:require 'mkmf' PLATFORM_IS_OSX = (Object;;RUBY_PLATFORM =~ /darwin/i) ? true ; false PLATFORM_IS_WINDOWS = !PLATFORM_IS_OSX if PLATFORM_IS_OSX CONFIG['LDSHARED'] = 'cc -dynamic -bundle -undefined suppress -flat_namespace' end create_makefile( 'api.c' )
The code above looks pretty clean but there is one thing WRONG! In the sting of last line never add the file suffix! That way init_api inside the api.c won't be recognized! So, last line should look like
create_makefile( 'api' )
.Here is a batch file Extract and Put it into ur project's folder -that will write compiling commands for u. Jst Place it into ur project's folder, change the vcvars32.bat path to your current vcvars32.bat path, and run it to compile.
-
The string you feed create_makefile should relate to the init function in your C extension.
As you see from the Hello World example, extconf contains this:
create_makefile( 'SX_HelloWorld' )
And in the C source you have the init function:
void Init_SX_HelloWorld( void )
Note how "Init_" is prepended of the name you feed makefile - and it's case sensitive.
@anton_s said:
change the vcvars32.bat path to your current vcvars32.bat path, and run it to compile.
I have found after making the tutorial that it is easier to just launch the command prompt shortcut that ships with Visual Studio. It's there in it's folder in the start menu. The environment is set up automatically.
Advertisement