浏览代码

toString()

David Rose 16 年之前
父节点
当前提交
9a638bfd2a
共有 2 个文件被更改,包括 54 次插入1 次删除
  1. 48 0
      direct/src/plugin/p3dConcreteStruct.cxx
  2. 6 1
      direct/src/plugin/p3dConcreteStruct.h

+ 48 - 0
direct/src/plugin/p3dConcreteStruct.cxx

@@ -134,6 +134,54 @@ set_property(const string &property, P3D_object *value) {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: P3DConcreteStruct::has_method
+//       Access: Public, Virtual
+//  Description: Returns true if the named method exists on this
+//               object, false otherwise.
+////////////////////////////////////////////////////////////////////
+bool P3DConcreteStruct::
+has_method(const string &method_name) {
+  if (method_name == "toString") {
+    return true;
+  }
+
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: P3DConcreteStruct::call
+//       Access: Public, Virtual
+//  Description: Invokes the named method on the object, passing the
+//               indicated parameters.  If the method name is empty,
+//               invokes the object itself.
+//
+//               If needs_response is true, the return value is a
+//               new-reference P3D_object on success, or NULL on
+//               failure.  If needs_response is false, the return
+//               value is always NULL, and there is no way to
+//               determine success or failure.
+////////////////////////////////////////////////////////////////////
+P3D_object *P3DConcreteStruct::
+call(const string &method_name, bool needs_response,
+     P3D_object *params[], int num_params) {
+  P3D_object *result = NULL;
+
+  if (method_name == "toString") {
+    string value;
+    make_string(value);
+    result = P3D_new_string_object(value.data(), value.length());
+  }
+
+  if (result != NULL && !needs_response) {
+    P3D_OBJECT_DECREF(result);
+    result = NULL;
+  }
+
+  return result;
+}
+
+
 ////////////////////////////////////////////////////////////////////
 //     Function: P3DConcreteStruct::fill_xml
 //       Access: Public, Virtual

+ 6 - 1
direct/src/plugin/p3dConcreteStruct.h

@@ -25,7 +25,8 @@
 //               Python and Javascript, so it may be more optimal for
 //               relatively small objects.
 //
-//               Methods are not supported.
+//               Methods are not supported, other than built-in
+//               methods like toString().
 ////////////////////////////////////////////////////////////////////
 class P3DConcreteStruct : public P3DObject {
 public:
@@ -40,6 +41,10 @@ public:
   virtual P3D_object *get_property(const string &property);
   virtual bool set_property(const string &property, P3D_object *value);
 
+  virtual bool has_method(const string &method_name);
+  virtual P3D_object *call(const string &method_name, bool needs_response,
+                           P3D_object *params[], int num_params);
+
   virtual bool fill_xml(TiXmlElement *xvalue, P3DSession *session);
 
 private: