diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-11-19 15:29:23 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-11-19 15:29:23 -0200 |
commit | 592a3f289b428e3ee5cc595a266607ad7f5d94ff (patch) | |
tree | 19a371157be240f7e0f579117d04d466e911afcd /ltm.c | |
parent | 9cdeb275e7c93007b2ece6f81aaeafe530076805 (diff) | |
download | lua-github-592a3f289b428e3ee5cc595a266607ad7f5d94ff.tar.gz |
first implementation of centralized global state.
Diffstat (limited to 'ltm.c')
-rw-r--r-- | ltm.c | 38 |
1 files changed, 17 insertions, 21 deletions
@@ -1,5 +1,5 @@ /* -** $Id: ltm.c,v 1.6 1997/11/04 15:27:53 roberto Exp roberto $ +** $Id: ltm.c,v 1.7 1997/11/10 17:47:01 roberto Exp roberto $ ** Tag methods ** See Copyright Notice in lua.h */ @@ -9,9 +9,9 @@ #include <string.h> #include "lauxlib.h" -#include "ldo.h" #include "lmem.h" #include "lobject.h" +#include "lstate.h" #include "ltm.h" @@ -31,10 +31,6 @@ static int luaI_checkevent (char *name, char *list[]) } -struct IM *luaT_IMtable; -static int IMtable_size; -static int last_tag; - /* events in LUA_T_NIL are all allowed, since this is used as a * 'placeholder' for "default" fallbacks @@ -67,34 +63,34 @@ static void init_entry (int tag) void luaT_init (void) { int t; - IMtable_size = NUM_TAGS*2; - last_tag = -(NUM_TAGS-1); - luaT_IMtable = luaM_newvector(IMtable_size, struct IM); - for (t=last_tag; t<=0; t++) + L->IMtable_size = NUM_TAGS*2; + L->last_tag = -(NUM_TAGS-1); + L->IMtable = luaM_newvector(L->IMtable_size, struct IM); + for (t=L->last_tag; t<=0; t++) init_entry(t); } int lua_newtag (void) { - --last_tag; - if ((-last_tag) >= IMtable_size) - IMtable_size = luaM_growvector(&luaT_IMtable, IMtable_size, + --L->last_tag; + if ((-L->last_tag) >= L->IMtable_size) + L->IMtable_size = luaM_growvector(&L->IMtable, L->IMtable_size, struct IM, memEM, MAX_INT); - init_entry(last_tag); - return last_tag; + init_entry(L->last_tag); + return L->last_tag; } static void checktag (int tag) { - if (!(last_tag <= tag && tag <= 0)) + if (!(L->last_tag <= tag && tag <= 0)) luaL_verror("%d is not a valid tag", tag); } void luaT_realtag (int tag) { - if (!(last_tag <= tag && tag < LUA_T_NIL)) + if (!(L->last_tag <= tag && tag < LUA_T_NIL)) luaL_verror("tag %d is not result of `newtag'", tag); } @@ -145,11 +141,11 @@ void luaT_settagmethod (int t, char *event, TObject *func) char *luaT_travtagmethods (int (*fn)(TObject *)) { int e; - if (fn(&luaD_errorim)) + if (fn(&L->errorim)) return "error"; for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ int t; - for (t=0; t>=last_tag; t--) + for (t=0; t>=L->last_tag; t--) if (fn(luaT_getim(t,e))) return luaT_eventname[e]; } @@ -203,8 +199,8 @@ void luaT_setfallback (void) luaL_arg_check(lua_isfunction(func), 2, "function expected"); switch (luaO_findstring(name, oldnames)) { case 0: /* old error fallback */ - oldfunc = luaD_errorim; - luaD_errorim = *luaA_Address(func); + oldfunc = L->errorim; + L->errorim = *luaA_Address(func); replace = errorFB; break; case 1: /* old getglobal fallback */ |