lzio.h 1.3 KB

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