| 1642 | } |
| 1643 | |
| 1644 | static void lpbE_encode(lpb_Env *e, const pb_Type *t, int idx) { |
| 1645 | lua_State *L = e->L; |
| 1646 | luaL_checkstack(L, 3, "message too many levels"); |
| 1647 | if (e->LS->encode_order) { |
| 1648 | const pb_Field *f = NULL; |
| 1649 | while (pb_nextfield(t, &f)) { |
| 1650 | if (lua53_getfield(L, idx, (const char*)f->name) != LUA_TNIL) |
| 1651 | lpb_encode_onefield(e, t, f, -1); |
| 1652 | lua_pop(L, 1); |
| 1653 | } |
| 1654 | } else { |
| 1655 | lua_pushnil(L); |
| 1656 | while (lua_next(L, lpb_relindex(idx, 1))) { |
| 1657 | if (lua_type(L, -2) == LUA_TSTRING) { |
| 1658 | const pb_Field *f = |
| 1659 | pb_fname(t, lpb_name(e->LS, lpb_toslice(L, -2))); |
| 1660 | if (f != NULL) lpb_encode_onefield(e, t, f, -1); |
| 1661 | } |
| 1662 | lua_pop(L, 1); |
| 1663 | } |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | static int Lpb_encode(lua_State *L) { |
| 1668 | lpb_State *LS = lpb_lstate(L); |
no test coverage detected