First post woo!
Let me start by pointing out that beyond very simple examples, I’m jumping off the deep end with C. I have some C# & Swift experience prior (also consider myself ~master but shy of Doctorate in pure Python) which has all helped me pick up on this pretty quickly, and I’ve already ported several functions (surprised myself with how fast I picked it up even). However, I’m stuck on this one issue pretty hard and not quite sure even how to google it (obviously have tried).
My module/extension needs some global dictionaries avaliable both in the module, and in Python.
To be very specific, from https://bitbucket.org/experimentfailed/testcraft/src/working/world.py, I’m trying to express lines 36, 40, 44, and 47 via the CPython API. However, just putting e.g.:
PyObject* worldBlocks = PyDict_New();
in the global scope of my C does not work. The compiler throws:
world_test.c:17:25: error: initializer element is not constant
If I put the same code in a function that returns void, I get the same error. If I put it in a function that returns PyObject, then it works. This behavior baffles me, probably due to my awkward language background and overall lack of knowledge in C. Actually, I more or less understand why the above doesn’t work in C global scope, but not quite sure about why it doesn’t in a generic void function (discovered that on accident)… Anyway, still not sure how to get the dicts I need into the this mystical global land that certainly has to exist…
I’m lost on this one, which feels weird with how far I’ve come. I ported my terrain generator (https://bitbucket.org/experimentfailed/testcraft/src/working/terrain_gen/) with relative ease!
Thanks for reading and for any insight!