Skip navigation.
 
mlWrapping C functions in Objective C proxy objects: naming convention?
FROM : Austin Ziegler
DATE : Thu Nov 20 06:27:22 2008

For a project that I'm working on, I have a need to write a code
generator that will wrap certain kinds of C functions as Objective C
messages on an Objective C proxy. Because I don't ultimately control
the input, the parameters on the C functions may be poorly named. I'm
looking for advice on how one might make useful object message names
from C functions.

The format of the functions in question is essentially like this[1]:

  int ns__add(double a, double b, double *result);
  int ns__sub(double a, double b, double *result);
  int ns__mul(double a, double b, double *result);
  int ns__div(double a, double b, double *result);
  int ns__pow(double a, double b, double *result);

The int return is a status code; the result of the operation is in
double* result. If there's an error in the operation. (The status code
may be ignorable, in which case part of my following question is
answered; I'm still researching this part. I suspect that it is best
not ignored.)

Anyway, the problem is how I should convert this function with poorly
named parameters into a proxy object and messages?

The options that I've come up with (expressed in terms of use) follow.
They're all expressed in terms of an object ns__CalcProxy:

  ns__CalcProxy calc = [[ns__CalcProxy alloc] init];
  double a, b, result;
  int status;

  result = [calc addDoubleA:a withDoubleB:b]; // #1
  result = [calc addDoubleA:a withDoubleB:b status:&status]; // #2
  status = [calc addDoubleA:a withDoubleB:b returning:&result]; // #3

The examples given here are simple; the items being returned may in
fact be pretty complex (and I'm planning on making it so that
structured parameters and return values may be passed in Objective C
proxies themselves).

I really don't like the "addDoubleA:withDoubleB:" name, to be honest,
but what am I supposed to do with:

  struct ns1__ludcmpResponse {matrix *a; ivector *i; xsd__double d;};
  int ns1__ludcmp(matrix *a, struct ns1__ludcmpResponse** result);

Like I said; I don't really have any control over the names of the
parameters, more's the pity.

-austin
[1] Actually, they're more like this:
  int soap_call_ns__add(struct soap *soap, const char *soap_endpoint,
        const char *soap_action, double a, double b, double *result);
But there's enough information in there for me to extract the former
to use as a proxy function.
--
Austin Ziegler * <email_removed> * http://www.halostatue.ca/
              * <email_removed> * http://www.halostatue.ca/feed/
              * <email_removed>

Related mailsAuthorDate
mlWrapping C functions in Objective C proxy objects: naming convention? Austin Ziegler Nov 20, 06:27
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Alexander Spohr Nov 20, 10:54
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Austin Ziegler Nov 20, 13:58
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Ken Thomases Nov 20, 14:52
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Bill Bumgarner Nov 20, 18:13
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Michael Ash Nov 20, 18:15
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Austin Ziegler Nov 20, 19:55
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Jonathon Kuo Nov 20, 22:23
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Shawn Erickson Nov 20, 23:07
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Ken Tozier Nov 21, 00:09
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Jonathon Kuo Nov 21, 00:58
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Charles Srstka Nov 21, 02:06
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Jonathon Kuo Nov 21, 02:40
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Charles Srstka Nov 21, 02:53
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Jonathon Kuo Nov 21, 04:08
mlRe: Wrapping C functions in Objective C proxy objects: naming convention? Austin Ziegler Nov 21, 06:03