diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-30 10:50:09 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-30 10:50:09 -0200 |
commit | b3959d58ffc60bbfd288ffa8bf2e9ef19b7a862d (patch) | |
tree | 5adcd2a40a12428434c1ec08d1c08e9680fbceca | |
parent | f379d06e24f22cb4d0afa3937c27ef35b73b00a6 (diff) | |
download | lua-b3959d58ffc60bbfd288ffa8bf2e9ef19b7a862d.tar.gz lua-b3959d58ffc60bbfd288ffa8bf2e9ef19b7a862d.tar.bz2 lua-b3959d58ffc60bbfd288ffa8bf2e9ef19b7a862d.zip |
-rw-r--r-- | lapi.c | 32 |
1 files changed, 12 insertions, 20 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.108 2000/10/24 19:19:15 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.109 2000/10/26 12:47:05 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -108,26 +108,23 @@ LUA_API void lua_pushvalue (lua_State *L, int index) { | |||
108 | 108 | ||
109 | LUA_API int lua_type (lua_State *L, int index) { | 109 | LUA_API int lua_type (lua_State *L, int index) { |
110 | StkId o = luaA_indexAcceptable(L, index); | 110 | StkId o = luaA_indexAcceptable(L, index); |
111 | if (o == NULL) return LUA_TNONE; | 111 | return (o == NULL) ? LUA_TNONE : ttype(o); |
112 | else return ttype(o); | ||
113 | } | 112 | } |
114 | 113 | ||
115 | LUA_API const char *lua_typename (lua_State *L, int t) { | 114 | LUA_API const char *lua_typename (lua_State *L, int t) { |
116 | UNUSED(L); | 115 | UNUSED(L); |
117 | return luaO_typenames[t]; | 116 | return (t == LUA_TNONE) ? "no value" : luaO_typenames[t]; |
118 | } | 117 | } |
119 | 118 | ||
120 | 119 | ||
121 | LUA_API int lua_iscfunction (lua_State *L, int index) { | 120 | LUA_API int lua_iscfunction (lua_State *L, int index) { |
122 | StkId o = luaA_indexAcceptable(L, index); | 121 | StkId o = luaA_indexAcceptable(L, index); |
123 | if (o == NULL) return 0; | 122 | return (o == NULL) ? 0 : iscfunction(o); |
124 | else return iscfunction(o); | ||
125 | } | 123 | } |
126 | 124 | ||
127 | LUA_API int lua_isnumber (lua_State *L, int index) { | 125 | LUA_API int lua_isnumber (lua_State *L, int index) { |
128 | TObject *o = luaA_indexAcceptable(L, index); | 126 | TObject *o = luaA_indexAcceptable(L, index); |
129 | if (o == NULL) return 0; | 127 | return (o == NULL) ? 0 : (tonumber(o) == 0); |
130 | else return (tonumber(o) == 0); | ||
131 | } | 128 | } |
132 | 129 | ||
133 | LUA_API int lua_isstring (lua_State *L, int index) { | 130 | LUA_API int lua_isstring (lua_State *L, int index) { |
@@ -138,8 +135,7 @@ LUA_API int lua_isstring (lua_State *L, int index) { | |||
138 | 135 | ||
139 | LUA_API int lua_tag (lua_State *L, int index) { | 136 | LUA_API int lua_tag (lua_State *L, int index) { |
140 | StkId o = luaA_indexAcceptable(L, index); | 137 | StkId o = luaA_indexAcceptable(L, index); |
141 | if (o == NULL) return LUA_NOTAG; | 138 | return (o == NULL) ? LUA_NOTAG : luaT_tag(o); |
142 | else return luaT_tag(o); | ||
143 | } | 139 | } |
144 | 140 | ||
145 | LUA_API int lua_equal (lua_State *L, int index1, int index2) { | 141 | LUA_API int lua_equal (lua_State *L, int index1, int index2) { |
@@ -160,32 +156,28 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { | |||
160 | 156 | ||
161 | LUA_API double lua_tonumber (lua_State *L, int index) { | 157 | LUA_API double lua_tonumber (lua_State *L, int index) { |
162 | StkId o = luaA_indexAcceptable(L, index); | 158 | StkId o = luaA_indexAcceptable(L, index); |
163 | if (o == NULL || tonumber(o)) return 0; | 159 | return (o == NULL || tonumber(o)) ? 0 : nvalue(o); |
164 | else return nvalue(o); | ||
165 | } | 160 | } |
166 | 161 | ||
167 | LUA_API const char *lua_tostring (lua_State *L, int index) { | 162 | LUA_API const char *lua_tostring (lua_State *L, int index) { |
168 | StkId o = luaA_indexAcceptable(L, index); | 163 | StkId o = luaA_indexAcceptable(L, index); |
169 | if (o == NULL || tostring(L, o)) return NULL; | 164 | return (o == NULL || tostring(L, o)) ? NULL : svalue(o); |
170 | else return svalue(o); | ||
171 | } | 165 | } |
172 | 166 | ||
173 | LUA_API size_t lua_strlen (lua_State *L, int index) { | 167 | LUA_API size_t lua_strlen (lua_State *L, int index) { |
174 | StkId o = luaA_indexAcceptable(L, index); | 168 | StkId o = luaA_indexAcceptable(L, index); |
175 | if (o == NULL || tostring(L, o)) return 0; | 169 | return (o == NULL || tostring(L, o)) ? 0 : tsvalue(o)->len; |
176 | else return tsvalue(o)->len; | ||
177 | } | 170 | } |
178 | 171 | ||
179 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) { | 172 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) { |
180 | StkId o = luaA_indexAcceptable(L, index); | 173 | StkId o = luaA_indexAcceptable(L, index); |
181 | if (o == NULL || !iscfunction(o)) return NULL; | 174 | return (o == NULL || !iscfunction(o)) ? NULL : clvalue(o)->f.c; |
182 | else return clvalue(o)->f.c; | ||
183 | } | 175 | } |
184 | 176 | ||
185 | LUA_API void *lua_touserdata (lua_State *L, int index) { | 177 | LUA_API void *lua_touserdata (lua_State *L, int index) { |
186 | StkId o = luaA_indexAcceptable(L, index); | 178 | StkId o = luaA_indexAcceptable(L, index); |
187 | if (o == NULL || ttype(o) != LUA_TUSERDATA) return NULL; | 179 | return (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL : |
188 | else return tsvalue(o)->u.d.value; | 180 | tsvalue(o)->u.d.value; |
189 | } | 181 | } |
190 | 182 | ||
191 | LUA_API const void *lua_topointer (lua_State *L, int index) { | 183 | LUA_API const void *lua_topointer (lua_State *L, int index) { |