* Packs all arguments as a stream for multiple upacking later. * Returns error if no arguments provided. */
| 510 | * Returns error if no arguments provided. |
| 511 | */ |
| 512 | int mp_pack(lua_State *L) { |
| 513 | int nargs = lua_gettop(L); |
| 514 | int i; |
| 515 | mp_buf *buf; |
| 516 | |
| 517 | if (nargs == 0) |
| 518 | return luaL_argerror(L, 0, "MessagePack pack needs input."); |
| 519 | |
| 520 | if (!lua_checkstack(L, nargs)) |
| 521 | return luaL_argerror(L, 0, "Too many arguments for MessagePack pack."); |
| 522 | |
| 523 | buf = mp_buf_new(L); |
| 524 | for(i = 1; i <= nargs; i++) { |
| 525 | /* Copy argument i to top of stack for _encode processing; |
| 526 | * the encode function pops it from the stack when complete. */ |
| 527 | luaL_checkstack(L, 1, "in function mp_check"); |
| 528 | lua_pushvalue(L, i); |
| 529 | |
| 530 | mp_encode_lua_type(L,buf,0); |
| 531 | |
| 532 | lua_pushlstring(L,(char*)buf->b,buf->len); |
| 533 | |
| 534 | /* Reuse the buffer for the next operation by |
| 535 | * setting its free count to the total buffer size |
| 536 | * and the current position to zero. */ |
| 537 | buf->free += buf->len; |
| 538 | buf->len = 0; |
| 539 | } |
| 540 | mp_buf_free(L, buf); |
| 541 | |
| 542 | /* Concatenate all nargs buffers together */ |
| 543 | lua_concat(L, nargs); |
| 544 | return 1; |
| 545 | } |
| 546 | |
| 547 | /* ------------------------------- Decoding --------------------------------- */ |
| 548 |
nothing calls this directly
no test coverage detected