[Types-sig] Help?

skaller skaller@maxtal.com.au
Wed, 29 Dec 1999 05:41:06 +1100


Um, I feel dumb asking this but ..

I'm having some trouble figuring out how the C API works
with functions and methods. Consider the script:

	def f(self,arg): pass
	class X:
		g = f

	x = X()
	X.g(x, 1)
	f(2,1)
	x.g(1)

Here, there is only a single function object, f.
A call to f requires two arguments: in C, the
declaration

	PyObject *f(PyObject *self, PyObject *args)

would have args be a two argument tuple, and self NULL,
for the call:

	f(2,1)

Now, when f is called by _either_

	X.g(x,1)
	x.g(1)

then x is the 'self' argument of the function,
and the tuple 'args' contains only one element.
Right?

So HOW do I convert f to a C function?
It does not seem possible. When used as 'f',
there are two arguments in the 'args' tuple,
but when used as g, the first arg is the self
pointer. The python script indicates a _single_
function can be correctly used in both cases,
but I cannot see how this is possible if
a C function is used.

Sorry to ask a dumb question. Can anyone correct
my misconceptions?

-- 
John Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850