Thanks for the replies. Yes, I know what I'm doing here:)
First of all, I agree with David that GC is not an issue, as long as you keep a reference to the object.
Second, I'm exposing *a few* *functions* into the global name space because when Mushclient's trigger/alias/timer fires, and if you set it to call-back a function, then Mushclient only knows to search in ax._scriptEngine_.globalNameSpaceModule for that function.
(BTW, it must be a function, and cannot be a *callable object*.)
If I'm writing all the script in the file that is included directly by Mushclient, then I can just use "globals()" to access the global symbol table. Or, if we are just using the "normal" python, we can "import __main__" and set an object to __main__'s attribute.
However, this does not work in Mushclinet (or activeScript), because:
1. "__main__" seems not to be the real global name space. (ax._scriptEngine_.globalNameSpaceModule is)
2. From a module other than the one directly included by the mushclient, one cannot use the "globals()" trick.
Therefore, if one wants his/her codes to be modular, and wants to use the trigger/alias/timer's callback feature, here's the only way I've seen so far:
1. Expose a global trigger/alias/timer function dispatcher (or delegation), which will be called by any fired trigger/alias/timer.
2. This dispatcher looks up a table, according to the fired trigger/alias/timer's name, to invoke the real callback function.
Thanks,
KL |