On Aug 10, 2005, at 6:02 PM, Nathaniel Gray wrote:
Is there any way to send float or double arguments to a method
designated at runtime? I've tried using objc_msgSendv, casting
it in various ways, and using -performv::, but nothing works.
Using objc_msgSendv() properly requires knowledge of your
platform's ABI. In particular, floating-point values must be
stored in a special place in the marg_list on PowerPC. objc-msg-
ppc.s notes some of the details.
I think those details are pretty well hidden by the marg_* macros
though. I've used method_getArgumentInfo() to get the offset of the
argument, and marg_setValue() to set it before calling objc_msgSendv
(). It worked fine with all sorts of types, including floats and
doubles.
Really? That's exactly what I'm doing. For a test case I wrote a
class OCOCTestCall with a class method
void test1_1mini() {
id nc = NSClassFromString(@"OCOCTestCall");
SEL sel = @selector(callFloat:);
marg_list margs;
int offset;
Method method;
const char* argtype;
union {float f; id i;} u;
[n8gray@golux test]$ ./ctest1
Got float: 0.000000
msgSendv: Float f = 0.000000
Got float: 0.000000
((float_msgSendv)objc_msgSendv): Float f = 1.000000
Got float: 0.000000
[nc performv::]: Float f = 0.000000
* using objc_msgSend() or objc_msgSend_stret() directly. Cast
objc_msgSend() to a function pointer type that matches your
method's signature, then make the call.
Typecasting only works for that if the signature is known at
compile-time. If you won't know the signature until runtime, you'll
need to either use the marg_* macros and pass the resulting
marg_list struct to objc_msgSendv(). Or, use ffi or ffcall to call
objc_msgSend().
That last option (ffi/ffcall) is the most complex, but it's the
only way I've found to implement a "foreign" language (Perl in my
case) subclass of an Objective-C class, and allow the "foreign"
language to call super's methods.
Hmm. I looked at libffi but the release notes said it didn't support
vararg functions. I'll have to look again. Maybe I'll take a look
at your code. :-)
Incidentally, I'm writing an Objective-C wrapper for OCaml, so your
code is more than a little bit relevant.
The problem I found was that there's no "v" (at least none that's
documented) equivalent to the objc_msgSendSuper() function. What I
settled on doing was using ffcall to call the "normal" msgSendSuper
functions, rather than the marg_* macros and the "v" functions.
if you have a pointer to the object's Class can't you use the
super_class field to get access to superclass methods? Maybe I'm
missing something?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/objc-language/email@hidden