aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-02-07 15:22:53 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-02-07 15:22:53 -0200
commit7c8f1823e7590cf97d1002d48a7bd233136bedcb (patch)
tree0ec76d957bccdf2867e2c5f5d942252a5968682d /lapi.c
parentca181f31e41bbff8039aee3977894df7f9b128cb (diff)
downloadlua-7c8f1823e7590cf97d1002d48a7bd233136bedcb.tar.gz
lua-7c8f1823e7590cf97d1002d48a7bd233136bedcb.tar.bz2
lua-7c8f1823e7590cf97d1002d48a7bd233136bedcb.zip
bug: true 1 != true 2 + no more lua_getstr + some new macros
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c33
1 files changed, 6 insertions, 27 deletions
diff --git a/lapi.c b/lapi.c
index 1ddbef73..d39afe86 100644
--- a/lapi.c
+++ b/lapi.c
@@ -180,8 +180,8 @@ LUA_API int lua_iscfunction (lua_State *L, int index) {
180 180
181LUA_API int lua_isnumber (lua_State *L, int index) { 181LUA_API int lua_isnumber (lua_State *L, int index) {
182 TObject n; 182 TObject n;
183 TObject *o = luaA_indexAcceptable(L, index); 183 const TObject *o = luaA_indexAcceptable(L, index);
184 return (o != NULL && luaV_tonumber(o, &n)); 184 return (o != NULL && tonumber(o, &n));
185} 185}
186 186
187 187
@@ -222,7 +222,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
222LUA_API lua_Number lua_tonumber (lua_State *L, int index) { 222LUA_API lua_Number lua_tonumber (lua_State *L, int index) {
223 TObject n; 223 TObject n;
224 const TObject *o = luaA_indexAcceptable(L, index); 224 const TObject *o = luaA_indexAcceptable(L, index);
225 if (o != NULL && (o = luaV_tonumber(o, &n)) != NULL) 225 if (o != NULL && tonumber(o, &n))
226 return nvalue(o); 226 return nvalue(o);
227 else 227 else
228 return 0; 228 return 0;
@@ -247,7 +247,7 @@ LUA_API const char *lua_tostring (lua_State *L, int index) {
247 else { 247 else {
248 const char *s; 248 const char *s;
249 lua_lock(L); /* `luaV_tostring' may create a new string */ 249 lua_lock(L); /* `luaV_tostring' may create a new string */
250 s = (luaV_tostring(L, o) == 0) ? svalue(o) : NULL; 250 s = (luaV_tostring(L, o) ? svalue(o) : NULL);
251 lua_unlock(L); 251 lua_unlock(L);
252 return s; 252 return s;
253 } 253 }
@@ -263,7 +263,7 @@ LUA_API size_t lua_strlen (lua_State *L, int index) {
263 else { 263 else {
264 size_t l; 264 size_t l;
265 lua_lock(L); /* `luaV_tostring' may create a new string */ 265 lua_lock(L); /* `luaV_tostring' may create a new string */
266 l = (luaV_tostring(L, o) == 0) ? tsvalue(o)->tsv.len : 0; 266 l = (luaV_tostring(L, o) ? tsvalue(o)->tsv.len : 0);
267 lua_unlock(L); 267 lua_unlock(L);
268 return l; 268 return l;
269 } 269 }
@@ -350,7 +350,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
350 350
351LUA_API void lua_pushboolean (lua_State *L, int b) { 351LUA_API void lua_pushboolean (lua_State *L, int b) {
352 lua_lock(L); 352 lua_lock(L);
353 setbvalue(L->top, b); 353 setbvalue(L->top, (b != 0)); /* ensure that true is 1 */
354 api_incr_top(L); 354 api_incr_top(L);
355 lua_unlock(L); 355 lua_unlock(L);
356} 356}
@@ -362,16 +362,6 @@ LUA_API void lua_pushboolean (lua_State *L, int b) {
362*/ 362*/
363 363
364 364
365LUA_API void lua_getstr (lua_State *L, int index, const char *name) {
366 TObject o;
367 lua_lock(L);
368 setsvalue(&o, luaS_new(L, name));
369 luaV_gettable(L, luaA_index(L, index), &o, L->top);
370 api_incr_top(L);
371 lua_unlock(L);
372}
373
374
375LUA_API void lua_gettable (lua_State *L, int index) { 365LUA_API void lua_gettable (lua_State *L, int index) {
376 StkId t; 366 StkId t;
377 lua_lock(L); 367 lua_lock(L);
@@ -439,17 +429,6 @@ LUA_API void lua_getmetatable (lua_State *L, int objindex) {
439*/ 429*/
440 430
441 431
442LUA_API void lua_setstr (lua_State *L, int index, const char *name) {
443 TObject o;
444 lua_lock(L);
445 api_checknelems(L, 1);
446 setsvalue(&o, luaS_new(L, name));
447 luaV_settable(L, luaA_index(L, index), &o, L->top - 1);
448 L->top--; /* remove element from the top */
449 lua_unlock(L);
450}
451
452
453LUA_API void lua_settable (lua_State *L, int index) { 432LUA_API void lua_settable (lua_State *L, int index) {
454 StkId t; 433 StkId t;
455 lua_lock(L); 434 lua_lock(L);