aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 7611db7f..dcb913f0 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.193 2009/10/05 16:44:33 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.194 2009/11/25 15:27:51 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -370,9 +370,9 @@ static void adjuststack (luaL_Buffer *B) {
370 if (B->lvl > 1) { 370 if (B->lvl > 1) {
371 lua_State *L = B->L; 371 lua_State *L = B->L;
372 int toget = 1; /* number of levels to concat */ 372 int toget = 1; /* number of levels to concat */
373 size_t toplen = lua_objlen(L, -1); 373 size_t toplen = lua_rawlen(L, -1);
374 do { 374 do {
375 size_t l = lua_objlen(L, -(toget+1)); 375 size_t l = lua_rawlen(L, -(toget+1));
376 if (B->lvl - toget + 1 >= LIMIT || toplen > l) { 376 if (B->lvl - toget + 1 >= LIMIT || toplen > l) {
377 toplen += l; 377 toplen += l;
378 toget++; 378 toget++;
@@ -463,7 +463,7 @@ LUALIB_API int luaL_ref (lua_State *L, int t) {
463 lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ 463 lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */
464 } 464 }
465 else { /* no free elements */ 465 else { /* no free elements */
466 ref = (int)lua_objlen(L, t) + 1; /* get a new reference */ 466 ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */
467 if (ref == FREELIST_REF) { /* FREELIST_REF not initialized? */ 467 if (ref == FREELIST_REF) { /* FREELIST_REF not initialized? */
468 lua_pushinteger(L, 0); 468 lua_pushinteger(L, 0);
469 lua_rawseti(L, t, FREELIST_REF); 469 lua_rawseti(L, t, FREELIST_REF);
@@ -627,6 +627,17 @@ LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
627} 627}
628 628
629 629
630LUALIB_API int luaL_len (lua_State *L, int idx) {
631 int l;
632 lua_len(L, idx);
633 l = lua_tointeger(L, -1);
634 if (l == 0 && !lua_isnumber(L, -1))
635 luaL_error(L, "object length is not a number");
636 lua_pop(L, 1); /* remove object */
637 return l;
638}
639
640
630LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { 641LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
631 if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ 642 if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */
632 switch (lua_type(L, idx)) { 643 switch (lua_type(L, idx)) {