PropertyIterator(IComponentContext& context, const PyScript::ScriptObject& pythonObject,
	                 const PyScript::ScriptDict& metaDataDict)
	    : context_(context), object_(pythonObject), metaDataDict_(metaDataDict)
	{
		if (object_.get() == nullptr)
		{
			return;
		}

		// Get a list of strings appropriate for object arguments
		PyScript::ScriptObject dir = object_.getDir(PyScript::ScriptErrorPrint());
		if (dir.get() != nullptr)
		{
			iterator_ = dir.getIter(PyScript::ScriptErrorPrint());
		}
	}
Beispiel #2
0
std::string DefinitionDetails::generateName( const PyScript::ScriptObject & object )
{
	PyScript::ScriptErrorPrint errorHandler;
	std::string typeName;

	if (PyScript::ScriptType::check( object ))
	{
		// Type type
		// type.__module__ + type.__name__ + id( object )
		PyScript::ScriptType scriptType(
			reinterpret_cast<PyTypeObject*>( object.get() ), PyScript::ScriptObject::FROM_BORROWED_REFERENCE );

		scriptType.getAttribute( "__module__", typeName, errorHandler );
		typeName += '.';
		typeName += scriptType.name();
	}
	else
	{
		// Class or None type
		// __module__ + __name__ + id( object )
		typeName = object.str( errorHandler ).c_str();
	}

	// Add an address in case there are multiple classes/types with the same
	// name in the same file.
	// E.g.
	// # module "Test"
	// class A( object ):
	//     class InnerClass( object ):
	//         pass
	//     pass
	// class B( object ):
	//     class InnerClass( object ): # different type with the name "Test.InnerClass"
	//         pass
	//     pass
	typeName += " at ";
	typeName += std::to_string( object.id().asUnsignedLongLong(
		PyScript::ScriptErrorRetain() ) );

	// Check for overflow
	assert( !PyScript::Script::hasError() );
#if defined( _DEBUG )
	PyScript::Script::clearError();
#endif // defined( _DEBUG )

	return typeName;
}