SWIG help, very new

Enrico Ng ng at fnmail.com
Wed May 23 22:33:54 CEST 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
file.

--
Enrico Ng <enrico at fnal.gov>


stack.c
----------------------------------
#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)->data=buffer;
  (*stack)->next=new STACK;
  (*stack)->next->prev=(*stack);
  (*stack)=(*stack)->next;
}

int pop(STACK **stack) {
  (*stack)=(*stack)->prev;
  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);}

-------------------------------------------------------------------------
stack.i
--------------------------------------------------------------------
%module stack

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






More information about the Python-list mailing list