| 1527 | } |
| 1528 | |
| 1529 | static void lpbE_enum(lpb_Env *e, const pb_Field *f, int idx) { |
| 1530 | lua_State *L = e->L; |
| 1531 | pb_Buffer *b = e->b; |
| 1532 | const pb_Field *ev; |
| 1533 | int type = lua_type(L, idx); |
| 1534 | if (type == LUA_TNUMBER) |
| 1535 | pb_addvarint64(b, (uint64_t)lua_tonumber(L, idx)); |
| 1536 | else if ((ev = pb_fname(f->type, |
| 1537 | lpb_name(e->LS, lpb_toslice(L, idx)))) != NULL) |
| 1538 | pb_addvarint32(b, ev->number); |
| 1539 | else if (type != LUA_TSTRING) |
| 1540 | argcheck(L, 0, 2, "number/string expected at field '%s', got %s", |
| 1541 | (const char*)f->name, luaL_typename(L, idx)); |
| 1542 | else { |
| 1543 | uint64_t v = lpb_tointegerx(L, idx, &type); |
| 1544 | if (!type) |
| 1545 | argcheck(L, 0, 2, "can not encode unknown enum '%s' at field '%s'", |
| 1546 | lua_tostring(L, -1), (const char*)f->name); |
| 1547 | pb_addvarint64(b, v); |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | static void lpbE_field(lpb_Env *e, const pb_Field *f, size_t *plen, int idx) { |
| 1552 | lua_State *L = e->L; |
no test coverage detected