Example #1
0
    void msgpack_pack(Packer& pk) const
    {
        static_assert(sizeof...(Args) % 2 == 0, "");
        pk.pack_map(sizeof...(Args) / 2);

        define_map_imp<std::tuple<Args&...>, sizeof...(Args)>::pack(pk, a);
    }
  void packTableAsTable(Packer& pk, int index) const {
    // calc the size of the table
    // TODO: Make this faster!!
    size_t len = 0;
    lua_pushnil(L);
    while (lua_next(L, index) != 0) {
      len++; lua_pop(L, 1);
    }
    pk.pack_map(len);

    int n = lua_gettop(L); // used as a positive index
    lua_pushnil(L);
    while (lua_next(L, index) != 0) {  
      pack(pk, n + 1); // -2:key
      pack(pk, n + 2); // -1:value
      lua_pop(L, 1); // removes value, keeps key for next iteration
    }
  }