From e31462e05533e320fd1a860cbb15991be0695ac0 Mon Sep 17 00:00:00 2001
From: Dominik Honnef <dominikho@gmx.net>
Date: Sun, 29 Nov 2009 16:11:44 +0100
Subject: [PATCH] further improvements to the ruby plugin

---
 cmake/FindRuby.cmake                    |   10 ++++++++++
 configure.in                            |   10 ++++++++++
 src/plugins/scripts/ruby/weechat-ruby.c |    6 +-----
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/cmake/FindRuby.cmake b/cmake/FindRuby.cmake
index be07011..fe0ea7b 100644
--- a/cmake/FindRuby.cmake
+++ b/cmake/FindRuby.cmake
@@ -54,11 +54,17 @@ IF(RUBY_EXECUTABLE)
     OUTPUT_VARIABLE RUBY_RUBY_LIB_PATH
     )
 
+  EXECUTE_PROCESS(
+    COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "puts Config::CONFIG['ruby_version']"
+    OUTPUT_VARIABLE RUBY_VERSION
+    )
+
   # remove the new lines from the output by replacing them with empty strings
   STRING(REPLACE "\n" "" RUBY_ARCH_DIR "${RUBY_ARCH_DIR}")
   STRING(REPLACE "\n" "" RUBY_POSSIBLE_LIB_PATH "${RUBY_POSSIBLE_LIB_PATH}")
   STRING(REPLACE "\n" "" RUBY_RUBY_LIB_PATH "${RUBY_RUBY_LIB_PATH}")
   STRING(REPLACE "\n" "" RUBY_ARCH "${RUBY_ARCH}")
+  STRING(REPLACE "\n" "" RUBY_VERSION "${RUBY_VERSION}")
 
   FIND_PATH(RUBY_INCLUDE_PATH
     NAMES ruby.h
@@ -77,6 +83,10 @@ IF(RUBY_EXECUTABLE)
     SET(RUBY_FOUND TRUE)
   ENDIF(RUBY_LIBRARY AND RUBY_INCLUDE_PATH)
 
+  IF(${RUBY_VERSION} STREQUAL "1.9.0")
+    SET(RUBY_FOUND FALSE)
+  ENDIF(${RUBY_VERSION} STREQUAL "1.9.0")
+
   MARK_AS_ADVANCED(
     RUBY_EXECUTABLE
     RUBY_LIBRARY
diff --git a/configure.in b/configure.in
index 085bee7..20e7772 100644
--- a/configure.in
+++ b/configure.in
@@ -529,6 +529,15 @@ if test "x$enable_ruby" = "xyes" ; then
         not_found="$not_found ruby"
     else
 	RUBY_VERSION=`$RUBY -rrbconfig -e "puts Config::CONFIG[['ruby_version']]"`
+        if test "$RUBY_VERSION" = "1.9.0"; then
+          AC_MSG_WARN([
+*** Ruby header files have been found, but they're of the version 1.9.0.
+*** Ruby 1.9.0 is an unstable release and should not be used in production.
+*** Please install Ruby >=1.8.6 or 1.9.1.
+*** WeeChat will be built without Ruby support.])
+          enable_ruby="no"
+          not_found="$not_found ruby"
+        else
         RUBY_INCLUDE=`$RUBY -rrbconfig -e "puts Config::CONFIG[['rubyhdrdir']] || Config::CONFIG[['archdir']]"`
         RUBY_ARCH=`$RUBY -rrbconfig -e 'print Config::CONFIG[["arch"]]'`
         AC_MSG_CHECKING(for Ruby header files)
@@ -546,6 +555,7 @@ if test "x$enable_ruby" = "xyes" ; then
         AC_MSG_RESULT(found)
         RUBY_LFLAGS=`$RUBY -rrbconfig -e "puts Config::CONFIG[['LIBRUBYARG_SHARED']]"`
     fi
+    fi
 else
     not_asked="$not_asked ruby"
 fi
diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c
index dfec8d4..3547976 100644
--- a/src/plugins/scripts/ruby/weechat-ruby.c
+++ b/src/plugins/scripts/ruby/weechat-ruby.c
@@ -169,7 +169,6 @@ int weechat_ruby_print_exception(VALUE err) {
                     weechat_gettext ("%s%s: error: %s"),
                     weechat_prefix ("error"), RUBY_PLUGIN_NAME,
                     STR2CSTR(rb_inspect(err)));
-    rb_ivar_set(err, "mesg", Qnil);
   } else {
 
     for (i = 0; i < RARRAY_LEN(backtrace); i++) {
@@ -479,8 +478,6 @@ weechat_ruby_load (const char *filename)
 
   if (NUM2INT(ruby_retcode) != 0)
     {
-      VALUE ruby_eval_error;
-
       switch (NUM2INT(ruby_retcode))
         {
         case 1:
@@ -954,7 +951,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
   rb_eval_string_protect(weechat_ruby_code, &ruby_error);
   if (ruby_error)
     {
-      VALUE ruby_error_info = rb_inspect(ruby_errinfo);
+      VALUE ruby_error_info = rb_inspect((VALUE)ruby_errinfo);
       weechat_printf (NULL,
                       weechat_gettext ("%s%s: unable to eval WeeChat ruby "
                                        "internal code"),
@@ -1002,6 +999,5 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
   /* unload all scripts */
   weechat_ruby_unload_all ();
   ruby_cleanup(0);
-
   return WEECHAT_RC_OK;
 }
-- 
1.6.5.3

