lzio.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. ** $Id: lzio.h,v 1.26 2011/07/15 12:48:03 roberto Exp $
  3. ** Buffered streams
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lzio_h
  7. #define lzio_h
  8. #include "lua.h"
  9. #include "lmem.h"
  10. #define EOZ (-1) /* end of stream */
  11. typedef struct Zio ZIO;
  12. #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z))
  13. typedef struct Mbuffer {
  14. char *buffer;
  15. size_t n;
  16. size_t buffsize;
  17. } Mbuffer;
  18. #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
  19. #define luaZ_buffer(buff) ((buff)->buffer)
  20. #define luaZ_sizebuffer(buff) ((buff)->buffsize)
  21. #define luaZ_bufflen(buff) ((buff)->n)
  22. #define luaZ_resetbuffer(buff) ((buff)->n = 0)
  23. #define luaZ_resizebuffer(L, buff, size) \
  24. (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
  25. (buff)->buffsize = size)
  26. #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
  27. LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
  28. LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
  29. void *data);
  30. LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
  31. /* --------- Private Part ------------------ */
  32. struct Zio {
  33. size_t n; /* bytes still unread */
  34. const char *p; /* current position in buffer */
  35. lua_Reader reader; /* reader function */
  36. void* data; /* additional data */
  37. lua_State *L; /* Lua state (for reader) */
  38. };
  39. LUAI_FUNC int luaZ_fill (ZIO *z);
  40. #endif