diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-08-31 10:31:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-08-31 10:31:44 -0300 |
commit | a290b84c670bbf0770d76429e7282c555a80058e (patch) | |
tree | f882c5d0f71dec5244501c567efe7402185c3c24 /ldo.c | |
parent | 1022b3c85ee2bc8ec109da03fb1168139f209536 (diff) | |
download | lua-a290b84c670bbf0770d76429e7282c555a80058e.tar.gz lua-a290b84c670bbf0770d76429e7282c555a80058e.tar.bz2 lua-a290b84c670bbf0770d76429e7282c555a80058e.zip |
`dohook' to abstract `callhook' and `linehook'
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 42 |
1 files changed, 18 insertions, 24 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.90 2000/08/29 19:01:34 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.91 2000/08/29 20:43:28 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -28,13 +28,8 @@ | |||
28 | #include "lzio.h" | 28 | #include "lzio.h" |
29 | 29 | ||
30 | 30 | ||
31 | #define EXTRA_STACK 32 /* space to handle stack overflow errors */ | 31 | /* space to handle stack overflow errors */ |
32 | 32 | #define EXTRA_STACK (2*LUA_MINSTACK) | |
33 | /* | ||
34 | ** typical numer of stack slots used by a (big) function | ||
35 | ** (this constant is used only for choosing error messages) | ||
36 | */ | ||
37 | #define SLOTS_PER_F 20 | ||
38 | 33 | ||
39 | 34 | ||
40 | void luaD_init (lua_State *L, int stacksize) { | 35 | void luaD_init (lua_State *L, int stacksize) { |
@@ -93,20 +88,26 @@ static void luaD_openstack (lua_State *L, StkId pos) { | |||
93 | } | 88 | } |
94 | 89 | ||
95 | 90 | ||
91 | static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) { | ||
92 | StkId old_Cbase = L->Cbase; | ||
93 | StkId old_top = L->Cbase = L->top; | ||
94 | luaD_checkstack(L, LUA_MINSTACK); /* assures minimum stack size */ | ||
95 | L->allowhooks = 0; /* cannot call hooks inside a hook */ | ||
96 | (*hook)(L, ar); | ||
97 | LUA_ASSERT(L->allowhooks == 0, "invalid allow"); | ||
98 | L->allowhooks = 1; | ||
99 | L->top = old_top; | ||
100 | L->Cbase = old_Cbase; | ||
101 | } | ||
102 | |||
103 | |||
96 | void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook) { | 104 | void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook) { |
97 | if (L->allowhooks) { | 105 | if (L->allowhooks) { |
98 | lua_Debug ar; | 106 | lua_Debug ar; |
99 | StkId old_Cbase = L->Cbase; | ||
100 | StkId old_top = L->Cbase = L->top; | ||
101 | ar._func = func; | 107 | ar._func = func; |
102 | ar.event = "line"; | 108 | ar.event = "line"; |
103 | ar.currentline = line; | 109 | ar.currentline = line; |
104 | L->allowhooks = 0; /* cannot call hooks inside a hook */ | 110 | dohook(L, &ar, linehook); |
105 | (*linehook)(L, &ar); | ||
106 | LUA_ASSERT(L->allowhooks == 0, "invalid allow"); | ||
107 | L->allowhooks = 1; | ||
108 | L->top = old_top; | ||
109 | L->Cbase = old_Cbase; | ||
110 | } | 111 | } |
111 | } | 112 | } |
112 | 113 | ||
@@ -115,16 +116,9 @@ static void luaD_callHook (lua_State *L, StkId func, lua_Hook callhook, | |||
115 | const char *event) { | 116 | const char *event) { |
116 | if (L->allowhooks) { | 117 | if (L->allowhooks) { |
117 | lua_Debug ar; | 118 | lua_Debug ar; |
118 | StkId old_Cbase = L->Cbase; | ||
119 | StkId old_top = L->Cbase = L->top; | ||
120 | ar._func = func; | 119 | ar._func = func; |
121 | ar.event = event; | 120 | ar.event = event; |
122 | L->allowhooks = 0; /* cannot call hooks inside a hook */ | 121 | dohook(L, &ar, callhook); |
123 | (*callhook)(L, &ar); | ||
124 | LUA_ASSERT(L->allowhooks == 0, "invalid allow"); | ||
125 | L->allowhooks = 1; | ||
126 | L->top = old_top; | ||
127 | L->Cbase = old_Cbase; | ||
128 | } | 122 | } |
129 | } | 123 | } |
130 | 124 | ||