Quiet annoying mutex debug logging messages
[clinton/bobotpp.git] / source / Interp.C
index 911bad2..0e1870b 100644 (file)
@@ -26,6 +26,9 @@
 #endif
 
 #include <libguile.h>
+extern "C" {
+#include <libguile/hooks.h>
+}
 
 #include "Bot.H"
 #include "BotInterp.H"
@@ -43,7 +46,7 @@ SCM Interp::bot_module = 0;
 pthread_mutex_t Interp::mutex = PTHREAD_MUTEX_INITIALIZER;
 #endif
 
-typedef SCM (*SCMFunc)();
+typedef scm_t_subr SCMFunc;
 
 SCM
 Interp::ScmApplyWrapper (void *data)
@@ -85,7 +88,7 @@ Interp::EmptyHandler(void *data, SCM tag, SCM args)
 SCM
 Interp::LazyApplyWrapper(void *data)
 {
-  return scm_internal_lazy_catch(SCM_BOOL_T,
+  return scm_internal_catch(SCM_BOOL_T,
                                 (scm_t_catch_body) Interp::ScmApplyWrapper, 
                                 data,
                                 (scm_t_catch_handler) Interp::LazyHandler, 
@@ -96,8 +99,8 @@ Interp::LazyApplyWrapper(void *data)
 static SCM
 lazy_eval_file(char *filename)
 {
-  return scm_internal_lazy_catch(SCM_BOOL_T,
-                                (scm_t_catch_body) scm_c_primitive_load, 
+  return scm_internal_catch(SCM_BOOL_T,
+                                (scm_t_catch_body) scm_c_primitive_load_path
                                 filename,
                                 (scm_t_catch_handler) Interp::LazyHandler, 0);
 }
@@ -105,7 +108,7 @@ lazy_eval_file(char *filename)
 static SCM
 lazy_eval_string(char *str)
 {
-  return scm_internal_lazy_catch(SCM_BOOL_T,
+  return scm_internal_catch(SCM_BOOL_T,
                                 (scm_t_catch_body) scm_c_eval_string, str,
                                 (scm_t_catch_handler) Interp::LazyHandler, 0);
 }
@@ -131,6 +134,12 @@ interp_init_helper (void* unused)
   scm_c_define ("bot:user-friend", scm_from_int (User::FRIEND));
   scm_c_define ("bot:user-master", scm_from_int (User::MASTER));
 
+  // user channel modes
+  scm_c_define ("bot:mode/op", scm_from_int (User::OP_MODE));
+  scm_c_define ("bot:mode/voice", scm_from_int (User::VOICE_MODE));
+  scm_c_define ("bot:mode/away", scm_from_int (User::AWAY_MODE));
+  scm_c_define ("bot:mode/ircop", scm_from_int (User::IRCOP_MODE));
+
   // protection
   scm_c_define ("bot:protection/none", scm_from_int (User::NO_PROT));
   scm_c_define ("bot:protection/no-ban", scm_from_int (User::NO_BAN));
@@ -150,8 +159,8 @@ interp_init_helper (void* unused)
   
   // sys-dir
   scm_c_define ("bot:sys-scripts-dir", 
-               scm_from_locale_string (String(PREFIX) + 
-                                      "/share/bobotpp/scripts/"));
+               scm_from_locale_string ((String(PREFIX) + 
+                                        "/share/bobotpp/scripts/").c_str ()));
   // Hooks
   scm_c_define ("hooks/action", scm_from_int(Hook::ACTION));
   scm_c_define ("hooks/nickname", scm_from_int(Hook::NICKNAME));
@@ -199,6 +208,8 @@ interp_init_helper (void* unused)
   bot_new_procedure ("bot:change-command-level", 
                     (SCMFunc)ScriptCommands::ChangeCommandLevel,
                     2, 0, 0);
+  scm_c_define_gsubr ("bot:channel-users", 1, 0, 0,
+                     (SCMFunc)ScriptCommands::ChannelUsers);
   scm_c_define_gsubr ("bot:ctcp", 3, 0, 0,
                      (SCMFunc)ScriptCommands::CTCP);
   scm_c_define_gsubr ("bot:ctcp-reply", 3, 0, 0,
@@ -285,10 +296,9 @@ interp_post_startup_helper (void *bot_module)
   scm_c_export ("the-bot-module", 0);
 
   // load bobot-utils
-  scm_primitive_load 
-    (scm_from_locale_string (String(PREFIX) + 
-                            "/share/bobotpp/scripts/bobot-utils.scm"));
-  return SCM_UNSPECIFIED;
+  return scm_primitive_load_path
+    (scm_from_locale_string ((String(PREFIX) + 
+                             "/share/bobotpp/scripts/bobot-utils.scm").c_str ()));
 }
 
 void
@@ -326,7 +336,7 @@ Interp::Execute(Bot *b, String command)
   
   bot = b;
   scm_internal_catch(SCM_BOOL_T,
-                    (scm_t_catch_body) lazy_eval_string, (void *) static_cast<const char *> (command),
+                    (scm_t_catch_body) lazy_eval_string, (void *) static_cast<const char *> (command.c_str ()),
                     (scm_t_catch_handler) Interp::EmptyHandler, 0);
   
 #ifdef MULTITHREAD
@@ -346,7 +356,7 @@ Interp::LoadScript(Bot *b, String filename)
   bot = b;
   scm_internal_catch(SCM_BOOL_T,
                     (scm_t_catch_body) lazy_eval_file, 
-                    (void *)static_cast<const char * >(filename),
+                    (void *)static_cast<const char * >(filename.c_str ()),
                     (scm_t_catch_handler) Interp::EmptyHandler, 0);
 #ifdef MULTITHREAD
   // We release the lock