- My main application is in Objective-C/Cocoa (OS X)
- The main application is "extended" using Python "plugins"
- We're making use of the Python framework
This is the code I'm using as a "bridge" to execute a specific script:
from Foundation import *
from AppKit import *
import imp
import sys
class ppPluginBridge(NSObject):
@classmethod
def loadModuleAtPath_functionName_arguments_documents_(self, path, func, args,docs):
f = open(path)
try:
mod = imp.load_module('plugin', f, path, (".py", "r", imp.PY_SOURCE))
realfunc = getattr(mod, func, None)
if realfunc is not None:
realfunc(*tuple(args))
except Exception as e:
docs.showConsoleError_('%s' % e)
finally:
f.close()
return NO
return YES
So this function takes a script in path and loads/executes it.
Now, what I need is : make some python classes/functions/modules automatically available to the final script (either declared externally or - preferably - in my ppPluginBridge.py file).
How can that be done?
finally: ... return NOmeans that the function always returnsNO