Posted to tcl by apw at Tue Aug 07 15:36:28 GMT 2007view raw

  1. /*
  2. * tclItclOOMethod.c --
  3. *
  4. * This file contains code to create and manage methods.
  5. *
  6. * Copyright (c) 2007 by Arnulf P. Wiedemann
  7. *
  8. * See the file "license.terms" for information on usage and redistribution of
  9. * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10. *
  11. * RCS: @(#) $Id: tclItclOOMethod.c,v 1.0 2007/07/30 14:20:21 apw Exp $
  12. */
  13.  
  14. #include "tclOOInt.h"
  15.  
  16. ^L
  17. /*
  18. * ----------------------------------------------------------------------
  19. *
  20. * Itcl_NewProcMethod --
  21. *
  22. * Create a new procedure-like method for an object for Itcl.
  23. *
  24. * ----------------------------------------------------------------------
  25. */
  26.  
  27. Tcl_Method
  28. Itcl_NewProcMethod(
  29. Tcl_Interp *interp, /* The interpreter containing the object. */
  30. Object *oPtr, /* The object to modify. */
  31. Tcl_Obj *nameObj, /* The name of the method, which must not be
  32. * NULL. */
  33. Tcl_Obj *argsObj, /* The formal argument list for the method,
  34. * which must not be NULL. */
  35. Tcl_Obj *bodyObj, /* The body of the method, which must not be
  36. * NULL. */
  37. ClientData *clientData)
  38. {
  39. ProcedureMethod *pmPtr;
  40. int flags; /* Whether this is a public method. */
  41. Tcl_Method method;
  42.  
  43. flags = PUBLIC_METHOD | USE_DECLARER_NS;
  44. method = (Tcl_Method)TclOONewProcMethod(interp, (Object *)clientData, flags,
  45. nameObj, argsObj, bodyObj, &pmPtr);
  46. pmPtr->flags = flags & USE_DECLARER_NS;
  47. pmPtr->clientData = clientData;
  48. if (clientData != NULL) {
  49. *clientData = pmPtr;
  50. }
  51. return method;
  52. }
  53. ^L
  54. /*
  55. * ----------------------------------------------------------------------
  56. *
  57. * Itcl_NewProcClassMethod --
  58. *
  59. * Create a new procedure-like method for a class for Itcl.
  60. *
  61. * ----------------------------------------------------------------------
  62. */
  63.  
  64. Tcl_Method
  65. Itcl_NewProcClassMethod(
  66. Tcl_Interp *interp, /* The interpreter containing the class. */
  67. Class *clsPtr, /* The class to modify. */
  68. TclOO_PreCallProc preCallPtr,
  69. TclOO_PostCallProc postCallPtr,
  70. ClientData clientData,
  71. Tcl_Obj *nameObj, /* The name of the method, which may be NULL;
  72. * if so, up to caller to manage storage
  73. * (e.g., because it is a constructor or
  74. * destructor). */
  75. Tcl_Obj *argsObj, /* The formal argument list for the method,
  76. * which may be NULL; if so, it is equivalent
  77. * to an empty list. */
  78. Tcl_Obj *bodyObj, /* The body of the method, which must not be
  79. * NULL. */
  80. ClientData *clientData2)
  81. {
  82. int flags; /* Whether this is a public method. */
  83. ProcedureMethod *pmPtr;
  84. Tcl_Method method;
  85.  
  86. flags = PUBLIC_METHOD | USE_DECLARER_NS;
  87. method = (Tcl_Method)TclOONewProcClassMethod(interp, clsPtr, flags,
  88. nameObj, argsObj, bodyObj, &pmPtr);
  89. pmPtr->flags = flags & USE_DECLARER_NS;
  90. pmPtr->preCallProc = preCallPtr;
  91. pmPtr->postCallProc = postCallPtr;
  92. pmPtr->clientData = clientData;
  93. if (clientData2 != NULL) {
  94. *clientData2 = pmPtr;
  95. }
  96. return method;
  97. }
  98.