[[project @ 2003-04-03 03:37:06 by unknown_lamer] unknown_lamer**20030403033706 2003-04-02 Clinton Ebadi * scripts/bobot-utils.scm: Make exported symbols from the-bot-module available in the guile-user module so that scripts loaded with Interp::Load function. 2003-03-30 Clinton Ebadi * scripts/bobot-utils.scm (bot:load-module): Loads a file from the %bot:loadpath into its own module and returns that (unnamed) module (bot:use-module): Calls bot:load-module and then adds the newly loaded module to the (current-module)'s use-list * source/Interp.C (interp_init_helper): New procedure to initialize the-bot-module (this is the old Interp::Startup verbatim) (interp_post_startup_helper): New procedure to export the-bot-module from bot_module (Startup): Now calls interp_init_helper and interp_post_startup_helper to initalize the bot module system * source/Interp.H: Added private variable bot_module to Interp ] { hunk ./ChangeLog 1 +2003-04-02 Clinton Ebadi + + * scripts/bobot-utils.scm: Make exported symbols from + the-bot-module available in the guile-user module so that scripts + loaded with Interp::Load function. + +2003-03-30 Clinton Ebadi + + * scripts/bobot-utils.scm (bot:load-module): Loads a file from the + %bot:loadpath into its own module and returns that (unnamed) module + (bot:use-module): Calls bot:load-module and then adds the newly + loaded module to the (current-module)'s use-list + + * source/Interp.C (interp_init_helper): New procedure to initialize + the-bot-module (this is the old Interp::Startup verbatim) + (interp_post_startup_helper): New procedure to export + the-bot-module from bot_module + (Startup): Now calls interp_init_helper and + interp_post_startup_helper to initalize the bot module system + + * source/Interp.H: Added private variable bot_module to Interp + hunk ./NEWS 19 +- Each script is now loaded into its own module so namespace clashes + should no longer occur +- New procedure: (bot:load-module INTERFACE-SPEC) will load a "bot + module" with the specified INTERFACE-SPEC (e.g. (foo bar)). A bot + module is the same as a system module except that you don't use + define-module to define it. The %bot:loadpath is searched for + INTERFACE-SPEC (when converted to a string) with an extension in + %bot:load-extensions. E.g. (foo bar) becomes "foo/bar". +- New procedure: (bot:use-module INTERFACE-SPEC) is the same as + bot:load-module except it will make the exported bindings from + INTERFACE-SPEC available in the current-module. hunk ./NEWS 78 - PREFIX/bobotpp/scripts/ (where PREFIX is /usr/local unless you + PREFIX/share/bobotpp/scripts/ (where PREFIX is /usr/local unless you hunk ./TODO 22 -* Lock around Guile Operations hunk ./TODO 43 + UPDATE[2002-12-22]: Guile CVS now has support for full pthreads, no + more coop stuff. After 1.8 is released threads will probably be used. hunk ./bobot++.info 417 -use the lower level functions. +use the lower level functions (in progress). hunk ./bobot++.info 537 -Node: High Level Message Functions13165 -Node: Low Level Message Functions13379 -Node: Misc Scripting Stuff14132 -Node: Concept Index14551 -Node: Function Index14733 -Node: Variable Index14994 +Node: High Level Message Functions13179 +Node: Low Level Message Functions13393 +Node: Misc Scripting Stuff14146 +Node: Concept Index14565 +Node: Function Index14747 +Node: Variable Index15008 hunk ./bobot++.texinfo 606 -level functions. +level functions (in progress). hunk ./bobot++.texinfo 648 -@c Since a bot calls hooks on things it says, you have to be careful -@c about hooks that output text that might match itself. E.g. if you have -@c a hook that matches @code{"foo"} and the hook displays @code{"foo to -@c the whatsit?"}, then the hook will call itself over and over until the -@c stack overflows! To protect against this I wrote the macro -@c @code{not-from-me}. You call it like this: @code{(not-from-me from -@c (stmts if not from bot) (stmts if from bot))}. E.g. - -@c @example -@c (bot:addhook hooks/public "foo" -@c (lambda (f t p) -@c (not-from-me f ((bot:say t "foo to the what!"))))) -@c @end example - -@c This say ``foo to the what!'' to the channel that ``foo'' was said in -@c and do nothing otherwise. You can optionally specify an action to be -@c executed if the message is from the bot: - -@c @example -@c (bot:addhook hooks/public "foo" -@c (lambda (f t p) -@c (not-from-me f ((bot:say t "foo to the what!")) -@c ((bot:say t "moof"))))) -@c @end example - -@c That will do the same thing as the first example, but the bot will -@c say ``moof'' if it said ``foo'' before. That probably isn't a very -@c nice thing to do, but it works as an example. You can have as many -@c staments as you want in the clauses. - hunk ./scripts/bobot-utils.scm 1 -;;; this is a library of stuff that bobot++ scripts would probably -;;; want to use. This file is autoloaded by bobot++ +;;; This file is automatically loaded by Bobot++. This is required for +;;; the bot to function. hunk ./scripts/bobot-utils.scm 7 -;;; Why the GPL? Technically anything that uses Bobot++'s functions -;;; must be GPLed, so all of your scripts have to be GPLed anyway -;;; because you are really linking with Bobot++, a GPLed program. +;;; the-bot-module must be available to guile-user so that scripts +;;; loaded with Interp::Load have access to the bot: procedures +(module-use! (resolve-module '(guile-user) #f) + the-bot-module) hunk ./scripts/bobot-utils.scm 12 -;;; Bot load (loads a file from %bot:loadpath) +(define-public %bot:loadpath (list + (string-append (getenv "HOME") + "/.bobotpp/scripts/") + bot:sys-scripts-dir)) +(define-public %bot:load-extensions %load-extensions) hunk ./scripts/bobot-utils.scm 18 -(define %bot:loadpath (list - (string-append (getenv "HOME") - "/.bobotpp/scripts/") - bot:sys-scripts-dir)) +;;; bot-log: Write as many messages as you want to the log. If the +;;; arg is a thunk it will be executed and it's output will be +;;; written to the log +(define-public (bot:log . messages) + (for-each + (lambda (x) + (if (thunk? x) + (display (x) (bot-logport)) + (display x (bot-logport)))) + messages ) + (bot:flushport)) hunk ./scripts/bobot-utils.scm 30 -(define (bot:load file) - (let loop ((load-path %bot:loadpath)) - (if (not (null? load-path)) - (if (catch 'system-error - (lambda () - (load - (string-append (car load-path) - file))) - (lambda args - #f )) - #t - (loop (cdr load-path))) - (begin (bot:log "ERROR: File " file " Not Found!\n") #f)))) +(define-public (bot:load file) + (let path-loop ((load-path %bot:loadpath)) + (if (and (not (null? load-path)) + (not + (let ext-loop ((extensions %bot:load-extensions)) + (if (not (null? extensions)) + (if (catch 'system-error + (lambda () + (bot:log "path: " (car load-path) + " file: " file + " ext: " (car extensions) + "\n") + (load + (string-append (car load-path) + file + (car extensions)))) + (lambda args + #f )) + #t + (ext-loop (cdr extensions))) + #f)))) + (path-loop (cdr load-path)) + (begin (bot:log "ERROR: File " file " Not Found!\n") #f)))) + +(define-public (bot:load-module module-spec) + (let ((module->string + (lambda (module) + (apply + (lambda (s . rest) + (string-append + s + (apply string-append + (map (lambda (str) (string-append "/" str)) rest)))) + (map symbol->string module)))) + (new-module + (make-module)) + (old-module (current-module))) + (module-use! new-module the-bot-module) + (set-current-module new-module) + (bot:load (module->string module-spec)) + (set-current-module old-module) + new-module)) + +(define-public (bot:use-module module-spec) + (module-use! (current-module) + (bot:load-module module-spec))) + hunk ./scripts/bobot-utils.scm 82 -(define (bot:match-not-channel regex) +(define-public (bot:match-not-channel regex) hunk ./scripts/bobot-utils.scm 87 -(define (bot:match-to-me regex) - (string-append (match-not-channel (bot:getnickname)) +(define-public (bot:match-to-me regex) + (string-append (bot:match-not-channel (bot:getnickname)) hunk ./scripts/bobot-utils.scm 92 -(define str-app string-append) ; shorter - - -;;;; Misc UTILS - -;;; bot-log: Write as many messages as you want to the log. If the -;;; arg is a thunk it will be executed and it's output will be -;;; written to the log -(define (bot:log . messages) - (for-each - (lambda (x) - (if (thunk? x) - (display (x) (bot-logport)) - (display x (bot-logport)))) - messages ) - (bot:flushport)) +(define-public str-app string-append) ; shorter hunk ./scripts/bobot-utils.scm 97 -(define (ctcp-quote message) +(define-public (ctcp-quote message) hunk ./scripts/bobot-utils.scm 104 -(define bot-load bot:load) -(define bot-action bot:action) -(define bot-adduser bot:adduser) -(define bot-addserver bot:addserver) -(define bot-addshit bot:addshit) -(define bot-ban bot:ban) -(define bot-cycle bot:cycle) -(define bot-deban bot:deban) -(define bot-delserver bot:delserver) -(define bot-deluser bot:deluser) -(define bot-delshit bot:delshit) -(define bot-deop bot:deop) -(define bot-die bot:die) -(define bot-do bot:do) -(define bot-invite bot:invite) -(define bot-join bot:join) -(define bot-keep bot:keep) -(define bot-kick bot:kick) -(define bot-kickban bot:kickban) -(define bot-lock bot:lock) -(define bot-logport bot:logport) -(define bot-mode bot:mode) -(define bot-msg bot:msg) -(define bot-nextserver bot:nextserver) -(define bot-nick bot:nick) -(define bot-op bot:op) -(define bot-part bot:part) -(define bot-reconnect bot:reconnect) -(define bot-say bot:say) -(define bot-server bot:server) -(define bot-setversion bot:setversion) -(define bot-tban bot:tban) -(define bot-tkban bot:tkban) -(define bot-topic bot:topic) -(define bot-unlock bot:unlock) -(define bot-getnickname bot:getnickname) -(define bot-getserver bot:getserver) -(define bot-getserverlist bot:getserverlist) -(define bot-flush bot:flush) -(define bot-flushport bot:flushport) -(define bot-random bot:random) -(define bot-addcommand bot:addcommand) -(define bot-delcommand bot:delcommand) -(define bot-addhook bot:addhook) -(define bot-addtimer bot:addtimer) -(define bot-deltimer bot:deltimer) +(define-public bot-load bot:load) +(define-public bot-action bot:action) +(define-public bot-adduser bot:adduser) +(define-public bot-addserver bot:addserver) +(define-public bot-addshit bot:addshit) +(define-public bot-ban bot:ban) +(define-public bot-cycle bot:cycle) +(define-public bot-deban bot:deban) +(define-public bot-delserver bot:delserver) +(define-public bot-deluser bot:deluser) +(define-public bot-delshit bot:delshit) +(define-public bot-deop bot:deop) +(define-public bot-die bot:die) +(define-public bot-do bot:do) +(define-public bot-invite bot:invite) +(define-public bot-join bot:join) +(define-public bot-keep bot:keep) +(define-public bot-kick bot:kick) +(define-public bot-kickban bot:kickban) +(define-public bot-lock bot:lock) +(define-public bot-logport bot:logport) +(define-public bot-mode bot:mode) +(define-public bot-msg bot:msg) +(define-public bot-nextserver bot:nextserver) +(define-public bot-nick bot:nick) +(define-public bot-op bot:op) +(define-public bot-part bot:part) +(define-public bot-reconnect bot:reconnect) +(define-public bot-say bot:say) +(define-public bot-server bot:server) +(define-public bot-setversion bot:setversion) +(define-public bot-tban bot:tban) +(define-public bot-tkban bot:tkban) +(define-public bot-topic bot:topic) +(define-public bot-unlock bot:unlock) +(define-public bot-getnickname bot:getnickname) +(define-public bot-getserver bot:getserver) +(define-public bot-getserverlist bot:getserverlist) +(define-public bot-flush bot:flush) +(define-public bot-flushport bot:flushport) +(define-public bot-random bot:random) +(define-public bot-addcommand bot:addcommand) +(define-public bot-delcommand bot:delcommand) +(define-public bot-addhook bot:addhook) +(define-public bot-addtimer bot:addtimer) +(define-public bot-deltimer bot:deltimer) hunk ./scripts/scheme_add_user 3 -(load "bobot:utils.scm") hunk ./scripts/scripts.load 1 -stupid_stuff/stupid_stuff -country -hello -tamere -uname -uptime -eval +(stupid_stuff stupid_stuff) +(country) +(hello) +(tamere) +(uname) +(uptime) +(eval) hunk ./source/Interp.C 32 +// static class member initial definitions hunk ./source/Interp.C 34 +SCM Interp::bot_module = 0; hunk ./source/Interp.C 58 -#define bot_new_procedure(a, b, c, d, e) scm_c_define_gsubr (a, c, d, e, b) +#define bot_new_procedure(a, b, c, d, e) scm_c_define_gsubr (a, c, d, e, b); scm_c_export (a, 0) +#define scm_c_define_gsubr(a, b, c, d, e) scm_c_define_gsubr (a, b, c, d, e); scm_c_export (a, 0) +#define scm_c_define(a, b) scm_c_define (a, b); scm_c_export (a, 0) hunk ./source/Interp.C 63 -Interp::Startup() +interp_init_helper (void* unused) hunk ./source/Interp.C 65 + scm_c_use_module ("guile-user"); hunk ./source/Interp.C 184 +} + +#undef bot_new_procedure +#undef scm_c_define_gsubr +#undef scm_c_define + hunk ./source/Interp.C 191 +SCM +interp_post_startup_helper (void *bot_module) +{ + SCM module = static_cast (bot_module); + scm_c_define ("the-bot-module", module); + scm_c_export ("the-bot-module", 0); hunk ./source/Interp.C 201 + return 0; +} hunk ./source/Interp.C 204 - +void +Interp::Startup() +{ + bot_module = scm_c_define_module ("the-bot-module", + interp_init_helper, 0); + scm_c_call_with_current_module (bot_module, + interp_post_startup_helper, + bot_module); hunk ./source/Interp.C 235 +void load_script_helper (void* file) +{ + String filename = *static_cast (file); + scm_c_use_module ("guile-user"); + gh_eval_file_with_catch(filename, Interp::ErrorHandler); +} + hunk ./source/Interp.C 250 + //scm_c_define_module ("", load_script_helper, &filename); hunk ./source/Interp.H 46 + static SCM bot_module; }