From 9a638bfd2a567f983ddd65097c923f8403a1a13a Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 22 Aug 2009 01:22:24 +0000 Subject: [PATCH] toString() --- direct/src/plugin/p3dConcreteStruct.cxx | 48 +++++++++++++++++++++++++ direct/src/plugin/p3dConcreteStruct.h | 7 +++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/direct/src/plugin/p3dConcreteStruct.cxx b/direct/src/plugin/p3dConcreteStruct.cxx index f686864d83..6e00447a87 100644 --- a/direct/src/plugin/p3dConcreteStruct.cxx +++ b/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 diff --git a/direct/src/plugin/p3dConcreteStruct.h b/direct/src/plugin/p3dConcreteStruct.h index 22060307ff..3f9fd7762b 100644 --- a/direct/src/plugin/p3dConcreteStruct.h +++ b/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: