Server Help

ASSS Questions - LinkedLists with Python

Initrd.gz - Wed Mar 18, 2009 10:38 pm
Post subject: LinkedLists with Python
Hello, again.

I am making a structure that requires use of LinkedLists, however, the main code that uses it is written with python, so I am using pytype. How compatible is LinkedLists with python? Can I use it like a list in python, or do I have to change something?

Thanks.
D1st0rt - Wed Mar 18, 2009 10:42 pm
Post subject:
Heh funny you should ask as one of my ongoing, longer term projects is coming up with a good way to translate arbitrary LinkedLists back and forth from Python. Right now I have lists of just players going back and forth, but it would be considerably more involved to get any list to work, especially from the C side. What specifically are you trying to do?
Initrd.gz - Wed Mar 18, 2009 10:49 pm
Post subject:
Store an arbitrary number of numbers/structures that represent prizes and override keys, as well as pointers. (All in separate linked lists.)

I have a python class that is the equivalent of the structure. Any way I can use that?
D1st0rt - Wed Mar 18, 2009 11:07 pm
Post subject:
Not easily. If you just want to have pointers, essentially a list of opaque types that is probably the quickest thing one could crank out, but for each new structure you wanted to use you would need to have custom conversion functions both ways, and you'd probably have to define a new python class using the C-API. Like I said, its an ongoing project.
Initrd.gz - Wed Mar 18, 2009 11:18 pm
Post subject:
I suppose I could write a couple of C wrappers around LL* and functions to get a value out of a linked list. Not exactly converting from LL to list, but it should work. Except maybe for the type... I could make it a single type linked list and have a small header struct defining the type of data... Hmm...
D1st0rt - Tue Mar 24, 2009 4:40 pm
Post subject:
Unfortunately I think the only way this would work right now is if you exposed some sort of AddElement function in your c interface and then called that while iterating through your python lists, or something along those lines. I'm still thinking about ways to implement generic list translations, if you have any ideas.
Initrd.gz - Tue Mar 24, 2009 6:06 pm
Post subject:
D1st0rt wrote:
Unfortunately I think the only way this would work right now is if you exposed some sort of AddElement function in your c interface and then called that while iterating through your python lists, or something along those lines. I'm still thinking about ways to implement generic list translations, if you have any ideas.

Yeah, that's what I was thinking.

I am not familiar with the python C interface, but I could learn and help you out icon_smile.gif . Pretty much the only thing I know about ATM it is that most of the stuff is stored in PyObject.
Initrd.gz - Mon Apr 06, 2009 6:12 pm
Post subject:
Well, another solution.

1. Is there any way to return a pointer to a python object from a python function?
2. Is it possible to typedef a void pointer to use as this and force the pointer returned into a cast?

Really, I just want to return something unique to a certain object in a Python set, so I can just create a GetObjectByName(name) function and iterates through the set, returning the pointer, and extract the values of it with python functions. I guess I could do something with random numbers, but pointers seem more consistent and practical.
D1st0rt - Tue Apr 07, 2009 4:00 pm
Post subject:
I'm not really sure what you're trying to do, there's some ambiguity as to what you want to accomplish in which language. That being said I think I came up with a good way to implement list translation it's just taking longer than I expected to wrap my head around the part of pymod-process that is necessary to get it done.
Initrd.gz - Tue Apr 07, 2009 5:08 pm
Post subject:
D1st0rt wrote:
I'm not really sure what you're trying to do, there's some ambiguity as to what you want to accomplish in which language. That being said I think I came up with a good way to implement list translation it's just taking longer than I expected to wrap my head around the part of pymod-process that is necessary to get it done.

Well, if I can help in any way, I will.

As for my module, it is composed like this, sort of:
Code: Show/Hide
itemslist = set()
class item(object):
    id = -1 # SQL use
    name = ""
    ...
    prizes = {}
    overrides = {}
    attributes = {}

def AddItem(item):
    set.add(item)

def GetItemByName(name):
    for i in itemslist:
        if i.name == name:
            return None # <-- Placeholder
I wanted something unique to each item in the set GetItemByName returns. A pointer would be nice. The id wouldn't be because I plan on adding an in-game ?additem command, which tags the id as -1. I was thinking about using random numbers, but that doesn't seem like the best solution.

Anyhoo, I think your method will work the best. Can't wait to download it when its done (hence why I want to help icon_lol.gif )

PS. Firefox makes for a bad code editor.
D1st0rt - Tue Apr 07, 2009 6:05 pm
Post subject:
I appreciate the offer, but I'm not sure if there's anything that can be delegated right now.

You may want to look into ctypes for the time being.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group