Server Help

ASSS Questions - Python Interfaces

Initrd.gz - Wed Mar 11, 2009 9:43 pm
Post subject: Python Interfaces
Hello all. I have another (probably newbie-ish) question.

I am making a python module, but I want a C interface to it. I am looking at D1st0rt's Optparser module, and that is helping out a lot. I was wondering if there was anything else I should know, because the ioptparser module doesn't really use ASSS as opposed to the optparser library/builtins that much. Also, I was wondering what this meant on the top of most includes:
Code: Show/Hide
/* dist: public */


Another question, but I don't think it is possible. Could you make a person "shoot" L5 bullets (burst rounds) the same way HS does it?

Thanks for your time.[/code]
Cheese - Thu Mar 12, 2009 2:30 am
Post subject:
lv5 doesnt exist, but lv4s, the purple ones, do...
Dr Brain - Thu Mar 12, 2009 6:53 am
Post subject:
The /* dist: public */ is used by an automated packaging script to pick out the files that need to be included with asss when it gets shipped out.
Initrd.gz - Thu Mar 12, 2009 6:55 pm
Post subject:
Thanks.

Another question: what is the difference between pyint: use and pyint: impl in the interface?
D1st0rt - Fri Mar 13, 2009 11:10 am
Post subject:
Use is for an interface you want to be able to use from python, impl is for an interface you want to be able to implement in python. You can also specify both with pyint: use, impl
Initrd.gz - Sat Mar 14, 2009 4:00 pm
Post subject:
Oh, so If I use impl, I can write python code for the interface?

Thanks a lot. This is probably the last question. How do I use pytype?
D1st0rt - Mon Mar 16, 2009 2:01 pm
Post subject:
There are a couple of different ways you can use pytype. It follows the general pattern of pytype: <mode>, <what it is in c>, <what you are going to call it in pyint declarations>

If you just want to be able to hold onto an arbitrary pointer to the object, you use opaque. name2 is what you will use in future pyint declarations:
Code: Show/Hide
/* pytype: opaque, typename *, name2 */
This won't have any functions you can call, and you wont be able to access any of the members, it's just for when you need to pass it back to a c module.

If you define a struct that contains only members pymod knows how to process (int, Player *, Arena *, etc) you can use that struct in python as an object. For example, from hgcore.h:
Code: Show/Hide
/* pytype: struct, struct HGTeam, hgteam */

For enums, you need to set up a naming convention in the c code where all entries within a struct have a consistent prefix. For example, from hgcore.h:
Code: Show/Hide
/* pyconst: enum, "HGS_*" */
This will create these constants in the asss namespace under their full name.
Initrd.gz - Tue Mar 17, 2009 10:54 am
Post subject:
Thanks a lot. That should be the last question.
Initrd.gz - Thu Mar 19, 2009 2:16 pm
Post subject:
Ok, another small question:

Say I have a structure like this:
Code: Show/Hide

typedef struct Bot
{
    char name[40];
    int ship;
    struct
    {
        unsigned alive : 1;
        unsigned aiming : 1;
        unsigned firing : 1;
        unsigned reloading : 1;
        unsigned padding : 4;
    } flags;
} Bot;
/* pytype: struct, *Bot, bot */

Could I use anything in the flags structure within the Bot structure in python, or do I have to pytype that as well?
D1st0rt - Tue Mar 24, 2009 4:33 pm
Post subject:
I am not sure if you can use generated structures within structures, it might have to be one of the hardcoded types.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group