51 lines
1.5 KiB
Plaintext
51 lines
1.5 KiB
Plaintext
From: a.eyre at optichrome.com (Adrian Eyre)
|
|
Date: Tue, 6 Apr 1999 13:04:38 GMT
|
|
Subject: Calling __builtins__ from C API
|
|
In-Reply-To: <Pine.BSF.4.02A.9903250145250.15122-100000@psycrow.raznick.com>
|
|
References: <Pine.BSF.4.02A.9903250145250.15122-100000@psycrow.raznick.com>
|
|
Message-ID: <000a01be802e$0798d4e0$2bcbd9c2@optichrome.com>
|
|
Content-Length: 1164
|
|
X-UID: 1197
|
|
|
|
> However, I can't figure out the proper way to refer to this
|
|
> instance from the C API. While I can use the PyRun_SimpleString
|
|
> function to refer the instance, this seems like a hack.
|
|
|
|
Try:
|
|
|
|
#include <Python.h>
|
|
void main()
|
|
{
|
|
Py_Initialize();
|
|
PyObject* builtinsMod = PyImport_ImportModule("__builtin__");
|
|
PyObject* builtinsDict = PyModule_GetDict(builtinsMod);
|
|
PyObject* someString = PyString_FromString("someValue");
|
|
PyDict_SetItemString(builtinsDict, "someName", someString);
|
|
Py_DECREF(builtinsMod);
|
|
Py_DECREF(builtinsDict);
|
|
Py_DECREF(someString);
|
|
Py_Finalize();
|
|
}
|
|
|
|
|
|
|
|
> What are the disadvantages of using this over the more cumbersome,
|
|
> PyObject_GetAttrString(), Py_BuildValue(), PyEval_CallObject(), etc.?
|
|
> How do you refer to a built-in function or object?
|
|
|
|
AFAIK, the only difference is that with PyRun_String(), it has to run
|
|
throught the parser first.
|
|
|
|
--------------------------------------------
|
|
Adrian Eyre <mailto:a.eyre at optichrome.com>
|
|
Optichrome Computer Solutions Ltd
|
|
Maybury Road, Woking, Surrey, GU21 5HX, UK
|
|
Tel: +44 1483 740 233 Fax: +44 1483 760 644
|
|
http://www.optichrome.com
|
|
--------------------------------------------
|
|
|
|
|
|
|
|
|
|
|