00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc 00008 * 123 Front Street West, Suite 1401 00009 * Toronto, Ontario 00010 * Canada M5J 2M2 00011 * 416-504-9876 00012 * 00013 * COMMENTS: 00014 * This file contains functions to run python code. 00015 */ 00016 00017 #ifndef __PY_Python_h__ 00018 #define __PY_Python_h__ 00019 00020 #include "PY_API.h" 00021 #include "PY_Result.h" 00022 #include <UT/UT_String.h> 00023 class PY_EvaluationContext; 00024 00025 // Expressions cannot contain multiple statements (defs, classes, print 00026 // statements, etc.) and they cannot contain multiple expressions. 00027 PY_API PY_Result PYrunPythonExpression( 00028 const char *python_code, PY_Result::Type desired_result_type, 00029 PY_EvaluationContext *context = NULL); 00030 00031 // The result type from running statements in the current thread can 00032 // be none (indicating normal completion), error, or exit. 00033 PY_API PY_Result PYrunPythonStatements( 00034 const char *python_code, 00035 PY_EvaluationContext *context = NULL); 00036 PY_API PY_Result PYrunPythonStatementsFromFile( 00037 const char *filename, 00038 PY_EvaluationContext *context = NULL); 00039 00040 // This version of PYrunPythonStatementsFromFile will set Python's 00041 // sys.argv to the arguments you supply. argv[0] will be the name of the 00042 // Python file. 00043 PY_API PY_Result PYrunPythonStatementsFromFile( 00044 int argc, char *argv[], 00045 PY_EvaluationContext *context = NULL); 00046 PY_API PY_Result PYrunPythonStatements( 00047 const char *python_code, 00048 int argc, char *argv[], 00049 PY_EvaluationContext *context = NULL); 00050 00051 // A non-empty string is returned if there are parse errors, a new thread 00052 // could not be started, or the file could not be loaded. 00053 PY_API UT_String PYrunPythonStatementsInNewThread( 00054 const char *python_code); 00055 PY_API UT_String PYrunPythonStatementsFromFileInNewThread( 00056 const char *file_name); 00057 00058 // Return the python result containing a stack trace and exception information. 00059 // If no exception occurred, the result type is none. 00060 PY_API PY_Result PYextractPythonException(); 00061 00062 // Given a python object and a desired type, try to convert it to that type. 00063 // python_object should be a PyObject*, but it's a void* to avoid having to 00064 // include Python.h from here. 00065 // 00066 // There are two versions: a performance-sensitive version that takes the 00067 // return PY_Result object by reference, and a convenience version one that 00068 // returns it by value. 00069 PY_API PY_Result PYextractResultFromPythonObject( 00070 void *opaque_python_object, PY_Result::Type desired_result_type); 00071 PY_API void PYextractResultFromPythonObject( 00072 void *opaque_python_object, PY_Result::Type desired_result_type, 00073 PY_Result &result); 00074 00075 // We don't want to have to prefix things with "hou." in expressions. 00076 // So, we create a separate evaluation context for expressions where 00077 // "from hou import *" has been run. 00078 PY_API PY_EvaluationContext &PYgetPythonExpressionEvaluationContext(); 00079 00080 // Given a string containing the contents of a module and the module's name, 00081 // compile the string and import that as a module. If no exception occurred, 00082 // the result type is none. 00083 PY_API PY_Result PYimportModuleFromString( 00084 const char *module_name, const char *module_contents); 00085 00086 // Return a PyCodeObject * corresponding to the frame before the current eval 00087 // frame. 00088 PY_API void *PYgetCodeObjectForPrevFrame(); 00089 00090 // Return a PyCodeObject * corresponding to the specified PyObject 00091 PY_API void *PYgetCodeObjectForFunction(void *opaque_python_object); 00092 00093 // This function controls whether running Python code automatically sets the 00094 // HOM_Module implementation (by importing the hou Python module). Call 00095 // PYsetAutoInitializeFromPython to false if you don't hou to be imported 00096 // automatically; otherwise, it will. You must call this static method 00097 // before running any Python code. Once any Python code is run, this 00098 // setting has no effect. 00099 PY_API void PYsetAutoInitializeFromPython(bool auto_initialize); 00100 00101 // This function is used by PY_InterpreterAutoLock to determine if 00102 // it should automatically import the hou module 00103 PY_API bool PYautoInitializeFromPython(); 00104 00105 #endif
1.5.9