annotate src/lua/lzio.h @ 198:5055ec9de278

competed move-table printing component of pokemon printing function.
author Robert McIntyre <rlm@mit.edu>
date Fri, 23 Mar 2012 00:30:34 -0500
parents 27763b933818
children
rev   line source
rlm@1 1 /*
rlm@1 2 ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $
rlm@1 3 ** Buffered streams
rlm@1 4 ** See Copyright Notice in lua.h
rlm@1 5 */
rlm@1 6
rlm@1 7
rlm@1 8 #ifndef lzio_h
rlm@1 9 #define lzio_h
rlm@1 10
rlm@1 11 #include "lua.h"
rlm@1 12
rlm@1 13 #include "lmem.h"
rlm@1 14
rlm@1 15
rlm@1 16 #define EOZ (-1) /* end of stream */
rlm@1 17
rlm@1 18 typedef struct Zio ZIO;
rlm@1 19
rlm@1 20 #define char2int(c) cast(int, cast(unsigned char, (c)))
rlm@1 21
rlm@1 22 #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
rlm@1 23
rlm@1 24 typedef struct Mbuffer {
rlm@1 25 char *buffer;
rlm@1 26 size_t n;
rlm@1 27 size_t buffsize;
rlm@1 28 } Mbuffer;
rlm@1 29
rlm@1 30 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
rlm@1 31
rlm@1 32 #define luaZ_buffer(buff) ((buff)->buffer)
rlm@1 33 #define luaZ_sizebuffer(buff) ((buff)->buffsize)
rlm@1 34 #define luaZ_bufflen(buff) ((buff)->n)
rlm@1 35
rlm@1 36 #define luaZ_resetbuffer(buff) ((buff)->n = 0)
rlm@1 37
rlm@1 38
rlm@1 39 #define luaZ_resizebuffer(L, buff, size) \
rlm@1 40 (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
rlm@1 41 (buff)->buffsize = size)
rlm@1 42
rlm@1 43 #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
rlm@1 44
rlm@1 45
rlm@1 46 LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
rlm@1 47 LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
rlm@1 48 void *data);
rlm@1 49 LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
rlm@1 50 LUAI_FUNC int luaZ_lookahead (ZIO *z);
rlm@1 51
rlm@1 52
rlm@1 53
rlm@1 54 /* --------- Private Part ------------------ */
rlm@1 55
rlm@1 56 struct Zio {
rlm@1 57 size_t n; /* bytes still unread */
rlm@1 58 const char *p; /* current position in buffer */
rlm@1 59 lua_Reader reader;
rlm@1 60 void* data; /* additional data */
rlm@1 61 lua_State *L; /* Lua state (for reader) */
rlm@1 62 };
rlm@1 63
rlm@1 64
rlm@1 65 LUAI_FUNC int luaZ_fill (ZIO *z);
rlm@1 66
rlm@1 67 #endif