~ubuntu-branches/ubuntu/intrepid/enigma/intrepid

« back to all changes in this revision

Viewing changes to tools/tolua.c

  • Committer: Bazaar Package Importer
  • Author(s): Erich Schubert
  • Date: 2005-08-28 15:30:09 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050828153009-sky64kb6tcq37xt5
Tags: 0.92.1-1
* New upstream subversion checkout
* Remove menu.s3m, which we are allowed to distributed but not to modify
  also copyright notice is confusing... (Closes: #321669)
* Rebuild with new libzipios (Closes: #325405)
  I hope this works without a versioned build-dependency
* Added "enigma replaces enigma-data" for upgrades (Closes: #308558)
* Added notes about the fonts copyright.
* updated to policy 3.6.2.1 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* tolua
2
 
** Support code for Lua bindings.
3
 
** Written by Waldemar Celes
4
 
** TeCGraf/PUC-Rio
5
 
** Jul 1998
6
 
** $Id: tolua.c,v 1.3 1999/07/28 22:21:09 celes Exp $
7
 
*/
8
 
 
9
 
/* This code is free software; you can redistribute it and/or modify it. 
10
 
** The software provided hereunder is on an "as is" basis, and 
11
 
** the author has no obligation to provide maintenance, support, updates,
12
 
** enhancements, or modifications. 
13
 
*/
14
 
 
15
 
#include "tolua.h"
16
 
#include "lua.h"
17
 
#include "lualib.h"
18
 
 
19
 
#include <stdio.h>
20
 
#include <stdlib.h>
21
 
#include <string.h>
22
 
 
23
 
 
24
 
static void help (void)
25
 
{
26
 
 fprintf(stderr,"\n"
27
 
         "usage: tolua [options] input_file\n"
28
 
         "\n"
29
 
         "Command line options are:\n"
30
 
         "  -v       : print version information.\n"
31
 
         "  -o  file : set output file; default is stdout.\n"
32
 
         "  -H  file : create include file.\n"
33
 
         "  -n  name : set package name; default is input file root name.\n"
34
 
         "  -p       : parse only.\n"
35
 
         "  -P       : parse and print structure information (for debug).\n"
36
 
         "  -h       : print this message.\n"
37
 
         "Should the input file be omitted, stdin is assumed;\n"
38
 
         "in that case, the package name must be explicitly set.\n\n" 
39
 
        );
40
 
}
41
 
 
42
 
static void version (void)
43
 
{
44
 
 fprintf(stderr, "%s (written by W. Celes)\n",TOLUA_VERSION);
45
 
}
46
 
 
47
 
static void setfield (lua_State* L, int table, char* f, char* v)
48
 
{
49
 
 lua_pushstring(L,f);
50
 
 lua_pushstring(L,v);
51
 
 lua_settable(L,table);
52
 
}
53
 
 
54
 
static void error (char* o)
55
 
{
56
 
 fprintf(stderr,"tolua: unknown option '%s'\n",o);
57
 
 help();
58
 
 exit(1);
59
 
}
60
 
 
61
 
int main (int argc, char* argv[])
62
 
{
63
 
 lua_State* L = lua_open(0);
64
 
 lua_baselibopen(L);
65
 
 lua_iolibopen(L);
66
 
 lua_strlibopen(L);
67
 
 lua_pushstring(L,TOLUA_VERSION); lua_setglobal(L,"TOLUA_VERSION");
68
 
 
69
 
 if (argc==1)
70
 
 {
71
 
  help();
72
 
  return 0;
73
 
 }
74
 
 else
75
 
 {
76
 
  int i, t;
77
 
  lua_newtable(L);
78
 
  lua_pushvalue(L,-1);
79
 
  lua_setglobal(L,"flags");
80
 
  t = lua_gettop(L);
81
 
  for (i=1; i<argc; ++i)
82
 
  {
83
 
   if (*argv[i] == '-')
84
 
   {
85
 
    switch (argv[i][1])
86
 
    {
87
 
     case 'v': version(); return 0;
88
 
     case 'h': help(); return 0;
89
 
     case 'p': setfield(L,t,"p",""); break;
90
 
     case 'P': setfield(L,t,"P",""); break;
91
 
     case 'o': setfield(L,t,"o",argv[++i]); break;
92
 
     case 'n': setfield(L,t,"n",argv[++i]); break;
93
 
     case 'H': setfield(L,t,"H",argv[++i]); break;
94
 
     default: error(argv[i]); break;
95
 
    }
96
 
   }
97
 
   else
98
 
   {
99
 
    setfield(L,t,"f",argv[i]);
100
 
    break;
101
 
   }
102
 
  }
103
 
  lua_pop(L,1);
104
 
 }
105
 
 
106
 
#if 1
107
 
 {
108
 
  int tolua_tolualua_open(lua_State* L);
109
 
  tolua_tolualua_open(L);
110
 
 }
111
 
#else
112
 
 {
113
 
  int i;
114
 
  char* p;
115
 
  char  path[BUFSIZ];
116
 
  char* files[] = {
117
 
                   "basic.lua",
118
 
                   "feature.lua",
119
 
                   "verbatim.lua",
120
 
                   "code.lua",
121
 
                   "typedef.lua",
122
 
                   "container.lua",
123
 
                   "package.lua",
124
 
                   "module.lua",
125
 
                   "define.lua",
126
 
                   "enumerate.lua",
127
 
                   "declaration.lua",
128
 
                   "variable.lua",
129
 
                   "array.lua",
130
 
                   "function.lua",
131
 
                   "operator.lua",
132
 
                   "class.lua",
133
 
                   "clean.lua",
134
 
                   "doit.lua",
135
 
                   NULL
136
 
                  };
137
 
  strcpy(path,argv[0]);
138
 
  p = strrchr(path,'/');
139
 
  p = (p==NULL) ? path : p+1;
140
 
  for (i=0; files[i]; ++i)
141
 
  {
142
 
   sprintf(p,"%s",files[i]);
143
 
   lua_dofile(L,path); 
144
 
  }
145
 
 }
146
 
 
147
 
#endif
148
 
 return 0;
149
 
}