getFunction method
Gets a function from the module
Implementation
DartPyFunction getFunction(String name) {
if (_functions.containsKey(name)) {
return _functions[name]!;
}
final funcName = name.toNativeUtf8();
final pFunc =
dartpyc.PyObject_GetAttrString(_moduleRef, funcName.cast<Char>());
malloc.free(funcName);
if (pFunc != nullptr) {
if (pFunc.isCallable) {
_functions[name] = DartPyFunction(pFunc);
return _functions[name]!;
} else {
dartpyc.Py_DecRef(pFunc);
throw DartPyException('$name is not callable');
}
} else {
throw DartPyException('Function $name not found in module $moduleName');
}
}