#include <assert.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
static int growstack_toclose(lua_State* L) {
// in lua_settop, trigger luaD_growstack(), ci->top change
// local var newtop in lua_settop invalid! cause CRASH !!
luaL_checkstack(L, 128, NULL);
return 0;
}
static int bug_test(lua_State* L) {
lua_Integer a=0x12345678, b=0x87654321;
lua_pushinteger(L, a);
// local t <close> = setmetatable({}, {__close = growstack_toclose })
lua_newtable(L);
lua_newtable(L); // MT : { __close = growstack_toclose }
lua_pushcfunction(L, growstack_toclose);
lua_setfield(L, -2, "__close");
lua_setmetatable(L, -2);
lua_toclose(L, -1);
// crash test
b = lua_tointeger(L, -1);
lua_assert( a==b );
return 0;