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

« back to all changes in this revision

Viewing changes to lib-src/lua/tolua_gp.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: get & push functions.
2
 
** Support code for Lua bindings.
3
 
** Written by Waldemar Celes
4
 
** TeCGraf/PUC-Rio
5
 
** Jul 1998
6
 
** $Id: tolua_gp.c,v 1.1 2003/02/09 21:30:32 dheck 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 "tolua_tm.h"
17
 
 
18
 
#include <string.h>
19
 
#include <stdlib.h>
20
 
 
21
 
double tolua_getnumber (lua_State* L, int narg, double def)
22
 
{
23
 
 return lua_gettop(L)<abs(narg) ? def : lua_tonumber(L,narg);
24
 
}
25
 
 
26
 
const char* tolua_getstring (lua_State* L, int narg, const char* def)
27
 
{
28
 
 return lua_gettop(L)<abs(narg) ? def : lua_tostring(L,narg);
29
 
}
30
 
 
31
 
void* tolua_getuserdata (lua_State* L, int narg, void* def)
32
 
{
33
 
 return lua_gettop(L)<abs(narg) ? def : lua_touserdata(L,narg);
34
 
}
35
 
 
36
 
void* tolua_getusertype (lua_State* L, int narg, void* def)
37
 
{
38
 
 return lua_gettop(L)<abs(narg) ? def : lua_touserdata(L,narg);
39
 
}
40
 
 
41
 
int tolua_getvalue (lua_State* L, int narg, int def)
42
 
{
43
 
 return lua_gettop(L)<abs(narg) ? def : narg;
44
 
}
45
 
 
46
 
int tolua_getbool (lua_State* L, int narg, int def)
47
 
{
48
 
 return lua_gettop(L)<abs(narg) ? 
49
 
         def : 
50
 
         lua_isnil(L,narg) ? 0 : lua_tonumber(L,narg)!=0;
51
 
}
52
 
 
53
 
double tolua_getfieldnumber (lua_State* L, int lo, int index, double def)
54
 
{
55
 
 double v;
56
 
 lua_pushnumber(L,index);
57
 
 lua_gettable(L,lo);
58
 
 v = lua_isnil(L,-1) ? def : lua_tonumber(L,-1);
59
 
 lua_pop(L,1);
60
 
 return v;
61
 
}
62
 
 
63
 
const char* tolua_getfieldstring 
64
 
(lua_State* L, int lo, int index, const char* def)
65
 
{
66
 
 const char* v;
67
 
 lua_pushnumber(L,index);
68
 
 lua_gettable(L,lo);
69
 
 v = lua_isnil(L,-1) ? def : lua_tostring(L,-1);
70
 
 lua_pop(L,1);
71
 
 return v;
72
 
}
73
 
 
74
 
void* tolua_getfielduserdata (lua_State* L, int lo, int index, void* def)
75
 
{
76
 
 void* v;
77
 
 lua_pushnumber(L,index);
78
 
 lua_gettable(L,lo);
79
 
 v = lua_isnil(L,-1) ? def : lua_touserdata(L,-1);
80
 
 lua_pop(L,1);
81
 
 return v;
82
 
}
83
 
 
84
 
void* tolua_getfieldusertype (lua_State* L, int lo, int index, void* def)
85
 
{
86
 
 void* v;
87
 
 lua_pushnumber(L,index);
88
 
 lua_gettable(L,lo);
89
 
 v = lua_isnil(L,-1) ? def : lua_touserdata(L,-1);
90
 
 lua_pop(L,1);
91
 
 return v;
92
 
}
93
 
 
94
 
int tolua_getfieldvalue (lua_State* L, int lo, int index, int def)
95
 
{
96
 
 int v;
97
 
 lua_pushnumber(L,index);
98
 
 lua_gettable(L,lo);
99
 
 v = lua_isnil(L,-1) ? def : lo;
100
 
 lua_pop(L,1);
101
 
 return v;
102
 
}
103
 
 
104
 
int tolua_getfieldbool (lua_State* L, int lo, int index, int def)
105
 
{
106
 
 int v;
107
 
 lua_pushnumber(L,index);
108
 
 lua_gettable(L,lo);
109
 
 v = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1)!=0;
110
 
 lua_pop(L,1);
111
 
 return v;
112
 
}
113
 
 
114
 
void tolua_pushnumber (lua_State* L, double value)
115
 
{
116
 
 lua_pushnumber(L,value);
117
 
}
118
 
 
119
 
void tolua_pushstring (lua_State* L, const char* value)
120
 
{
121
 
 if (value == NULL)
122
 
  lua_pushnil(L);
123
 
 else
124
 
  lua_pushstring(L,value);
125
 
}
126
 
 
127
 
void tolua_pushuserdata (lua_State* L, void* value)
128
 
{
129
 
 if (value == NULL)
130
 
  lua_pushnil(L);
131
 
 else
132
 
  lua_pushuserdata(L,value);
133
 
}
134
 
 
135
 
void tolua_pushusertype (lua_State* L, void* value, int tag)
136
 
{
137
 
 if (value == NULL)
138
 
  lua_pushnil(L);
139
 
 else
140
 
  lua_pushusertag(L,value,tag);
141
 
}
142
 
 
143
 
void tolua_pushvalue (lua_State* L, int lo)
144
 
{
145
 
 lua_pushvalue(L,lo);
146
 
}
147
 
 
148
 
void tolua_pushbool (lua_State* L, int value)
149
 
{
150
 
 if (value)
151
 
  lua_pushnumber(L,(double)value);
152
 
 else
153
 
  lua_pushnil(L);
154
 
}
155
 
 
156
 
void tolua_pushfieldnumber (lua_State* L, int lo, int index, double v)
157
 
{
158
 
 lua_pushnumber(L,index);
159
 
 tolua_pushnumber(L,v);
160
 
 lua_settable(L,lo);
161
 
}
162
 
 
163
 
void tolua_pushfieldstring (lua_State* L, int lo, int index, const char* v)
164
 
{
165
 
 lua_pushnumber(L,index);
166
 
 tolua_pushstring(L,v);
167
 
 lua_settable(L,lo);
168
 
}
169
 
 
170
 
void tolua_pushfielduserdata (lua_State* L, int lo, int index, void* v)
171
 
{
172
 
 lua_pushnumber(L,index);
173
 
 tolua_pushuserdata(L,v);
174
 
 lua_settable(L,lo);
175
 
}
176
 
 
177
 
void tolua_pushfieldusertype (lua_State* L, int lo, int index, void* v, int tag)
178
 
{
179
 
 lua_pushnumber(L,index);
180
 
 tolua_pushusertype(L,v,tag);
181
 
 lua_settable(L,lo);
182
 
}
183
 
 
184
 
void tolua_pushfieldvalue (lua_State* L, int lo, int index, int v)
185
 
{
186
 
 lua_pushnumber(L,index);
187
 
 lua_pushvalue(L,v);
188
 
 lua_settable(L,lo);
189
 
}
190
 
 
191
 
void tolua_pushfieldbool (lua_State* L, int lo, int index, int v)
192
 
{
193
 
 lua_pushnumber(L,index);
194
 
 tolua_pushbool(L,v);
195
 
 lua_settable(L,lo);
196
 
}
197