manually defined Resource() function

This commit is contained in:
Guido van Rossum 1995-02-05 17:01:24 +00:00
parent 315592383e
commit 81920f1b75
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
resource_body = """
char *buf;
int len;
Handle h;
if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
return NULL;
h = NewHandle(len);
if ( h == NULL ) {
PyErr_NoMemory();
return NULL;
}
HLock(h);
memcpy(*h, buf, len);
HUnlock(h);
return (PyObject *)ResObj_New(h);
"""
f = ManualGenerator("Resource", resource_body)
f.docstring = lambda: """Convert a string to a resource object.
The created resource object is actually just a handle.
Apply AddResource() to write it to a resource file.
"""
functions.append(f)