cosmopolitan/tool/net/luacheck.h
Paul Kulchenko 9a6bd304a5
Fix reporting of Lua stack items from various hook calls (#395)
Some hooks can be called after OnHttpRequest, which may leave an
anchored item on stack, so this have to be taken into account to
avoid spurious reports.
2022-04-27 21:57:52 -07:00

23 lines
799 B
C

#ifndef COSMOPOLITAN_TOOL_NET_LUACHECK_H_
#define COSMOPOLITAN_TOOL_NET_LUACHECK_H_
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "third_party/lua/cosmo.h"
#include "third_party/lua/lua.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define AssertLuaStackIsAt(L, level) \
do { \
if (lua_gettop(L) > level) { \
char *s = LuaFormatStack(L); \
WARNF("lua stack should be at %d;" \
" extra values ignored:\n%s", \
level, s); \
free(s); \
} \
} while (0)
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_TOOL_NET_LUACHECK_H_ */