octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

octave.object(support) (Modified by Paul Kienzle)


From: Paul Kienzle
Subject: octave.object(support) (Modified by Paul Kienzle)
Date: Thu, 15 Jan 2004 15:02:42 -0500

Hello,

I've been playing with a new type that allows you to define
objects and methods implemented in oct-files, but callable
directly from scripts using the usual object.method(args)
syntax.

It works reasonably well without any change to octave
sources.  The following operations work:

# Can create a new type, and query its properties
  x = vtkitem(1)
  [a,b] = x.query(1,2)

# The object inside is persistent
  x.set(2);
  x

# It can be assigned
  t = vtkitem(3)
  u = t
  s.x = t
  c = { t }


# The destructor is called in the appropriate places
  clear x            # when cleared
  vtkitem(4)         # not when it is ans
  clear ans
  vtkitem(5).set(6)  # but when it is an intermediate
  function f, t = vtkitem(4), end
  f                  # when a function returns
  clear x u t        # not cleared: still a copy in c{1}
  c{1} = 1;          # cleared: last copy is gone
  c = { vtkitem(7) };
  clear c            # goes away with the cell array
  s.x = vtkitem(8);
  clear s            # cleared when struct is destroyed
  s.x = vtkitem(9);
  s.x = 1;           # and when field is replaced

  # Hmmm... 'clear s.x c{2:4} d[2,:]' is nice syntax.
  # Can't do it though without making clear a keyword.

  # You can see the available methods
  x = vtkitem(9);
  methods(x)

There are still some issues though.  The following
operations do not work:

# The following does not call the subsasgn method:
  x = vtkitem(10);
  x.query = 1;

# The following do not call subsref with nargout=2:
  c = { vtkitem(11) }
  [a,b] = c{1}.query
  [a,b] = vtkitem(12).query
  c.x = vtkitem(13)
  [a,b] = c.x.query

# The following do not call the destructor for vtkitem
  function f, static t=vtkitem(14); end
  f
  clear f  # persistent variables not deleted?

  x = vtkitem(15);
  exit     # toplevel symbol table not deleted?

  global x = vtkitem(16);
  exit     # global symbol table not deleted?

There is no support for operator overloading, and
since the interface code for multiple different classes
will share the same class id, my dispatch hack won't
allow function overloading either.

The code is attached.

Paul Kienzle
address@hidden

Attachment: vtkitem.cc
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]