⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pythoninterpreter.cpp

📁 "More for C++" is a class library that provides some features that are usually common for object ori
💻 CPP
字号:
////  This file is part of the "More for C++" library////  Copyright (c) 1999-2003 by Thorsten Goertz (thorsten@morefor.org)////  The "More for C++" library is free software; you can redistribute it and/or//  modify it under the terms of the license that comes with this package.////  Read "license.txt" for more details.////  THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED//  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES//  OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.////////////////////////////////////////////////////////////////////////////////#include <more/create.hpp>#include <more/script/pythoninterpreter.hpp>#include <python.hpp>#include "pythoninterpreterimpl.hpp"using namespace more;using namespace more::script;////////////////////////////////////////////////////////////////////////////////void PythonInterpreter::registerNativeModule(  const String& sModule,  PyMethodDef*  pMethodDefs){  PythonInterpreterImpl::registerNativeModule( sModule, pMethodDefs );}////////////////////////////////////////////////////////////////////////////////void PythonInterpreter::registerExtensionType(  const String& sModule,  PyTypeObject* pTypeObject){  PythonInterpreterImpl::registerExtensionType( sModule, pTypeObject );}////////////////////////////////////////////////////////////////////////////////PythonInterpreter::~PythonInterpreter( ){}////////////////////////////////////////////////////////////////////////////////PythonGuard::PythonGuard( ){  PyInterpreterState* pInterpreterState;  PyEval_AcquireLock( );  pInterpreterState = PythonInterpreterFactory::pMainThreadState -> interp;  m_pThreadState = PyThreadState_New( pInterpreterState );  PyThreadState_Swap( m_pThreadState );}////////////////////////////////////////////////////////////////////////////////PythonGuard::~PythonGuard( ){  PyThreadState_Swap( 0 );  PyThreadState_Delete( m_pThreadState );  PyEval_ReleaseLock( );}////////////////////////////////////////////////////////////////////////////////void PythonException::throwNativeException( ){  throw NativePythonException( );}////////////////////////////////////////////////////////////////////////////////PyObject* PythonObject::from( bool b ){  return PyInt_FromLong( b? 1 : 0 );}////////////////////////////////////////////////////////////////////////////////PyObject* PythonObject::from( char c ){  return PyString_FromStringAndSize( &c, 1 );}////////////////////////////////////////////////////////////////////////////////PyObject* PythonObject::from( unsigned char byte ){  return PyBuffer_FromMemory( ( void* ) &byte, 1 );}////////////////////////////////////////////////////////////////////////////////PyObject* PythonObject::from( short nShort ){  return PyInt_FromLong( nShort );}////////////////////////////////////////////////////////////////////////////////PyObject* PythonObject::from( unsigned short nUnsignedShort ){  return PyInt_FromLong( nUnsignedShort );}////////////////////////////////////////////////////////////////////////////////PyObject* PythonObject::from( int nInt ){  return PyInt_FromLong( nInt );}////////////////////////////////////////////////////////////////////////////////PyObject* PythonObject::from( unsigned int nUnsignedInt ){  return PyInt_FromLong( ( long ) nUnsignedInt );}////////////////////////////////////////////////////////////////////////////////PyObject* PythonObject::from( long nLong ){  return PyLong_FromLong( nLong );}////////////////////////////////////////////////////////////////////////////////PyObject* PythonObject::from( unsigned long nUnsignedLong ){  return PyLong_FromLong( ( long ) nUnsignedLong );}////////////////////////////////////////////////////////////////////////////////PyObject* PythonObject::from( const String& sString ){  return PyString_FromStringAndSize( sString, sString.getLength( ) );}////////////////////////////////////////////////////////////////////////////////void PythonObject::del( PyObject* pPyObject ){  Py_XDECREF( pPyObject );}////////////////////////////////////////////////////////////////////////////////PythonException::PythonException(  const String& sDescription): m_sDescription( sDescription ){}////////////////////////////////////////////////////////////////////////////////PythonException::operator const char* ( ) const{  return m_sDescription;}////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -