Mercurial > pytave
changeset 203:7d03df51d6e8
support simple callables
* @pyobj.m: improve subsref method
* @pyobj/dummy.m: doctests
author | Colin Macdonald <cbm@m.fsf.org> |
---|---|
date | Fri, 20 May 2016 10:21:04 -0700 |
parents | 3fa99babc7b5 |
children | 61df785bd8b0 |
files | @pyobj/dummy.m @pyobj/pyobj.m |
diffstat | 2 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/@pyobj/dummy.m Fri May 20 00:20:03 2016 -0700 +++ b/@pyobj/dummy.m Fri May 20 10:21:04 2016 -0700 @@ -42,6 +42,20 @@ %% @end group %% @end example %% +%% We can accesss ``callables'' (methods) of objects: +%% @example +%% @group +%% % x.keys() % FIXME: should be this but its broken +%% ddotkeys = pyobj(x.keys); +%% ddotkeys() +%% @result{} ans = +%% @{ +%% [1,1] = two +%% [1,2] = one +%% @} +%% @end group +%% @end example +%% %% @code{pyeval} should return a @@pyobj for things it cannot convert to %% Octave-native objects: %% @example @@ -75,6 +89,7 @@ %% @end group %% @end example %% +%% %% @seealso{pyobj} %% @end defmethod
--- a/@pyobj/pyobj.m Fri May 20 00:20:03 2016 -0700 +++ b/@pyobj/pyobj.m Fri May 20 10:21:04 2016 -0700 @@ -135,7 +135,11 @@ function r = subsref(x, idx) switch idx.type case '()' - error('not implemented: () indexing') + if ( ~strcmp (idx.subs, '')) + idx + error('not implemented: function calls with arguments') + end + r = pyeval (sprintf ('__InOct__["%s"]()', x.id)); case '.' assert(ischar(idx.subs)) r = pyeval (sprintf ('__InOct__["%s"].%s', x.id, idx.subs));