<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote"><pre>><i> Hi Roman,<br></i>><i> What do you mean by "the code generated by Py++ just works"? Do you mean
<br></i>><i> you created a class<br></i>><i> MyClass {<br></i>><i> public:<br></i>><i> MyClass(char const*) ;<br></i>><i> }<br></i>><i> and you had successfully initialized it in Python? I tried a similar
<br></i>><i> example class and had no problem with it.<br></i><br>That what you described :-).<br><br>><i> The real problem I had was with this specific class NiString in Gamebryo<br></i>><i> game engine, is it possible that something
<br></i>><i> going on inside Gamebryo might cause the problem? Or the game engine is<br></i>><i> irrelevant to this problem?<br></i><br>I think that NiString is relevant. Take a look on this FAQ:<br><a href="http://www.boost.org/libs/python/doc/v2/faq.html#custom_string">
http://www.boost.org/libs/python/doc/v2/faq.html#custom_string</a></pre></blockquote><div>Hi Roman, <br>Thanks for you suggestions. <br>I looked into the custom_string code, it is a nice example but different with my problem. I don't want python automatically convert my NiFixedString to python string, all I want is a way to use the constructor of NiFixedString class to create a python object.
<br> a = NiFixedString("test")<br><br>Theoretically this is no different than wrapping any other class with a constructor that takes a string/char const*, and this code should do it, right? <br>BOOST_PYTHON_MODULE(NiStringTest)
<br>{ <br> class_<NiFixedString,boost::noncopyable>("pNiFixedString", init<char const*>()); <br>}<br><br>Btw, NiFixedString encapsulates a memory efficient implementation of reference-counted
ASCII strings, here is the header file, is there any thing that potentially cause the exception? Also, from my understanding, PY++ simplifies the process of generating the wrapper code, could adopting PY++ possibly help with this problem?
<br><br>#ifndef NIFIXEDSTRINGTABLE_H<br>#define NIFIXEDSTRINGTABLE_H<br><br>#include "NiRTLib.h"<br>#include "NiGlobalStringTable.h"<br>#include "NiPath.h"<br><br>class NIMAIN_ENTRY NiFixedString : public NiMemObject
<br>{<br>public:<br> NiFixedString();<br> NiFixedString(const char* pcString);<br> NiFixedString(const NiFixedString& kString);<br> ~NiFixedString();<br><br> operator const char*() const;<br><br> bool Exists() const;
<br><br> NiFixedString& operator=(const NiFixedString& kString);<br> NiFixedString& operator=(const char* pcString);<br><br> size_t GetLength() const;<br> unsigned int GetRefCount() const;<br><br> bool Equals(const char* pcStr) const;
<br> bool EqualsNoCase(const char* pcStr) const;<br><br> bool Contains(const char* pcStr) const;<br> bool ContainsNoCase(const char* pcStr) const;<br><br> friend bool operator==(const NiFixedString& s1, const NiFixedString& s2);
<br> friend bool operator!=(const NiFixedString& s1, const NiFixedString& s2);<br> <br> friend bool operator==(const NiFixedString& s1, const char* s2);<br> friend bool operator!=(const NiFixedString& s1, const char* s2);
<br> <br> friend bool operator==(const char* s1, const NiFixedString& s2);<br> friend bool operator!=(const char* s1, const NiFixedString& s2);<br> <br> // Begin Emergent internal use only<br> // End Emergent internal use only
<br>protected:<br> NiGlobalStringTable::GlobalStringHandle m_kHandle;<br>};<br><br>NIMAIN_ENTRY void NiStandardizeFilePath(NiFixedString& kString);<br><br>#include "NiFixedString.inl"<br><br>#endif<br><br>
Excerpt from NifixedString.inl<br><br>inline NiFixedString::NiFixedString(const char* pcString)<br>{<br> if (pcString == NULL)<br> {<br> m_kHandle = NiGlobalStringTable::NULL_STRING;<br> }<br> else<br> {
<br> m_kHandle = NiGlobalStringTable::AddString(pcString);<br> }<br>}<br><br><br><br><br><br><br><br><br> <br> </div><br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
<pre>><i> And still, what the "unidentifiable C++ exception" is really saying?<br></i><br>Boost.Python has next code:<br><br>try{<br> run you C++ code<br>}<br>catch( registered exceptions ){<br> convert them to Python exception
<br>}<br>catch( ... ){<br> throw Python RuntimeError( "unidentifiable C++ exception" )<br>}<br><br>So or you forgot to register your exception or ... something really<br>bad happened.</pre></blockquote><div><br>
<br><br></div><br>