diff options
Diffstat (limited to '')
-rw-r--r-- | lauxlib.c | 25 |
1 files changed, 18 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.187 2009/06/18 18:59:58 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.188 2009/06/19 14:21:57 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 | */ |
@@ -106,9 +106,16 @@ static void pushfuncname (lua_State *L, lua_Debug *ar) { | |||
106 | 106 | ||
107 | static int countlevels (lua_State *L) { | 107 | static int countlevels (lua_State *L) { |
108 | lua_Debug ar; | 108 | lua_Debug ar; |
109 | int level = 1; | 109 | int li = 1, le = 1; |
110 | while (lua_getstack(L, level, &ar)) level++; | 110 | /* find an upper bound */ |
111 | return level; | 111 | while (lua_getstack(L, le, &ar)) { li = le; le *= 2; } |
112 | /* do a binary search */ | ||
113 | while (li < le) { | ||
114 | int m = (li + le)/2; | ||
115 | if (lua_getstack(L, m, &ar)) li = m + 1; | ||
116 | else le = m; | ||
117 | } | ||
118 | return le - 1; | ||
112 | } | 119 | } |
113 | 120 | ||
114 | 121 | ||
@@ -263,9 +270,13 @@ LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, | |||
263 | } | 270 | } |
264 | 271 | ||
265 | 272 | ||
266 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { | 273 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) { |
267 | if (!lua_checkstack(L, space)) | 274 | if (!lua_checkstack(L, space)) { |
268 | luaL_error(L, "stack overflow (%s)", mes); | 275 | if (msg) |
276 | luaL_error(L, "stack overflow (%s)", msg); | ||
277 | else | ||
278 | luaL_error(L, "stack overflow"); | ||
279 | } | ||
269 | } | 280 | } |
270 | 281 | ||
271 | 282 | ||