Extending via C++, adding a module throws exception
Posted: Thu Oct 30, 2014 1:39 am
Hello,
I'm trying to extend SP with a C++ addon. The following exception is thrown:
I really don't know why this happens. In my opinion, I followed everything described on https://docs.python.org/3/extending/embedding.html#extending-embedded-python
The module is definitely loaded. When I don't load my C++ stuff, the normal 'no module named blah' error appears.
The necessary code is:
I'm thankful for help.
I'm trying to extend SP with a C++ addon. The following exception is thrown:
Code: Select all
sp load pbtest
[SP] Loading plugin 'pbtest'...
[SP] Caught an Exception:
Traceback (most recent call last):
File '..\addons\source-python\packages\source-python\plugins\manager.py', line 72, in __missing__
instance = self.instance(plugin_name, self.base_import)
File '..\addons\source-python\packages\source-python\plugins\instance.py', line 82, in __init__
self._plugin = import_module(import_name)
File '..\addons\source-python\plugins\pbtest\pbtest.py', line 1, in <module>
from pawnbridge import numargs
ImportError: 'pawnbridge' is not a built-in module
I really don't know why this happens. In my opinion, I followed everything described on https://docs.python.org/3/extending/embedding.html#extending-embedded-python
The module is definitely loaded. When I don't load my C++ stuff, the normal 'no module named blah' error appears.
The necessary code is:
Code: Select all
static int numargs = 0;
static PyObject* emb_numargs(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":numargs"))
return NULL;
return PyLong_FromLong(numargs);
}
static PyMethodDef PawnBridgeMethods[] = {
{ "numargs", emb_numargs, METH_VARARGS,
"Return the number of arguments received by the process." },
{ NULL, NULL, 0, NULL }
};
static PyModuleDef PawnBridgeModule = {
PyModuleDef_HEAD_INIT, "pawnbridge", NULL, -1, PawnBridgeMethods,
NULL, NULL, NULL, NULL
};
static PyObject* PyInit_emb(void)
{
return PyModule_Create(&PawnBridgeModule);
}
bool PawnBridge::SDK_OnLoad(char *error, size_t maxlength, bool late)
{
numargs = 42;
PyImport_AppendInittab("pawnbridge", &PyInit_emb);
Py_Initialize();
return true;
}
I'm thankful for help.