native Lua  0.5.0-devel
Lua on the platform you use with the compiler you choose
lzio.h
Go to the documentation of this file.
1 /*
2 ** $Id: lzio.h $
3 ** Buffered streams
4 ** See Copyright Notice in lua.h
5 */
6 
7 
8 #ifndef lzio_h
9 #define lzio_h
10 
11 #include "lua.h"
12 
13 #include "lmem.h"
14 
15 #include "_native_lua_config.h" /* native Lua */
16 
17 
18 #define EOZ (-1) /* end of stream */
19 
20 typedef struct Zio ZIO;
21 
22 #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z))
23 
24 
25 typedef struct Mbuffer {
26  char *buffer;
27  size_t n;
28  size_t buffsize;
30 
31 #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
32 
33 #define luaZ_buffer(buff) ((buff)->buffer)
34 #define luaZ_sizebuffer(buff) ((buff)->buffsize)
35 #define luaZ_bufflen(buff) ((buff)->n)
36 
37 #define luaZ_buffremove(buff,i) ((buff)->n -= (i))
38 #define luaZ_resetbuffer(buff) ((buff)->n = 0)
39 
40 
41 #define luaZ_resizebuffer(L, buff, size) \
42  ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \
43  (buff)->buffsize, size), \
44  (buff)->buffsize = size)
45 
46 #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
47 
48 
49 LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
50  void *data);
51 LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */
52 
53 
54 
55 /* --------- Private Part ------------------ */
56 
57 struct Zio {
58  size_t n; /* bytes still unread */
59  const char *p; /* current position in buffer */
60  lua_Reader reader; /* reader function */
61  void *data; /* additional data */
62  lua_State *L; /* Lua state (for reader) */
63 };
64 
65 
66 LUAI_FUNC int luaZ_fill (ZIO *z);
67 
68 #endif
LUAI_FUNC
#define LUAI_FUNC
Definition: luaconf.h:324
Mbuffer::buffer
char * buffer
Definition: lzio.h:26
luaZ_init
LUAI_FUNC void luaZ_init(lua_State *L, ZIO *z, lua_Reader reader, void *data)
Definition: lzio.c:38
Zio::reader
lua_Reader reader
Definition: lzio.h:60
_native_lua_config.h
native Lua configuration file
Zio::p
const char * p
Definition: lzio.h:59
Zio::L
lua_State * L
Definition: lzio.h:62
luaZ_fill
LUAI_FUNC int luaZ_fill(ZIO *z)
Definition: lzio.c:23
Mbuffer
Definition: lzio.h:25
lua.h
Mbuffer
struct Mbuffer Mbuffer
luaZ_read
LUAI_FUNC size_t luaZ_read(ZIO *z, void *b, size_t n)
Definition: lzio.c:48
Mbuffer::n
size_t n
Definition: lzio.h:27
Mbuffer::buffsize
size_t buffsize
Definition: lzio.h:28
lua_State
Definition: lstate.h:283
Zio::n
size_t n
Definition: lzio.h:58
lmem.h
Zio::data
void * data
Definition: lzio.h:61
lua_Reader
const char *(* lua_Reader)(lua_State *L, void *ud, size_t *sz)
Definition: lua.h:119
Zio
Definition: lzio.h:57