9
3

lzio.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. ** $Id: lzio.h $
  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_buffremove(buff,i) ((buff)->n -= (i))
  23. #define luaZ_resetbuffer(buff) ((buff)->n = 0)
  24. #define luaZ_resizebuffer(L, buff, size) \
  25. ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \
  26. (buff)->buffsize, size), \
  27. (buff)->buffsize = size)
  28. #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
  29. LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
  30. void *data);
  31. LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */
  32. /* --------- Private Part ------------------ */
  33. struct Zio {
  34. size_t n; /* bytes still unread */
  35. const char *p; /* current position in buffer */
  36. lua_Reader reader; /* reader function */
  37. void *data; /* additional data */
  38. lua_State *L; /* Lua state (for reader) */
  39. };
  40. LUAI_FUNC int luaZ_fill (ZIO *z);
  41. #endif