1 /* BEGIN CSTYLED */ 2 /* 3 ** $Id: lzio.h,v 1.26.1.1 2013/04/12 18:48:47 roberto Exp $ 4 ** Buffered streams 5 ** See Copyright Notice in lua.h 6 */ 7 8 9 #ifndef lzio_h 10 #define lzio_h 11 12 #include <sys/lua/lua.h> 13 14 #include "lmem.h" 15 16 17 #define EOZ (-1) /* end of stream */ 18 19 typedef struct Zio ZIO; 20 21 #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 22 23 24 typedef struct Mbuffer { 25 char *buffer; 26 size_t n; 27 size_t buffsize; 28 } Mbuffer; 29 30 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 31 32 #define luaZ_buffer(buff) ((buff)->buffer) 33 #define luaZ_sizebuffer(buff) ((buff)->buffsize) 34 #define luaZ_bufflen(buff) ((buff)->n) 35 36 #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 38 39 #define luaZ_resizebuffer(L, buff, size) \ 40 (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 41 (buff)->buffsize = size) 42 43 #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 44 45 46 LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 47 LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 void *data); 49 LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 50 51 52 53 /* --------- Private Part ------------------ */ 54 55 struct Zio { 56 size_t n; /* bytes still unread */ 57 const char *p; /* current position in buffer */ 58 lua_Reader reader; /* reader function */ 59 void* data; /* additional data */ 60 lua_State *L; /* Lua state (for reader) */ 61 }; 62 63 64 LUAI_FUNC int luaZ_fill (ZIO *z); 65 66 #endif 67 /* END CSTYLED */ 68