[Pyobjc-dev] Method Swizzling - class_getInstanceMethod
Brought to you by:
ronaldoussoren
|
From: Saptarshi G. <sap...@gm...> - 2008-10-14 05:54:27
|
Hello,
How exactly do I use this function? For example,
This is a plugin in Python(Leopard 10.5.5), the principal class is
Voo(see end of email).
I load the bundle and instantiate it like this
NSBundle *bun=[NSBundle bundleWithPath:@"/Users/yanger/toperuse/PyRu/
example2/dist/gigo.plugin"];
Class currPrincipalClass = [bun principalClass];
id ins=[[currPrincipalClass alloc] init];
(i'm basing this of PyRu)
Voo is trying to swizzle goody method I added to PythonStuff.
However,
a) load is not run
b) <type 'exceptions.AttributeError'>: 'module' object has no
attribute 'class_getInstanceMethod'
Any ideas what I should do?
Thanks
Saptarshi
==Python Bundle(gigo.py)==
from Foundation import *
from AppKit import *
from Foundation import *
import objc
class PythonStuff(objc.Category(PythonStuff)):
def mygoody(self):
NSLog("Alpha betea")
class Voo(NSObject):
@classmethod
def load(cls):
NSLog("A")
def init(self):
super(Voo, self).init()
NSLog("B:")
originalMethod =
objc.class_getInstanceMethod(objc.lookUpClass(u"PythonStuff"), "goody")
replacedMethod =
objc.class_getInstanceMethod(objc.lookUpClass(u"PythonStuff"),
"mygoody")
objc.method_exchangeImplementations(originalMethod,
replacedMethod)
NSLog("C:")
return self
==setup.py==
from distutils.core import setup
import py2app
plist = dict(NSPrincipalClass='Voo')
setup(
plugin = ['gigo.py'],
options=dict(py2app=dict(extension='.plugin', plist=plist))
)
|