- Main Page
- Classes
- Files

# lzio.h

Go to the documentation of this file.

    00001 /*
    00002 ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $
    00003 ** Buffered streams
    00004 ** See Copyright Notice in lua.h
    00005 */
    00006
    00007
    00008 #ifndef lzio_h
    00009 #define lzio_h
    00010
    00011 #include "lua.h"
    00012
    00013 #include "lmem.h"
    00014
    00015
    00016 #define EOZ     (-1)                    /* end of stream */
    00017
    00018 typedef struct Zio ZIO;
    00019
    00020 #define char2int(c)     cast(int, cast(unsigned char, (c)))
    00021
    00022 #define zgetc(z)  (((z)->n--)>0 ?  char2int(*(z)->p++) : luaZ_fill(z))
    00023
    00024 typedef struct Mbuffer {
    00025   char *buffer;
    00026   size_t n;
    00027   size_t buffsize;
    00028 } Mbuffer;
    00029
    00030 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
    00031
    00032 #define luaZ_buffer(buff)       ((buff)->buffer)
    00033 #define luaZ_sizebuffer(buff)   ((buff)->buffsize)
    00034 #define luaZ_bufflen(buff)      ((buff)->n)
    00035
    00036 #define luaZ_resetbuffer(buff) ((buff)->n = 0)
    00037
    00038
    00039 #define luaZ_resizebuffer(L, buff, size) \
    00040         (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
    00041         (buff)->buffsize = size)
    00042
    00043 #define luaZ_freebuffer(L, buff)        luaZ_resizebuffer(L, buff, 0)
    00044
    00045
    00046 LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
    00047 LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
    00048                                         void *data);
    00049 LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
    00050 LUAI_FUNC int luaZ_lookahead (ZIO *z);
    00051
    00052
    00053
    00054 /* --------- Private Part ------------------ */
    00055
    00056 struct Zio {
    00057   size_t n;                     /* bytes still unread */
    00058   const char *p;                /* current position in buffer */
    00059   lua_Reader reader;
    00060   void* data;                   /* additional data */
    00061   lua_State *L;                 /* Lua state (for reader) */
    00062 };
    00063
    00064
    00065 LUAI_FUNC int luaZ_fill (ZIO *z);
    00066
    00067 #endif