Py_CompileString() private méthode

private Py_CompileString ( string code, string file, IntPtr tok ) : IntPtr
code string
file string
tok IntPtr
Résultat IntPtr
Exemple #1
0
        public static PyObject Compile(string code, string filename = "", RunFlagType mode = RunFlagType.File)
        {
            var    flag = (int)mode;
            IntPtr ptr  = Runtime.Py_CompileString(code, filename, flag);

            PythonException.ThrowIfIsNull(ptr);
            return(new PyObject(ptr));
        }
Exemple #2
0
        public static PyObject Compile(string code, string filename = "", RunFlagType mode = RunFlagType.File)
        {
            var    flag = (IntPtr)mode;
            IntPtr ptr  = Runtime.Py_CompileString(code, filename, flag);

            Runtime.CheckExceptionOccurred();
            return(new PyObject(ptr));
        }
Exemple #3
0
        public static PyModule FromString(string name, string code)
        {
            using NewReference c = Runtime.Py_CompileString(code, "none", (int)RunFlagType.File);
            PythonException.ThrowIfIsNull(c);
            NewReference m = Runtime.PyImport_ExecCodeModule(name, c);

            PythonException.ThrowIfIsNull(m);
            return(new PyModule(ref m));
        }
Exemple #4
0
        /// <summary>
        /// ModuleFromString Method
        /// </summary>
        /// <remarks>
        /// Given a string module name and a string containing Python code,
        /// execute the code in and return a module of the given name.
        /// </remarks>
        public static PyObject ModuleFromString(string name, string code)
        {
            IntPtr c = Runtime.Py_CompileString(code, "none", (int)RunFlagType.File);

            PythonException.ThrowIfIsNull(c);
            IntPtr m = Runtime.PyImport_ExecCodeModule(name, c);

            PythonException.ThrowIfIsNull(m);
            return(new PyObject(m));
        }
Exemple #5
0
        /// <summary>
        /// ModuleFromString Method
        /// </summary>
        /// <remarks>
        /// Given a string module name and a string containing Python code,
        /// execute the code in and return a module of the given name.
        /// </remarks>
        public static PyObject ModuleFromString(string name, string code)
        {
            IntPtr c = Runtime.Py_CompileString(code, "none", (IntPtr)257);

            Runtime.CheckExceptionOccurred();
            IntPtr m = Runtime.PyImport_ExecCodeModule(name, c);

            Runtime.CheckExceptionOccurred();
            return(new PyObject(m));
        }
Exemple #6
0
        /// <summary>
        /// ModuleFromString Method
        /// </summary>
        ///
        /// <remarks>
        /// Given a string module name and a string containing Python code,
        /// execute the code in and return a module of the given name.
        /// </remarks>

        public static PyObject ModuleFromString(string name, string code)
        {
            IntPtr c = Runtime.Py_CompileString(code, "none", (IntPtr)257);

            if (c == IntPtr.Zero)
            {
                throw new PythonException();
            }
            IntPtr m = Runtime.PyImport_ExecCodeModule(name, c);

            if (m == IntPtr.Zero)
            {
                throw new PythonException();
            }
            return(new PyObject(m));
        }
        /// <summary>
        /// ModuleFromString Method
        /// </summary>
        /// <remarks>
        /// Given a string module name and a string containing Python code,
        /// execute the code in and return a module of the given name.
        /// </remarks>
        public static PyObject ModuleFromString(string name, string code)
        {
            IntPtr c = Runtime.Py_CompileString(code, "none", (IntPtr)257);

            Runtime.CheckExceptionOccurred();
            IntPtr m = Runtime.PyImport_ExecCodeModule(name, c);

            Runtime.CheckExceptionOccurred();
            PyObject res = new PyObject(m);

            if (!objs.ContainsKey(name))
            {
                objs.TryAdd(name, res);
            }
            return(res);
        }
        public static PyObject CompileToModule(string name, string code, string filename = "", RunFlagType mode = RunFlagType.File)
        {
            var    flag = (IntPtr)mode;
            IntPtr ptr  = Runtime.Py_CompileString(code, filename, flag);

            Runtime.CheckExceptionOccurred();

            IntPtr m = Runtime.PyImport_ExecCodeModule(name, ptr);

            Runtime.CheckExceptionOccurred();
            PyObject res = new PyObject(m);

            if (!objs.ContainsKey(name))
            {
                objs.TryAdd(name, res);
            }
            return(res);
        }