sketchucation logo sketchucation
    • Login
    1. Home
    2. chyn2000
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    C
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 9
    • Groups 1

    chyn2000

    @chyn2000

    10
    Reputation
    1
    Profile views
    9
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    chyn2000 Unfollow Follow
    registered-users

    Latest posts made by chyn2000

    • RE: [Tutorial] SketchUp Ruby C Extension

      So, I have to apologize for wasting your time...

      First thing I need to do (yet again) is RTFM.

      The answer to threading is incredibly simple:
      _beginthread( silly, 0, (void*)12 );

      becomes

      rb_thread_create( silly, (void*)12);

      found it on:
      http://ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html

      So, if you will excuse me, I need to go beat myself half to death...

      posted in Developers' Forum
      C
      chyn2000
    • RE: [Tutorial] SketchUp Ruby C Extension

      Hey guys,

      So, I got the ruby extension process to work, but I seem to be running into one little catch... multithreading.

      FYI: I'm using Pelle's C with the options TBD suggested in his SUExt example. I'm on a Win 7 (64 bit) system (though hopefully that won't matter).

      I'm trying to use _beginthread, but using TBD's settings, it seems I have an unresolved symbol '_beginthread'.

      Just to let you know, I am kind of new to multithreading and DLLs. I have created threaded applications, but never a threaded dll.

      Taking an example program that I have gotten to compile and run as a standalone app (pelle's C option multithreaded (lib)), I add the libs, includes and functions required to make it a ruby extension and it suddenly can't resolve _beginthread.

      A couple of modifications to TBD's project settings and I get it to compile and even be recognized by the irb. However, it seems the second the thread tries to run, the whole irb closes.

      The settings I modified to "get it to work" was:
      Runtime library from multithread (dll) to multithread (lib)
      and turn off "Omit default library in object files"

      Any ideas?

      Thanks,
      Reg

      
      // general Windows
      #pragma comment(lib, "kernel32.lib")
      #pragma comment(lib, "gdi32.lib")
      #pragma comment(lib, "user32.lib")
      #pragma comment(lib, "shell32.lib")
      #pragma comment(lib, "advapi32.lib")
      
      // Ruby
      #define HAVE_ISINF 1  // isinf macro redefinition workaround
      #pragma comment(lib, "msvcrt-ruby18.lib");
      
      // DLL
      #pragma comment(lib, "crt.lib");
      
      #include <stdio.h>
      #include <windows.h>
      #include <process.h>         // needed for _beginthread()
       
      // Ruby headers 
      #include "ruby.h"
      
      void  silly( void * );       // function prototype
      
      // De fining a space for information and references about the module to be stored internally
      VALUE KMRH = Qnil;
      
      int j = -1;
      
      // our function
      VALUE method_display_model(VALUE self, VALUE input)
      {
          // Our program's first thread starts in the main function.
          printf( "Now in the main function.\n" );
      
          // Let's now create our second thread and ask it to start
          // in the silly() function.
      //    _beginthread( silly, 0, (void*)12 );  //Commented out to see if the program would stay alive and it does
      
          // From here on there are two separate threads executing
          // our one program.
      
          // This main thread can call the silly() function if it wants to.
      	while(j != 0)
      	{
          	silly( (void*)j );
      		j--;
      	}
      
          Sleep( 10000 );
      
      	int i = NUM2INT(input);
      	return INT2NUM(i + 1);
      }
      
      // The initialization method for this module
      void Init_KMRH(void)
      {
      	KMRH = rb_define_class("KMRH", rb_cObject);
      	rb_define_method(KMRH, "display", method_display_model, 1);
      }
      
      
      void  silly( void *arg )
      {
      	int k = 10;
      	while(k-- != 0)
      	{
      //    	printf( "The silly() function was passed %d\n", (INT_PTR)arg );
          	printf( "The silly() function was passed %d\n", k );
      	}
      }
      
      
      posted in Developers' Forum
      C
      chyn2000
    • RE: [Tutorial] SketchUp Ruby C Extension

      @jim said:

      Ok, I just built TBD's suext example using Visual Studio Express 2010.

      In order to get the extension to require properly, I had to use:

      require "SUExt" <-- note case

      require "suext" failed.

      Yep Jim. That was exactly it!

      Thanks everyone. Let me know if there is anything I can do to help.

      Actually, it occurs to me that we may want to start making a small library of math and geometry ruby extensions very targeted towards SU. Thoughts?

      -Chyn

      posted in Developers' Forum
      C
      chyn2000
    • RE: [Tutorial] SketchUp Ruby C Extension

      I built in Pelles C.

      So, the path isn't hard coded in the program. I can place a copy of the suext.so on my d:\ and it changes the error out put to match:

      irb(main):002:0> require 'D:\suext'
      LoadError: 127: The specified procedure could not be found. - Init_D:\suext
      D:\suext.so
      from D:\suext.so
      from d:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
      from (irb):2
      from :0

      Is there a specific directory I should have the file at?

      posted in Developers' Forum
      C
      chyn2000
    • RE: [Tutorial] SketchUp Ruby C Extension

      Ah. Gotchya now.

      Nirg. Same result...

      Anything else? Maybe is one of you guys have successfully built the example you could post it for download. That would make sure I've got my environment set up correctly.

      -Chyn

      posted in Developers' Forum
      C
      chyn2000
    • RE: [Tutorial] SketchUp Ruby C Extension

      Both. The '/'s and ''s that are in the post were copied and pasted. I didn't change any of them. Let me know if you want the original output. I just shortened the paths for readability.

      -Chyn

      posted in Developers' Forum
      C
      chyn2000
    • RE: [Tutorial] SketchUp Ruby C Extension

      Ok. That certainly changed things a little.

      I type:
      irb(main):002:0> require 'path_to_project\suext'

      and get back:
      LoadError: 127: The specified procedure could not be found. - Init_path_to_project\suext
      path_to_project\suext.so
      from path_to_project\suext.so
      from path_to_ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
      from (irb):2
      from :0

      posted in Developers' Forum
      C
      chyn2000
    • RE: [Tutorial] SketchUp Ruby C Extension

      Hi Guys.

      First, I want to say that this project you have started is awesome. I had just decided I needed a ruby extension to get a speed boost for a plug-in project. I found a lot of tutorials on making extensions, but most were for either linux or for MS Visual Studio 6 on Windows. I'm not using either environment. I am on Windows 7 (64bit).

      Sooooo, I have followed TBD's example program the best I can.

      • I have downloaded the SUExt files.
      • I have downloaded the Ruby Installer and Source per the SUExt readme file and installed Ruby.
      • I have installed Pelles C.

      I tried to open suext.ppj file and Pelles C kept throwing an error about "suext.obj is wrongly located in -path_to_project-". So I tried suext6.ppj and it seemed to be fine. It even seemed to build once I pointed Pelles C to where my Ruby installation was at.

      From here I'm a little lost. Am I done? I brought up the irb and typed in: require 'path_to_project/suext.so'
      The results were as follows:

      LoadError: 127: The specified procedure could not be found. - Init_path_to_project\suext
      path_to_project\suext.so
      from path_to_project\suext.so
      from path_to_ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
      from (irb):1
      from :0

      What am I missing?

      Thanks
      -Chyn

      posted in Developers' Forum
      C
      chyn2000
    • RE: [plugin] Ruby Code Editor - UPDATED to v3.0 3/4/2013

      I wanted to say that this is an AWESOME plugin!

      Some functionality suggestions that (IMHO) would make your interface even more invaluable:

      Add break point capability:
      At break points, the pluging could add a popup before execution (behind the scenes, not in the viewable text field). The user would just press 'OK' to continue on.

      Add Escape or Kill button:
      The Escape would be an emergency breakout to stop execution if the user created an inf loop. Maybe force inserted into any loop conditions (again, behind the sceens).

      Add Variable Watcher window:
      This might be pretty hard, but then maybe not, but also a variable watcher window sharing the space with the results/error window. I could see this working by having pairs of fields. Type the variable name in one field and the program updates that fields pair with the in scope value.

      Reduce Web Console's realestate during execution:
      Have the option to hide, minimize or make the Web Console transparent during code execution.

      Just some suggestions, though I'm sure you are busy doing things that actually make you money so you can pay for internet access (oh, and I guess eat and have a place to sleep too... ๐Ÿ˜‰ )

      Cheers!
      Reg

      posted in Plugins
      C
      chyn2000