** ensure that stack[idx][fname] has a table and push that table ** into the stack */
| 2951 | ** into the stack |
| 2952 | */ |
| 2953 | LUALIB_API int luaL_getsubtable(lua_State *L, int idx, const char *fname) { |
| 2954 | if (lua_getfield(L, idx, fname) == LUA_TTABLE) |
| 2955 | return 1; /* table already there */ |
| 2956 | else { |
| 2957 | lua_pop(L, 1); /* remove previous result */ |
| 2958 | idx = lua_absindex(L, idx); |
| 2959 | lua_newtable(L); |
| 2960 | lua_pushvalue(L, -1); /* copy to be left at top */ |
| 2961 | lua_setfield(L, idx, fname); /* assign new table to field */ |
| 2962 | return 0; /* false, because did not find table there */ |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | |
| 2967 | /* |
no test coverage detected