From 77aa5645c55e8f44060cab8657002d7a07de0e64 Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Sun, 13 Sep 2015 19:10:36 +0200 Subject: luaL_checkstack accepts NULL message. --- c-api/compat-5.3.c | 12 ++++++++++++ c-api/compat-5.3.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c index 34b8001..fd41798 100644 --- a/c-api/compat-5.3.c +++ b/c-api/compat-5.3.c @@ -155,6 +155,18 @@ COMPAT53_API void luaL_checkversion (lua_State *L) { } +COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg) { + if (!lua_checkstack(L, sp+LUA_MINSTACK)) { + if (msg != NULL) + luaL_error(L, "stack overflow (%s)", msg); + else { + lua_pushliteral(L, "stack overflow"); + lua_error(L); + } + } +} + + COMPAT53_API int luaL_getsubtable (lua_State *L, int i, const char *name) { int abs_i = lua_absindex(L, i); luaL_checkstack(L, 3, "not enough stack slots"); diff --git a/c-api/compat-5.3.h b/c-api/compat-5.3.h index c70ea33..2309294 100644 --- a/c-api/compat-5.3.h +++ b/c-api/compat-5.3.h @@ -131,6 +131,9 @@ COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum); #define luaL_checkversion COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkversion) COMPAT53_API void luaL_checkversion (lua_State *L); +#define luaL_checkstack COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkstack_53) +COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg); + #define luaL_getsubtable COMPAT53_CONCAT(COMPAT53_PREFIX, L_getsubtable) COMPAT53_API int luaL_getsubtable (lua_State* L, int i, const char *name); -- cgit v1.2.3-55-g6feb