This is basically correct. You don't even need to call your own
initfoo(), it is automatically called when you do "import foo" as long
as there's an entry for foo in the table in config.c.
This way, all your scripts will run in the same __main__ module, which
will keep hold on to any values left there by previous scripts. It's
up to you if you like that -- you could clean up after a script, or
initialize a new environment for each new run.
> Next step: all the function I consider receive a string or
> an integer, and return (possibly) a string. Thus, I just
> have to start each such function with
>
> getargs(args, "s", &p) or getargs(args, "s", &i)
^i please!
> and exit with a
>
> return mkvalue("s", r), where char *r holds the return value.
>
> Of course if there is an error I have to call err_setstr().
OK.
> Finally: I really need to be able to call my functions
> func1, func2,..., and not foo.func1, foo.func2 etc. Is
> there a way to obtain this? For otherwise all existing scripts
> will break!
Instead of "import foo", you can run_command("from foo import *").
--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>