Author |
Message |
Hawkaloogie Newbie
Joined: Jan 11 2003 Posts: 13 Offline
|
Posted: Fri Dec 26, 2008 4:44 am Post subject: obj->ToggleSet in Python |
 |
|
|
|
Would it be possible to make obj->ToggleSet work through the Python interface? I've got 50+ objects to toggle at once, and doing them individually makes it look slow (cool, kinda, but slow).
If I want ToggleSet, do I need to learn C? |
|
Back to top |
|
 |
Hakaku Server Help Squatter

Joined: Apr 07 2006 Posts: 299 Location: Canada Offline
|
Posted: Fri Dec 26, 2008 7:17 pm Post subject: |
 |
|
|
|
From what I can tell, object->ToggleSet is only available in C, though you could just use object->Toggle for each individual object. It's not as efficient, but I don't see there being a hugely noticeable delay if you did so (but I haven't tried, so I can't say). |
|
Back to top |
|
 |
tcsoccerman Server Help Squatter
Age:33 Gender: Joined: Jan 15 2007 Posts: 694 Location: Atlantis Offline
|
Posted: Fri Dec 26, 2008 10:04 pm Post subject: |
 |
|
|
|
he said there was, which is why he specifically wanted to use ToggleSet() |
|
Back to top |
|
 |
Hawkaloogie Newbie
Joined: Jan 11 2003 Posts: 13 Offline
|
Posted: Sat Dec 27, 2008 12:13 am Post subject: |
 |
|
|
|
Yeah, that's why I asked if it would be possible to make ToggleSet work. I've been trying to figure out the magic that is the pymod interface with little luck (having just started with Python a couple days ago, and my C knowledge being completely academic).
It seems that if I could translate the Python lists into the required C data structures, that it would work.
Is whatever I just mumbled about even possible? Is there documentation available somewhere for this type of thing?
I'll start checking the Google.
EDIT: Swig seems interesting... |
|
Back to top |
|
 |
Grelminar Creator of Asss
Joined: Feb 26 2003 Posts: 378 Offline
|
Posted: Sat Dec 27, 2008 5:30 am Post subject: |
 |
|
|
|
pymod is really confusing, even to me. Whenever I want to change something I have to spend an hour re-learning how it all works. Swig is also really confusing, though, so it's not clear that it would have been a net win if I had used that instead of basically reimplementing the parts that I needed.
You should be able to make toggleset work by adding support for lists of integers to pymod. You'd want to make a new type in pymod-process.py (see the other class type_...'s) and write conversion functions in pymod.c (cvt_c2p/p2c_...). Actually you only need p2c in this case. It shouldn't be too hard to make it work, the hard part is making it work without leaking memory on every call
It's probably easiest to use a fixed-size buffer and enforce a maximum size, because then you can allocate it on the stack and don't have to worry about freeing it. I think. Good luck. |
|
Back to top |
|
 |
Hawkaloogie Newbie
Joined: Jan 11 2003 Posts: 13 Offline
|
Posted: Sat Dec 27, 2008 5:46 am Post subject: |
 |
|
|
|
Thanks, I'll try that and report on my findings.
In the future, I might try something more ambitious with SWIG. The benefits with SWIG seem incredible: Automatic handling of array pointers (which means ToggleSet would work out-of-the-box), completely generated from .h files, interface translation for objects done inside the SWIG interface file (cleaner code), and the ability to translate to a whole host of languages. I've got a SWIG interface to objects.c compiling, but it seems that it needs to use shared objects instead of compiling everything into the binary. Since I have absolutely no idea how to change the Makefile to do that, I'm stuck for now.
That being said, are there any references anyone can suggest for GNU Make and/or the rest of the GNU build tools? |
|
Back to top |
|
 |
Grelminar Creator of Asss
Joined: Feb 26 2003 Posts: 378 Offline
|
Posted: Sun Dec 28, 2008 3:37 am Post subject: |
 |
|
|
|
If you can make a natural-feeling interface using swig, go for it. I've written some swig typemaps myself, and I know it's really powerful, but it's also hard to use and confusing to debug when it doesn't work. Specifically, it doesn't know anything about asss' interface and callback systems, so to make those come out naturally, you'll have to write a bunch of helper code, similar to what's in pymod.c now.
For make, you might be able to find an introduction to the concept of a makefile (i.e. a directed graph of files with actions) somewhere, but the best reference is probably the gnu make manual itself, even though it's a little dry. asss does use several gnu-specific features.
There's nothing about swig that requires shared objects. It just generates a .c file that you can compile and link however you want. You will need to integrate it into the makefile though, however you link it, so you should learn how to do that. |
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
Posted: Tue Dec 30, 2008 8:37 pm Post subject: |
 |
|
|
|
In working on exposing some of the Hyperspace stuff to python, I actually started on hand coding some translation functions for the util LinkedList a while back. It took me several days of poring back and forth between pymod, pymod_process, and the Py/C API docs to even figure out what needed to be done, so I back burnered it while focusing on more immediate concerns. I'm actually pretty excited about this thread because I thought I was the only person who was doing any serious work with pymod.
The other day I found Cython which looks to be much easier to use than SWIG but haven't taken it for a spin yet. _________________
 |
|
Back to top |
|
 |
|