diff options
Diffstat (limited to 'src/lua/lapi.c')
| -rw-r--r-- | src/lua/lapi.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/lua/lapi.c b/src/lua/lapi.c index c824da2..03e756d 100644 --- a/src/lua/lapi.c +++ b/src/lua/lapi.c | |||
| @@ -629,11 +629,21 @@ static int auxgetstr (lua_State *L, const TValue *t, const char *k) { | |||
| 629 | } | 629 | } |
| 630 | 630 | ||
| 631 | 631 | ||
| 632 | /* | ||
| 633 | ** Get the global table in the registry. Since all predefined | ||
| 634 | ** indices in the registry were inserted right when the registry | ||
| 635 | ** was created and never removed, they must always be in the array | ||
| 636 | ** part of the registry. | ||
| 637 | */ | ||
| 638 | #define getGtable(L) \ | ||
| 639 | (&hvalue(&G(L)->l_registry)->array[LUA_RIDX_GLOBALS - 1]) | ||
| 640 | |||
| 641 | |||
| 632 | LUA_API int lua_getglobal (lua_State *L, const char *name) { | 642 | LUA_API int lua_getglobal (lua_State *L, const char *name) { |
| 633 | Table *reg; | 643 | const TValue *G; |
| 634 | lua_lock(L); | 644 | lua_lock(L); |
| 635 | reg = hvalue(&G(L)->l_registry); | 645 | G = getGtable(L); |
| 636 | return auxgetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name); | 646 | return auxgetstr(L, G, name); |
| 637 | } | 647 | } |
| 638 | 648 | ||
| 639 | 649 | ||
| @@ -811,10 +821,10 @@ static void auxsetstr (lua_State *L, const TValue *t, const char *k) { | |||
| 811 | 821 | ||
| 812 | 822 | ||
| 813 | LUA_API void lua_setglobal (lua_State *L, const char *name) { | 823 | LUA_API void lua_setglobal (lua_State *L, const char *name) { |
| 814 | Table *reg; | 824 | const TValue *G; |
| 815 | lua_lock(L); /* unlock done in 'auxsetstr' */ | 825 | lua_lock(L); /* unlock done in 'auxsetstr' */ |
| 816 | reg = hvalue(&G(L)->l_registry); | 826 | G = getGtable(L); |
| 817 | auxsetstr(L, luaH_getint(reg, LUA_RIDX_GLOBALS), name); | 827 | auxsetstr(L, G, name); |
| 818 | } | 828 | } |
| 819 | 829 | ||
| 820 | 830 | ||
| @@ -861,12 +871,10 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { | |||
| 861 | 871 | ||
| 862 | static void aux_rawset (lua_State *L, int idx, TValue *key, int n) { | 872 | static void aux_rawset (lua_State *L, int idx, TValue *key, int n) { |
| 863 | Table *t; | 873 | Table *t; |
| 864 | TValue *slot; | ||
| 865 | lua_lock(L); | 874 | lua_lock(L); |
| 866 | api_checknelems(L, n); | 875 | api_checknelems(L, n); |
| 867 | t = gettable(L, idx); | 876 | t = gettable(L, idx); |
| 868 | slot = luaH_set(L, t, key); | 877 | luaH_set(L, t, key, s2v(L->top - 1)); |
| 869 | setobj2t(L, slot, s2v(L->top - 1)); | ||
| 870 | invalidateTMcache(t); | 878 | invalidateTMcache(t); |
| 871 | luaC_barrierback(L, obj2gco(t), s2v(L->top - 1)); | 879 | luaC_barrierback(L, obj2gco(t), s2v(L->top - 1)); |
| 872 | L->top -= n; | 880 | L->top -= n; |
| @@ -1063,8 +1071,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, | |||
| 1063 | LClosure *f = clLvalue(s2v(L->top - 1)); /* get newly created function */ | 1071 | LClosure *f = clLvalue(s2v(L->top - 1)); /* get newly created function */ |
| 1064 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ | 1072 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ |
| 1065 | /* get global table from registry */ | 1073 | /* get global table from registry */ |
| 1066 | Table *reg = hvalue(&G(L)->l_registry); | 1074 | const TValue *gt = getGtable(L); |
| 1067 | const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); | ||
| 1068 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ | 1075 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ |
| 1069 | setobj(L, f->upvals[0]->v, gt); | 1076 | setobj(L, f->upvals[0]->v, gt); |
| 1070 | luaC_barrier(L, f->upvals[0], gt); | 1077 | luaC_barrier(L, f->upvals[0], gt); |
