Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ruby c++

While looking for information on the subject, I looked into the ONLamp article Extending Ruby with C by Garrett Rooney, the Extending Ruby chapter in the Pickaxe, README.EXT (located at /usr/share/doc/ruby1.8-dev/README.EXT.gz on my Ubuntu system) and got some help from Kjetil.
The resulting file can be found here: wtmplist.c.
Disclaimer: I’m not resposible if you should destroy something with your newfound skills, nor am I responsible if you should suddenly get the urge to leave your wife/loved ones in favor of Ruby.
Table of Contents:
What to Extend?
How Do I Want the Interface to Be?
Get to it! #include <ruby.h>
Groundwork.
Making it Compile.
Collect the Data th Make Available.
Adding More Functionality.
Test Your New Library.
What to Extend?
Obviously you start by figuring out what you want to extend Ruby with. Some library missing, or better implemented in C? Some library you wrote yourself and want to be able to use from Ruby scripts?
I have a project coming up where I’ll have to look into /var/log/wtmp to get login entries, and didn’t find any classes/modules that made this possible in Ruby. There are documented (through Man) C functions to access the structures in the file, so I started to look at the introductions to extending Ruby (regrettably I somehow forgot about the Pickaxe at this point, but Kjetil reminded me after I had been cursing for a while).
Moving on to the next step …
How Do I Want the Interface to Be?
The point here is to think how you would like the information and methods represented in Ruby. In my case, I want to read in all entries in wtmp, and have them available in a list of some sort. In Ruby that means using the array. So an Array of entries doesn’t sound too bad. To make things cleaner, I’ll also put it in a module. This maps to this Ruby code (roughly):
module Wtmp
class List < Array
def initialize
# open wtmp
# wtmp.each_struct


Ïà¹ØÎĵµ£º

Ruby 101£º·½·¨¶ÔÏó


Ruby 101£º·½·¨¶ÔÏó
Written by Allen Lee
´Ó·½·¨µ÷ÓÃ˵Æð
      ÔÚÉÏһƪÎÄÕÂÀÎÒÃÇ¿´µ½µ÷ÓöÔÏóµÄ·½·¨ÊµÖÊÉÏÊÇÏò¶ÔÏó·¢ËÍÏûÏ¢£¬ÏÂÃ棬ÎÒÃÇÔÙÀ´¿´Ò»¸öÓÐȤµÄÓ¦Óá£ÔÚRubyÀ×Öµä¿ÉÒÔͨ¹ý {key => value} À´´´½¨£¬Èç¹ûÄãʹÓõİ汾ÊÇ1.9»òÒÔÉÏ£¬µ±keyµÄÀàÐÍÊÇSymbolʱ£¬´´½¨×ÖµäµÄÓ ......

JavaÓëC++µÄÇø±ð

JavaÓëC++×î´óµÄ²»Í¬µÄ£¬JavaÍêÈ«ÊÇÃæÏò¶ÔÏóµÄ£¬ÊÇÓÉÀ๹³ÉµÄ£¬¶øC++ÊÇÓɶÔÏóÓë¹ý³Ì×é³É¡£
1¡¢Â·¾¶£º
Java°üÀ¨Ò»¸ö°üpackage,C++ûÓУ»
2¡¢ÒýÈëÀà
java import.*.*; C++  include ""';
3¡¢Ô¤¶¨Ò壬
C++°üÀ¨Ô¤¶¨Ò壬Java²»°üÀ¨
4¡¢½á¹¹
C++°üÀ¨½á¹¹£¬JavaÖ»°üÀ¨À࣬½á¹¹Ìå¿ÉÒÔת»¯ÎªÀà¡£
5¡¢ÀàÃûÓëÎļþÃû
Jav ......

LinusΪʲô²»ÓÃC++дLinuxÄںˣ¿

ÔÚ×î½üµÄÒ»¸ö¹ØÓÚLKMLµÄÌÖÂÛÖУ¬Linus¸ø³öÁËΪʲô²»ÓÃC++À´Ð´LinuxÄں˵ÄÀíÓÉ£º
"In fact, in Linux we did try C++ once already, back in 1992. It sucks. Trust me - writing kernel code in C++ is a BLOODY STUPID IDEA.
“ÊÂʵÉÏ£¬ÎÒÃÇÔø¾­³¢ÊÔ¹ýÓÃC++À´Ð´£¬ÊÇÔÚ1992ÄêµÄʱºò¡£ºÜÔã¸â¡£ÏàÐÅÎÒ--ÓÃC++À´Ð´ÄÚºË ......

LinuxÏÂC++ʵÏÖPHPÀ©Õ¹Öм¶Ó¦Óã¨Ò»£©


´ËƪÎÄÕÂ×¼±¸·Ö2¸ö²¿·ÖÀ´½²Êö£º
    µÚÒ»²¿·ÖÖ÷ÒªÏêϸ½²ÊöÒ»ÏÂÔõô¹¹½¨Ò»¸öÍê³ÉµÄC++Ó¦ÓÃÀ©Õ¹Ä£¿é£»
   
µÚ¶þ²¿·ÖÖ÷Òª½²ÊöÔÚPHP¼°Zend¿ò¼ÜÏÂÔõôʹÓÃZend APIºÍC++ÓïÑÔÀ´ÊµÏÖ×Ô¼ºËùÒªµÄ¹¦ÄÜÒÔ¼°ÏîÄ¿µÄ¿ª·¢£»
    ´ËƪÎÄÕÂËùÔËÓõĻ·¾³ÔÚLinux
2.4.21-4.ELsmp(Red Ha ......

win»·¾³Ï±¾µØ°²×°ruby on rails

¹ý³ÌÈçÏ£º
1¡¢rubyÏÂÔØÒ»¼ü°²×°£º
http://rubyforge.org/frs/download.php/29263/ruby186-26.exe
ruby -v ÏÔʾ°æ±¾£¬°²×°³É¹¦
2¡¢ÏÂÔØrubygems°²×°£º
http://rubyforge.org/frs/download.php/60719/rubygems-1.3.5.zip
½âѹ£¬ruby setup.rb
gem -v  ÏÔʾ°æ±¾£¬°²×°³É¹¦
3¡¢ÏÂÔØrailsµÄ gem °²×°£¨gem install ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ