MCPcopy Create free account
hub / github.com/Tencent/UnLua / lpbE_enum

Function lpbE_enum

Plugins/UnLuaExtensions/LuaProtobuf/Source/src/pb.cpp:1529–1549  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1527}
1528
1529static 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
1551static void lpbE_field(lpb_Env *e, const pb_Field *f, size_t *plen, int idx) {
1552 lua_State *L = e->L;

Callers 1

lpbE_fieldFunction · 0.85

Calls 7

lua_typeFunction · 0.85
pb_addvarint64Function · 0.85
pb_fnameFunction · 0.85
lpb_tosliceFunction · 0.85
pb_addvarint32Function · 0.85
argcheckFunction · 0.85
lpb_tointegerxFunction · 0.85

Tested by

no test coverage detected