1
/* tolua: get & push functions.
2
** Support code for Lua bindings.
3
** Written by Waldemar Celes
6
** $Id: tolua_gp.c,v 1.1 2003/02/09 21:30:32 dheck Exp $
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.
21
double tolua_getnumber (lua_State* L, int narg, double def)
23
return lua_gettop(L)<abs(narg) ? def : lua_tonumber(L,narg);
26
const char* tolua_getstring (lua_State* L, int narg, const char* def)
28
return lua_gettop(L)<abs(narg) ? def : lua_tostring(L,narg);
31
void* tolua_getuserdata (lua_State* L, int narg, void* def)
33
return lua_gettop(L)<abs(narg) ? def : lua_touserdata(L,narg);
36
void* tolua_getusertype (lua_State* L, int narg, void* def)
38
return lua_gettop(L)<abs(narg) ? def : lua_touserdata(L,narg);
41
int tolua_getvalue (lua_State* L, int narg, int def)
43
return lua_gettop(L)<abs(narg) ? def : narg;
46
int tolua_getbool (lua_State* L, int narg, int def)
48
return lua_gettop(L)<abs(narg) ?
50
lua_isnil(L,narg) ? 0 : lua_tonumber(L,narg)!=0;
53
double tolua_getfieldnumber (lua_State* L, int lo, int index, double def)
56
lua_pushnumber(L,index);
58
v = lua_isnil(L,-1) ? def : lua_tonumber(L,-1);
63
const char* tolua_getfieldstring
64
(lua_State* L, int lo, int index, const char* def)
67
lua_pushnumber(L,index);
69
v = lua_isnil(L,-1) ? def : lua_tostring(L,-1);
74
void* tolua_getfielduserdata (lua_State* L, int lo, int index, void* def)
77
lua_pushnumber(L,index);
79
v = lua_isnil(L,-1) ? def : lua_touserdata(L,-1);
84
void* tolua_getfieldusertype (lua_State* L, int lo, int index, void* def)
87
lua_pushnumber(L,index);
89
v = lua_isnil(L,-1) ? def : lua_touserdata(L,-1);
94
int tolua_getfieldvalue (lua_State* L, int lo, int index, int def)
97
lua_pushnumber(L,index);
99
v = lua_isnil(L,-1) ? def : lo;
104
int tolua_getfieldbool (lua_State* L, int lo, int index, int def)
107
lua_pushnumber(L,index);
109
v = lua_isnil(L,-1) ? 0 : lua_tonumber(L,-1)!=0;
114
void tolua_pushnumber (lua_State* L, double value)
116
lua_pushnumber(L,value);
119
void tolua_pushstring (lua_State* L, const char* value)
124
lua_pushstring(L,value);
127
void tolua_pushuserdata (lua_State* L, void* value)
132
lua_pushuserdata(L,value);
135
void tolua_pushusertype (lua_State* L, void* value, int tag)
140
lua_pushusertag(L,value,tag);
143
void tolua_pushvalue (lua_State* L, int lo)
148
void tolua_pushbool (lua_State* L, int value)
151
lua_pushnumber(L,(double)value);
156
void tolua_pushfieldnumber (lua_State* L, int lo, int index, double v)
158
lua_pushnumber(L,index);
159
tolua_pushnumber(L,v);
163
void tolua_pushfieldstring (lua_State* L, int lo, int index, const char* v)
165
lua_pushnumber(L,index);
166
tolua_pushstring(L,v);
170
void tolua_pushfielduserdata (lua_State* L, int lo, int index, void* v)
172
lua_pushnumber(L,index);
173
tolua_pushuserdata(L,v);
177
void tolua_pushfieldusertype (lua_State* L, int lo, int index, void* v, int tag)
179
lua_pushnumber(L,index);
180
tolua_pushusertype(L,v,tag);
184
void tolua_pushfieldvalue (lua_State* L, int lo, int index, int v)
186
lua_pushnumber(L,index);
191
void tolua_pushfieldbool (lua_State* L, int lo, int index, int v)
193
lua_pushnumber(L,index);