lzio.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. ** $Id: lzio.h,v 1.14 2002/10/08 18:46:08 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 char2int(c) cast(int, cast(unsigned char, (c)))
  12. #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
  13. #define zname(z) ((z)->name)
  14. void luaZ_init (ZIO *z, lua_Chunkreader reader, void *data, const char *name);
  15. size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
  16. int luaZ_lookahead (ZIO *z);
  17. typedef struct Mbuffer {
  18. char *buffer;
  19. size_t buffsize;
  20. } Mbuffer;
  21. char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
  22. #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
  23. #define luaZ_sizebuffer(buff) ((buff)->buffsize)
  24. #define luaZ_buffer(buff) ((buff)->buffer)
  25. #define luaZ_resizebuffer(L, buff, size) \
  26. (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
  27. (buff)->buffsize = size)
  28. #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
  29. /* --------- Private Part ------------------ */
  30. struct Zio {
  31. size_t n; /* bytes still unread */
  32. const char *p; /* current position in buffer */
  33. lua_Chunkreader reader;
  34. void* data; /* additional data */
  35. const char *name;
  36. };
  37. int luaZ_fill (ZIO *z);
  38. #endif