set_method_table¶
set_method_table sets the methods (member functions) for the given object.
-
obj = set_method_table(obj, ssClass)
-
obj = set_method_table(obj, ssClass, bUpdate)
Return Value
obj is a pointer for the first parameter or 0, if an error occurred.
Parameters
-
obj
obj is the object created with obj_create.
-
ssClass
To set the method table, a function with the name ssClass + “_methods” will be invoked. This function must set the methods, see comment.
-
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 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.
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 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 _g) and the pointer will be saved with obj_set_methods
in the object o. With o.methods
(see obj_methods) the method
can be retrieved.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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()
History
Version | Description |
---|---|
R2013.2 | Default parameter bUpdate modified (see above) and documentation modified. |
4.1.1 | New. |
id-1586543