.. highlightlang:: us .. index:: set_method_table .. _set_method_table: set_method_table ================ .. us.tag set_method_table NOTREADYENGLISH obj New411 Changed5502 :ref:`set_method_table` sets the methods (member functions) for the given object. .. function:: obj = set_method_table(obj, ssClass) obj = set_method_table(obj, ssClass, bUpdate) .. us.return **Return Value** *obj* is a pointer for the first parameter or 0, if an error occurred. .. us.params **Parameters** .. uparam:: obj *obj* is the object created with :ref:`obj_create`. .. uparam:: ssClass To set the method table, a function with the name *ssClass* + "_methods" will be invoked. This function must set the methods, see comment. .. uparam:: bUpdate If the *bUpdate* parameter is TRUE (1), the function *ssClass* + ``"_method"`` will be invoked and the method table will be copied to ``_g()._method_table``. The method table will be assigned to *obj* by calling :ref:`obj_set_methods`. If the *bUpdate* parameter is FALSE (0), only the current ``_g()._method_table`` will be assigned to the *obj* object. If the *bUpdate* is not specified, the value set in ``_g()._debug`` will be used for *bUpdate*. The first call after F4 (save/execute) ``_g()._debug`` is set to 1. .. us.comment **Comment** To create a method table, you must specify global functions witch can be added to the table. The first parameter of the function must be the object itself:: def my_obj_print(this) { // ... } methodTable = [. print = "my_obj_print" ]; *methodTable* is the method table. The :ref:`set_method_table` function expects a function with the name *ssClass* + "_methods" to exist. This function must return an object with a method table:: def my_methods() { return [. print = "my_obj_print" ]; } :: o = [. a = 1, b = 2]; set_method_table(o, "my") The method table will be copied into the global variable ``_g()._method_table.my`` (see :ref:`_g `) and the pointer will be saved with :ref:`obj_set_methods` in the object *o*. With ``o.methods`` (see :ref:`obj_methods`) the method can be retrieved. .. us.example **Example** .. code-block:: us :linenos: :emphasize-lines: 9-14,18 def my_obj_print(this) { k = this.keys for (i in 1:len(k)) { printf("%s = ", k[i]); print this[k[i]] } } def my_methods() { return [. print = "my_obj_print", __print__ = "my_obj_print"]; } def my_create() { this = [.]; set_method_table(this, "my"); return this; } o = my_create(); o.a = 1; o.b = 2; :: o print o o.print() .. us.history **History** .. list-table:: :header-rows: 1 * - Version - Description * - R2013.2 - Default parameter *bUpdate* modified (see above) and documentation modified. * - 4.1.1 - New. .. seealso:: :ref:`overview-uniscript-objects`, :ref:`obj_set_methods`, :ref:`obj_methods`, :ref:`obj_set_parent`, :ref:`obj_parent` :sub:`id-1586543`