diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-10-30 14:25:59 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-10-30 14:25:59 -0300 |
| commit | 43c8e5bded052801f54a7439d18933b83570eb82 (patch) | |
| tree | 97f6d1e020110e14c798537c7bbb1f90feed4044 /lapi.c | |
| parent | b8b709b6d40c5c18d9b8ef33bb50afc55f048ab8 (diff) | |
| download | lua-43c8e5bded052801f54a7439d18933b83570eb82.tar.gz lua-43c8e5bded052801f54a7439d18933b83570eb82.tar.bz2 lua-43c8e5bded052801f54a7439d18933b83570eb82.zip | |
Full abstraction for representation of array values
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 31 |
1 files changed, 14 insertions, 17 deletions
| @@ -653,21 +653,17 @@ l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) { | |||
| 653 | } | 653 | } |
| 654 | 654 | ||
| 655 | 655 | ||
| 656 | /* | 656 | static void getGlobalTable (lua_State *L, TValue *gt) { |
| 657 | ** Get the global table in the registry. Since all predefined | 657 | Table *registry = hvalue(&G(L)->l_registry); |
| 658 | ** indices in the registry were inserted right when the registry | 658 | luaH_getint(registry, LUA_RIDX_GLOBALS, gt); |
| 659 | ** was created and never removed, they must always be in the array | 659 | } |
| 660 | ** part of the registry. | ||
| 661 | */ | ||
| 662 | #define getGtable(L) \ | ||
| 663 | (&hvalue(&G(L)->l_registry)->array[LUA_RIDX_GLOBALS - 1]) | ||
| 664 | 660 | ||
| 665 | 661 | ||
| 666 | LUA_API int lua_getglobal (lua_State *L, const char *name) { | 662 | LUA_API int lua_getglobal (lua_State *L, const char *name) { |
| 667 | const TValue *G; | 663 | TValue gt; |
| 668 | lua_lock(L); | 664 | lua_lock(L); |
| 669 | G = getGtable(L); | 665 | getGlobalTable(L, >); |
| 670 | return auxgetstr(L, G, name); | 666 | return auxgetstr(L, >, name); |
| 671 | } | 667 | } |
| 672 | 668 | ||
| 673 | 669 | ||
| @@ -840,10 +836,10 @@ static void auxsetstr (lua_State *L, const TValue *t, const char *k) { | |||
| 840 | 836 | ||
| 841 | 837 | ||
| 842 | LUA_API void lua_setglobal (lua_State *L, const char *name) { | 838 | LUA_API void lua_setglobal (lua_State *L, const char *name) { |
| 843 | const TValue *G; | 839 | TValue gt; |
| 844 | lua_lock(L); /* unlock done in 'auxsetstr' */ | 840 | lua_lock(L); /* unlock done in 'auxsetstr' */ |
| 845 | G = getGtable(L); | 841 | getGlobalTable(L, >); |
| 846 | auxsetstr(L, G, name); | 842 | auxsetstr(L, >, name); |
| 847 | } | 843 | } |
| 848 | 844 | ||
| 849 | 845 | ||
| @@ -1093,10 +1089,11 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, | |||
| 1093 | LClosure *f = clLvalue(s2v(L->top.p - 1)); /* get new function */ | 1089 | LClosure *f = clLvalue(s2v(L->top.p - 1)); /* get new function */ |
| 1094 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ | 1090 | if (f->nupvalues >= 1) { /* does it have an upvalue? */ |
| 1095 | /* get global table from registry */ | 1091 | /* get global table from registry */ |
| 1096 | const TValue *gt = getGtable(L); | 1092 | TValue gt; |
| 1093 | getGlobalTable(L, >); | ||
| 1097 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ | 1094 | /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ |
| 1098 | setobj(L, f->upvals[0]->v.p, gt); | 1095 | setobj(L, f->upvals[0]->v.p, >); |
| 1099 | luaC_barrier(L, f->upvals[0], gt); | 1096 | luaC_barrier(L, f->upvals[0], >); |
| 1100 | } | 1097 | } |
| 1101 | } | 1098 | } |
| 1102 | lua_unlock(L); | 1099 | lua_unlock(L); |
