~ubuntu-branches/ubuntu/edgy/swig1.3/edgy

« back to all changes in this revision

Viewing changes to Examples/lua/variables/example.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:16:04 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205011604-ygx904it6413k3go
Tags: 1.3.27-1ubuntu1
Resynchronise with Debian again, for the new subversion packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* File : example.c */
 
2
 
 
3
/* I'm a file containing some C global variables */
 
4
 
 
5
#include <stdio.h>
 
6
#include <stdlib.h>
 
7
#include "example.h"
 
8
 
 
9
int              ivar = 0;                    
 
10
short            svar = 0;
 
11
long             lvar = 0;
 
12
unsigned int     uivar = 0;
 
13
unsigned short   usvar = 0;
 
14
unsigned long    ulvar = 0;
 
15
signed char      scvar = 0;
 
16
unsigned char    ucvar = 0;
 
17
char             cvar = 0;
 
18
float            fvar = 0;
 
19
double           dvar = 0;
 
20
char            *strvar = 0;
 
21
const char       cstrvar[] = "Goodbye";
 
22
int             *iptrvar = 0;
 
23
char             name[256] = "Dave";
 
24
char             path[256] = "/home/beazley";
 
25
 
 
26
 
 
27
/* Global variables involving a structure */
 
28
Point           *ptptr = 0;
 
29
Point            pt = { 10, 20 };
 
30
 
 
31
/* A variable that we will make read-only in the interface */
 
32
int              status = 1;
 
33
 
 
34
/* A debugging function to print out their values */
 
35
 
 
36
void print_vars() {
 
37
  printf("ivar      = %d\n", ivar);
 
38
  printf("svar      = %d\n", svar);
 
39
  printf("lvar      = %ld\n", lvar);
 
40
  printf("uivar     = %u\n", uivar);
 
41
  printf("usvar     = %u\n", usvar);
 
42
  printf("ulvar     = %lu\n", ulvar);
 
43
  printf("scvar     = %d\n", scvar);
 
44
  printf("ucvar     = %u\n", ucvar);
 
45
  printf("fvar      = %g\n", fvar);
 
46
  printf("dvar      = %g\n", dvar);
 
47
  printf("cvar      = %c\n", cvar);
 
48
  printf("strvar    = %s\n", strvar ? strvar : "(null)");
 
49
  printf("cstrvar   = %s\n", cstrvar ? cstrvar : "(null)");
 
50
  printf("iptrvar   = %p\n", iptrvar);
 
51
  printf("name      = %s\n", name);
 
52
  printf("ptptr     = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
 
53
  printf("pt        = (%d, %d)\n", pt.x, pt.y);
 
54
  printf("status    = %d\n", status);
 
55
}
 
56
 
 
57
/* A function to create an integer (to test iptrvar) */
 
58
 
 
59
int *new_int(int value) {
 
60
  int *ip = (int *) malloc(sizeof(int));
 
61
  *ip = value;
 
62
  return ip;
 
63
}
 
64
 
 
65
/* A function to create a point */
 
66
 
 
67
Point *new_Point(int x, int y) {
 
68
  Point *p = (Point *) malloc(sizeof(Point));
 
69
  p->x = x;
 
70
  p->y = y;
 
71
  return p;
 
72
}
 
73
 
 
74
char * Point_print(Point *p) {
 
75
  static char buffer[256];
 
76
  if (p) {
 
77
    sprintf(buffer,"(%d,%d)", p->x,p->y);
 
78
  } else {
 
79
    sprintf(buffer,"null");
 
80
  }
 
81
  return buffer;
 
82
}
 
83
 
 
84
void pt_print() {
 
85
  printf("(%d, %d)\n", pt.x, pt.y);
 
86
}