diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-23 10:16:18 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-23 10:16:18 -0300 |
| commit | 9243c414d92c253edd908f438caa31e2aa16f3f4 (patch) | |
| tree | e8959a48f4672037aef061cc6eb82bba21d0766b /lapi.c | |
| parent | 477ca2fe8ceaf79038972977915987adbef0e425 (diff) | |
| download | lua-9243c414d92c253edd908f438caa31e2aa16f3f4.tar.gz lua-9243c414d92c253edd908f438caa31e2aa16f3f4.tar.bz2 lua-9243c414d92c253edd908f438caa31e2aa16f3f4.zip | |
first version of empty entries in tables
(so that, in the future, tables can contain regular nil entries)
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 30 |
1 files changed, 18 insertions, 12 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.283 2018/02/05 17:10:52 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.285 2018/02/20 16:52:50 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -657,14 +657,26 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { | |||
| 657 | } | 657 | } |
| 658 | 658 | ||
| 659 | 659 | ||
| 660 | static int finishrawget (lua_State *L, const TValue *val) { | ||
| 661 | if (isempty(val)) /* avoid copying empty items to the stack */ | ||
| 662 | setnilvalue(s2v(L->top)); | ||
| 663 | else | ||
| 664 | setobj2s(L, L->top, val); | ||
| 665 | api_incr_top(L); | ||
| 666 | lua_unlock(L); | ||
| 667 | return ttnov(s2v(L->top - 1)); | ||
| 668 | } | ||
| 669 | |||
| 670 | |||
| 660 | LUA_API int lua_rawget (lua_State *L, int idx) { | 671 | LUA_API int lua_rawget (lua_State *L, int idx) { |
| 661 | TValue *t; | 672 | TValue *t; |
| 673 | const TValue *val; | ||
| 662 | lua_lock(L); | 674 | lua_lock(L); |
| 663 | t = index2value(L, idx); | 675 | t = index2value(L, idx); |
| 664 | api_check(L, ttistable(t), "table expected"); | 676 | api_check(L, ttistable(t), "table expected"); |
| 665 | setobj2s(L, L->top - 1, luaH_get(hvalue(t), s2v(L->top - 1))); | 677 | val = luaH_get(hvalue(t), s2v(L->top - 1)); |
| 666 | lua_unlock(L); | 678 | L->top--; /* remove key */ |
| 667 | return ttnov(s2v(L->top - 1)); | 679 | return finishrawget(L, val); |
| 668 | } | 680 | } |
| 669 | 681 | ||
| 670 | 682 | ||
| @@ -673,10 +685,7 @@ LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { | |||
| 673 | lua_lock(L); | 685 | lua_lock(L); |
| 674 | t = index2value(L, idx); | 686 | t = index2value(L, idx); |
| 675 | api_check(L, ttistable(t), "table expected"); | 687 | api_check(L, ttistable(t), "table expected"); |
| 676 | setobj2s(L, L->top, luaH_getint(hvalue(t), n)); | 688 | return finishrawget(L, luaH_getint(hvalue(t), n)); |
| 677 | api_incr_top(L); | ||
| 678 | lua_unlock(L); | ||
| 679 | return ttnov(s2v(L->top - 1)); | ||
| 680 | } | 689 | } |
| 681 | 690 | ||
| 682 | 691 | ||
| @@ -687,10 +696,7 @@ LUA_API int lua_rawgetp (lua_State *L, int idx, const void *p) { | |||
| 687 | t = index2value(L, idx); | 696 | t = index2value(L, idx); |
| 688 | api_check(L, ttistable(t), "table expected"); | 697 | api_check(L, ttistable(t), "table expected"); |
| 689 | setpvalue(&k, cast_voidp(p)); | 698 | setpvalue(&k, cast_voidp(p)); |
| 690 | setobj2s(L, L->top, luaH_get(hvalue(t), &k)); | 699 | return finishrawget(L, luaH_get(hvalue(t), &k)); |
| 691 | api_incr_top(L); | ||
| 692 | lua_unlock(L); | ||
| 693 | return ttnov(s2v(L->top - 1)); | ||
| 694 | } | 700 | } |
| 695 | 701 | ||
| 696 | 702 | ||
