-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLuaStackGuard.h
More file actions
53 lines (47 loc) · 937 Bytes
/
LuaStackGuard.h
File metadata and controls
53 lines (47 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#ifndef __SCRIPTBIND_LUA_LUASTACKGUARD_H__
#define __SCRIPTBIND_LUA_LUASTACKGUARD_H__
#include "LuaHelp.h"
#include "Base/Debug.h"
struct LuaStackGuard
{
LuaStackGuard(lua_State *p)
{
state_=p;
top_=lua_gettop(state_);
}
~LuaStackGuard()
{
lua_settop(state_,top_);
}
private:
int top_;
lua_State* state_;
};
#define _GUARD_STACK(ls) LuaStackGuard __guard__(ls);
#ifdef _DEBUG
struct LuaStackValidator
{
LuaStackValidator( lua_State *state,const char *text )
{
text_ = text;
state_ = state;
top_ = lua_gettop(state_);
}
~LuaStackValidator()
{
if (top_ != lua_gettop(state_))
{
ERROR("lua stack validator error in fuc:%s\n", text_);
lua_settop(state_,top_);
}
}
const char* text_;
lua_State* state_;
int top_;
};
#define _CHECK_STACK(L) LuaStackValidator __stackCheck((L),__FUNCTION__);
#else
#define _CHECK_STACK(L)
#endif
#endif // __SCRIPTBIND_LUA_LUASTACKGUARD_H__