Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:37:58

0001 /*
0002 ** $Id: lzio.h $
0003 ** Buffered streams
0004 ** See Copyright Notice in lua.h
0005 */
0006 
0007 
0008 #ifndef lzio_h
0009 #define lzio_h
0010 
0011 #include "lua.h"
0012 
0013 #include "lmem.h"
0014 
0015 
0016 #define EOZ (-1)            /* end of stream */
0017 
0018 typedef struct Zio ZIO;
0019 
0020 #define zgetc(z)  (((z)->n--)>0 ?  cast_uchar(*(z)->p++) : luaZ_fill(z))
0021 
0022 
0023 typedef struct Mbuffer {
0024   char *buffer;
0025   size_t n;
0026   size_t buffsize;
0027 } Mbuffer;
0028 
0029 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
0030 
0031 #define luaZ_buffer(buff)   ((buff)->buffer)
0032 #define luaZ_sizebuffer(buff)   ((buff)->buffsize)
0033 #define luaZ_bufflen(buff)  ((buff)->n)
0034 
0035 #define luaZ_buffremove(buff,i) ((buff)->n -= (i))
0036 #define luaZ_resetbuffer(buff) ((buff)->n = 0)
0037 
0038 
0039 #define luaZ_resizebuffer(L, buff, size) \
0040     ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \
0041                 (buff)->buffsize, size), \
0042     (buff)->buffsize = size)
0043 
0044 #define luaZ_freebuffer(L, buff)    luaZ_resizebuffer(L, buff, 0)
0045 
0046 
0047 LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
0048                                         void *data);
0049 LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */
0050 
0051 
0052 
0053 /* --------- Private Part ------------------ */
0054 
0055 struct Zio {
0056   size_t n;         /* bytes still unread */
0057   const char *p;        /* current position in buffer */
0058   lua_Reader reader;        /* reader function */
0059   void *data;           /* additional data */
0060   lua_State *L;         /* Lua state (for reader) */
0061 };
0062 
0063 
0064 LUAI_FUNC int luaZ_fill (ZIO *z);
0065 
0066 #endif