Re: objc_method_list structure?
Re: objc_method_list structure?
- Subject: Re: objc_method_list structure?
- From: "Mike Hall" <email@hidden>
- Date: Thu, 11 Nov 2004 20:59:25 -0600
----- Original Message -----
From: "Tim Conkling" <email@hidden>
To: "cocoa-dev" <email@hidden>
Sent: Thursday, November 11, 2004 8:02 PM
Subject: objc_method_list structure?
> According to the documentation, the method_list field in the above
> structure is supposed to be "An array of objc_method data structures."
> I'm not sure what should go in the [0] index and what should go in the
> [1] index in order to make this array...
>
> Can anyone fill me in?
private void addMethods(objc_class classdef,ObjectiveCMethod[] methods) {
int[] cnt = new int[] { methods.length };
int mlistptr = malloc(sizeOfMethodList +
methods.length*objc_method.sizeOf); // Get new array
memmove(mlistptr+4,cnt,4); // Set the new count
int mlist = mlistptr + 8; // Bump to start of objc_method
array
// Finally add the new one
for (int i=0; i< methods.length; i++) {
objc_method added = new objc_method(mlist+i*objc_method.sizeOf);
added.setSelector(methods[i].getSelector());
added.setMethodImp(methods[i].getImp());
String types = encode(methods[i].getMethod(),methods[i].getHints());
byte[] b = (types+"\0").getBytes();
int typesptr = malloc(b.length);
memmove(typesptr,b,b.length);
added.setMethodTypes(typesptr);
}
class_addMethods(classdef.getPointer(),mlistptr);
}
Been a while, and I did it in java, but the above is I think how I set up my
java interface, maybe not correctly, but seemed to work so far.
Your count is the number of methods.
int[] cnt = new int[] { methods.length };
length of the methods array here.
That goes 4 off the front of the method list pointer. Skips the bogus
obsolete or whatever field you showed?
Then you add in the array of objc_method structs.
That I happen to have in C
struct objc_method
{
SEL method_name;
char * method_types;
IMP method_imp;
};
If of any interest, that struct is implemented by
macnative.jnidirect.ns.struct.objc_method.java
and the above code is from
macnative.jnidirect.ns.ObjectiveCClass
in my JNIDirect 'ns' cocoa package.
which just changed locations from my iDisk to
http://sourceforge.net/projects/macnative/
an old JDirect project I'd set up out of curiosity to see what kind of
interest there might be in offering some of my code that way.
There wasn't much.
JDirect was the native glue used by Mac Java prior to the 1.4 Cocoa based
VM.
JDirect is now unsupported.
JNIDirect is a separate SourceForge project that provides a JDirect
compatible JNI linkage code generator sort of deal.
http://sourceforge.net/projects/jnidirect/
if I remember right.
Sorry, for me to answer requires a certain amount of digression.
Mike Hall mikehall at spacestar dot net
http://www.spacestar.net/users/mikehall
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden