DEFMETHOD vs. DEFUN

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

DEFMETHOD vs. DEFUN

Rik-4
jwe,

Why are some built-in functions defined using the macro DEFMETHOD and
others using DEFUN?  I happened to notice in file-io.cc that textscan() is
defined using DEFMETHOD, but it seems like DEFUN should just be used.

If I go to libinterp/corefcn I see a preference for DEFUN, but a fair
number of DEFMETHOD as well.

grep '^DEFUN' *.cc | wc -l
526
grep '^DEFMETHOD' *.cc | wc -l
110

Just curious,
Rik


Reply | Threaded
Open this post in threaded view
|

Re: DEFMETHOD vs. DEFUN

John W. Eaton
Administrator
On 11/23/2017 05:09 PM, Rik wrote:

> Why are some built-in functions defined using the macro DEFMETHOD and
> others using DEFUN?  I happened to notice in file-io.cc that textscan() is
> defined using DEFMETHOD, but it seems like DEFUN should just be used.
>
> If I go to libinterp/corefcn I see a preference for DEFUN, but a fair
> number of DEFMETHOD as well.
>
> grep '^DEFUN' *.cc | wc -l
> 526
> grep '^DEFMETHOD' *.cc | wc -l
> 110

DEFMETHOD and DEFUN are equivalent except that DEFMETHOD creates a
function that has a reference to the octave::interpreter object as the
first argument.  If that is not needed, then DEFUN can be used.

I've only been converting to DEFMETHOD as needed.  If textscan doesn't
need the interpreter object, then it could be switched to use DEFUN.

jwe