// __setattr__: set an item in the maxscript globals hash table static int mxs_setattro( PyObject* self, PyObject* key, PyObject* value ) { //mprintf( _T("mxs_setattro entered\n") ); MXS_PROTECT( two_value_locals( name, result ) ); PyStringToMCHAR mkey(key); vl.name = Name::intern( mkey.mchar() ); // Step 3: get a preexisting global value vl.result = globals->get( vl.name ); if ( vl.result ) { // Step 4: try to set the global variable try { if ( is_thunk( vl.result ) ) ((Thunk*) vl.result)->assign( ObjectWrapper::intern(value) ); else globals->set( vl.name, ObjectWrapper::intern(value) ); } MXS_CATCHERRORS(); } // Step 5: cleanup the maxscript memory MXS_CLEANUP(); //mprintf( _T("mxs_setattro leaving\n") ); return 0; }
void write_dictionary_section(boost::property_tree::ptree& data, const std::string& key, const std::map<std::string, T>& values) { // Write out metadata std::string m_heading = key + "."; for(const auto& map_entry : values) { std::string mkey(m_heading); mkey += map_entry.first; data.put(mkey, map_entry.second); } }
// __getattr__: get an item from the maxscript globals hash table static PyObject* mxs_getattro( PyObject* self, PyObject* key ) { // Step 1: convert the key to a name //mprintf( _T("mxs_getattro entered\n") ); MXS_PROTECT(one_value_local(name)); PyStringToMCHAR mkey(key); vl.name = Name::intern( mkey.mchar() ); // Step 2: collect the PyObject* instance PyObject * output = ObjectWrapper::py_intern( globals->get( vl.name ) ); MXS_CLEANUP(); //mprintf( _T("mxs_getattro leaving\n") ); return output; }