Jump to content

somGetMethodToken

From EDM2
Revision as of 20:15, 12 October 2017 by Martini (talk | contribs) (Created page with "{{DISPLAYTITLE:somGetMethodToken}} This method returns a method access token for static method. Not generally overridden. For backward compatibility, this method does not tak...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This method returns a method access token for static method. Not generally overridden.

For backward compatibility, this method does not take an Environment parameter.

Original Class
SOMClass

Syntax

somMToken somGetMethodToken (SOMClass receiver, somId methodId)

Parameters

receiver (SOMClass)
A pointer to a SOMClass object.
methodId (somId)
A somId identifying a method.

Return Code

rc (somMToken)
Returns a somMToken method access token.

Remarks

This method returns a method access token for a static method with the specified id that was introduced by the receiver class or an ancestor of the receiver class. This method token can be passed to the somResolve function (or one of the other offset-based method resolution functions) to select a method procedure pointer from a method table of an object whose class is the same as, or is derived from the class that introduced the method.

The example below assumes that the class Animal introduces the method setSound.

Example Code

#include < >
main() {
somMToken tok;
Animal myAnimal;
somTD_Animal_setSound methodPtr; /* use typedef from animal.h */
Environment *ev = somGetGlobalEnvironment();
myAnimal = AnimalNew();

/* next 3 lines equivalent to _setSound(myAnimal, ev, "Roar!!!"); */
tok = _ somGetMethodToken(_Animal, somIdFromString("setSound"));
methodPtr = (somTD_Animal_setSound)somResolve(myAnimal, tok);
methodPtr(myAnimal, ev, "Roar!!!");
_display(myAnimal, ev);
_somFree(myAnimal);
}

Related

Functions

Methods