Update all deprecated/discouraged Guile calls
[clinton/bobotpp.git] / source / BotInterp.C
index 815c9bf..0a1419c 100644 (file)
@@ -1,6 +1,6 @@
 // BotInterp.C  -*- C++ -*-
 // Copyright (c) 1998 Etienne BERNARD
-// Copyright (C) 2002 Clinton Ebadi
+// Copyright (C) 2002,2005,2008 Clinton Ebadi
 
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -14,7 +14,8 @@
 
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+// 02110-1301, USA.
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -35,8 +36,9 @@ extern "C"
 BotInterp::BotInterp(Bot *b, String fn)
   : bot(b), counter(0)
 {
-  logPort = scm_open_file(Utils::str2scm (fn),
-                          Utils::str2scm ("a"));
+  logPort = scm_open_file (Utils::str2scm (fn),
+                           Utils::str2scm ("a"));
+
   scm_gc_protect_object(logPort);
 }
 
@@ -52,13 +54,10 @@ BotInterp::LoadScript(String filename)
   Interp::LoadScript(bot, filename);
 }
 
-void
-BotInterp::ScriptLog(SCM throw_args)
+SCM
+BotInterp::ScriptLog()
 {
-  scm_display_error_message(SCM_CADR (throw_args),
-                            SCM_CADDR (throw_args),
-                            logPort);
-  scm_flush(logPort);
+  return logPort;
 }
 
 namespace
@@ -75,9 +74,10 @@ BotInterp::AddHook(int hooktype, SCM regex, SCM function, int pri, bool fall,
   if (scm_string_p(regex) == SCM_BOOL_F)
     return false;
   String rx = Utils::to_upper (Utils::scm2str (regex));
-  SCM r = scm_make_regexp(regex,
-                          scm_listify (gh_lookup("regexp/icase"),
-                                  SCM_UNDEFINED));
+  // fixme: really ought to use scm_c_module_lookup with bot module
+  SCM r = scm_make_regexp (regex,
+                          scm_list_n (scm_variable_ref (scm_c_lookup ("regexp/icase")),
+                                      SCM_UNDEFINED));
   scm_gc_protect_object(r);
   scm_gc_protect_object(function);
   // First, we check if an hook doesn't exist yet
@@ -117,10 +117,11 @@ BotInterp::RunHooks(int hooktype, String match, SCM args)
                         SCM_UNDEFINED, SCM_UNDEFINED) != SCM_BOOL_F)
       {
        wd.func = (*it)->function;
-       result = gh_catch(SCM_BOOL_T, 
-                         (scm_t_catch_body) scm_apply_wrapper,
-                         static_cast<void *> (&wd), 
-                         (scm_t_catch_handler) Interp::ErrorHandler, 0);
+       result = scm_internal_catch(SCM_BOOL_T, 
+                                   (scm_t_catch_body) 
+                                   Interp::LazyApplyWrapper,
+                                   static_cast<void *> (&wd), 
+                                   (scm_t_catch_handler) Interp::EmptyHandler, 0);
        if (! (*it)->fallthru)
          break;
     }
@@ -136,13 +137,13 @@ BotInterp::AddTimer(int delay, SCM function)
   scm_gc_protect_object(function);
   Timer *t = new Timer(c, when, function);
   timersList.push_back(t);
-  return scm_long2num (c);
+  return scm_from_int (c);
 }
 
 bool
 BotInterp::DelTimer(SCM timer)
 {
-  int count = scm_num2long(timer, SCM_ARG1, "BotInterp::DelTimer");
+  int count = scm_to_int (timer);
   std::list<Timer *>::iterator it = timersList.begin();
   std::list<Timer *>::iterator it2 = timersList.end();
 
@@ -165,13 +166,14 @@ BotInterp::RunTimers(int now)
   std::list<Timer *>::iterator it3;
 
   struct wrapper_data wd;
-  wd.args = scm_listify (SCM_UNDEFINED);
+  wd.args = scm_list_n (SCM_UNDEFINED);
 
   while (it != it2) {
     if ((*it)->when <= now) {
       wd.func = (*it)->function;
-      gh_catch(SCM_BOOL_T, (scm_t_catch_body) scm_apply_wrapper,
-               (void *)&wd, (scm_t_catch_handler) Interp::ErrorHandler, 0);
+      scm_internal_catch(SCM_BOOL_T,
+                    (scm_t_catch_body) Interp::LazyApplyWrapper, (void *)&wd,
+                    (scm_t_catch_handler) Interp::EmptyHandler, 0);
       scm_gc_unprotect_object(wd.func);
       it3 = it;
       ++it3;