SWIG help, very new

Enrico Ng ng at fnmail.com
Wed May 23 16:33:54 EDT 2001

Hi, I'm very new to SWIG.
I wrote a small stack program in C
and want to use swig to make a python module with it.
but it isnt working for me.
Most likely because I'm not really sure what should go in the interface

Enrico Ng <enrico at fnal.gov>

#include <stdio.h>
#include <string.h>

typedef struct stk{int data; struct stk *next; struct stk *prev;} STACK;
void init(){STACK* stack;}

void push(int buffer,STACK **stack) {
  (*stack)->next=new STACK;

int pop(STACK **stack) {
  delete (*stack)->next;
  return (*stack)->data;}

void add(STACK* stack){push(pop(&stack)+pop(&stack),&stack);}
void sub(STACK* stack){push(-pop(&stack)+pop(&stack),&stack);}
void mul(STACK* stack){push(pop(&stack)*pop(&stack),&stack);}
void div(STACK* stack){push(1/(pop(&stack)/pop(&stack)),&stack);}

%module stack

typedef struct stk{int data; struct stk *next; struct stk *prev;}STACK;
STACK *stack;

More information about the Python-list mailing list