Python's standard-library FFI is ctypes — no pip install needed. The whole
binding is one short file.
Keep the callback objects alive. CFUNCTYPE(...) wrappers must not be
garbage-collected while the engine holds their pointers, so we store them in the
module-level _cb struct for the program's lifetime.
- Build
libdoomgeneric(seebindings/README.md). - Make it loadable and run:
It writes
# macOS DYLD_LIBRARY_PATH=/path/to/lib python3 doom.py -iwad /path/to/doom1.wad # Linux LD_LIBRARY_PATH=/path/to/lib python3 doom.py -iwad /path/to/doom1.wad
frame.ppmat frame 100.
lib.dg_screen_buffer()returns aPOINTER(c_uint32); index it like an array (buf[i], each0x00RRGGBB).- The per-pixel Python loop is fine for a demo; for real-time display use
numpy(np.ctypeslib.as_array) to copy the whole framebuffer at once. - Real input: return
1fromon_get_keyand write through the pointer args, e.g.pressed[0] = 1; key[0] = 0xa3(KEY_FIRE).