Native Objects

The objects produced by native modules are not restricted to m types. For instance, the streams returned by io.open are native objects which cannot be manipulated from within m, only by module io and a few other modules.

But native objects are not restricted to streams: an instance of any subclass of CBase can be wrapped into a native object. When doing so, the instance will automatically be deleted if the native object containing it is freed by garbage collection.

Each native object has a type which is a zero terminated character string. The type is used to check for a particular object type (C++ runtime types are not supported by Symbian), and when converting the object to a string, e.g. when printing it to the console. For instance, native streams have the type

/**
   The type of all native I/O streams.
*/
static const char * const TYPE = "stream";

Native objects are created by the following function from class Runtime:

To access native objects, Runtime::Value offers the following methods: And here is a sample fragment using native objects:

class MyObject : public CBase {
public:
  static const char * const TYPE = "myobject";
  static MyObject *NewL();
  ...
  TInt count() const;
}

Runtime::Value ExecuteL(TInt index, Runtime::Value *params,
                        TInt paramCount, TRequestStatus &status)
{
  MyObject *obj;
  Runtime::Value result;
  switch (index) {
  case NewFunction: 
    // create a native object around a MyObject instance
    obj = MyObject::NewL();
   &nbs