Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
LinkedLists with Python

 
Post new topic   Reply to topic Printable version
 View previous topic  Does the ASSS site have a mirror? Post :: Post Damage and bot1d  View next topic  
Author Message
Initrd.gz
Seasoned Helper


Joined: Sep 18 2008
Posts: 134
Location: Over there --->
Offline

PostPosted: Wed Mar 18, 2009 10:38 pm    Post subject: LinkedLists with Python Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List AIM Address
D1st0rt
Miss Directed Wannabe


Age:36
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Wed Mar 18, 2009 10:42 pm    Post subject: Reply to topic Reply with quote

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?
_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Initrd.gz
Seasoned Helper


Joined: Sep 18 2008
Posts: 134
Location: Over there --->
Offline

PostPosted: Wed Mar 18, 2009 10:49 pm    Post subject: Reply to topic Reply with quote

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?
Back to top
View users profile Send private message Add User to Ignore List AIM Address
D1st0rt
Miss Directed Wannabe


Age:36
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Wed Mar 18, 2009 11:07 pm    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Initrd.gz
Seasoned Helper


Joined: Sep 18 2008
Posts: 134
Location: Over there --->
Offline

PostPosted: Wed Mar 18, 2009 11:18 pm    Post subject: Reply to topic Reply with quote

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...
Back to top
View users profile Send private message Add User to Ignore List AIM Address
D1st0rt
Miss Directed Wannabe


Age:36
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Tue Mar 24, 2009 4:40 pm    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Initrd.gz
Seasoned Helper


Joined: Sep 18 2008
Posts: 134
Location: Over there --->
Offline

PostPosted: Tue Mar 24, 2009 6:06 pm    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Initrd.gz
Seasoned Helper


Joined: Sep 18 2008
Posts: 134
Location: Over there --->
Offline

PostPosted: Mon Apr 06, 2009 6:12 pm    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List AIM Address
D1st0rt
Miss Directed Wannabe


Age:36
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Tue Apr 07, 2009 4:00 pm    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Initrd.gz
Seasoned Helper


Joined: Sep 18 2008
Posts: 134
Location: Over there --->
Offline

PostPosted: Tue Apr 07, 2009 5:08 pm    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List AIM Address
D1st0rt
Miss Directed Wannabe


Age:36
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Tue Apr 07, 2009 6:05 pm    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 640 page(s) served in previous 5 minutes.

phpBB Created this page in 0.525431 seconds : 36 queries executed (80.8%): GZIP compression disabled