151,152c151,152
< EmbeddedSwig::EmbeddedSwig(void (*init_func)())
< : initFunc(init_func)
---
> EmbeddedSwig::EmbeddedSwig(void (*init_func)(), const string& _context)
> : initFunc(init_func), context(_context)
167c167,168
< // initialize SWIG modules. initSwig() is autogenerated and calls
---
> char* old_context = _Py_PackageContext;
> // initialize SWIG modules. initFunc() is autogenerated and calls
169,172c170,182
< list<EmbeddedSwig *>::iterator i = getList().begin();
< list<EmbeddedSwig *>::iterator end = getList().end();
< for (; i != end; ++i)
< (*i)->initFunc();
---
> for (auto i : getList()) {
> // to ensure that the loaded modules are placed in the right
> // package we have to be a bit unorthodox and directly
> // manipulate the package context since swig simply calls
> // Py_InitModule with nothing but the module name of the
> // wrapper
> char* cstr = new char[i->context.size() + 1];
> strcpy(cstr, i->context.c_str());
> _Py_PackageContext = cstr;
> i->initFunc();
> delete[] cstr;
> }
> _Py_PackageContext = old_context;