Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lzio.h File Reference
#include "lua.h"
#include "lmem.h"

Go to the source code of this file.

Data Structures

struct  Mbuffer
 
struct  Zio
 

Macros

#define EOZ   (-1) /* end of stream */
 
#define char2int(c)   cast(int, cast(unsigned char, (c)))
 
#define zgetc(z)   (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
 
#define luaZ_initbuffer(L, buff)   ((buff)->buffer = NULL, (buff)->buffsize = 0)
 
#define luaZ_buffer(buff)   ((buff)->buffer)
 
#define luaZ_sizebuffer(buff)   ((buff)->buffsize)
 
#define luaZ_bufflen(buff)   ((buff)->n)
 
#define luaZ_resetbuffer(buff)   ((buff)->n = 0)
 
#define luaZ_resizebuffer(L, buff, size)
 
#define luaZ_freebuffer(L, buff)   luaZ_resizebuffer(L, buff, 0)
 

Typedefs

typedef struct Zio ZIO
 
typedef struct Mbuffer Mbuffer
 

Functions

LUAI_FUNC char * luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n)
 
LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data)
 
LUAI_FUNC size_t luaZ_read (ZIO *z, void *b, size_t n)
 
LUAI_FUNC int luaZ_lookahead (ZIO *z)
 
LUAI_FUNC int luaZ_fill (ZIO *z)
 

Macro Definition Documentation

◆ char2int

#define char2int ( c)    cast(int, cast(unsigned char, (c)))

Definition at line 20 of file lua-5.1.5/src/lzio.h.

Referenced by luaZ_fill(), and luaZ_lookahead().

◆ EOZ

◆ luaZ_buffer

◆ luaZ_bufflen

◆ luaZ_freebuffer

#define luaZ_freebuffer ( L,
buff )   luaZ_resizebuffer(L, buff, 0)

◆ luaZ_initbuffer

#define luaZ_initbuffer ( L,
buff )   ((buff)->buffer = NULL, (buff)->buffsize = 0)

Definition at line 30 of file lua-5.1.5/src/lzio.h.

Referenced by lua_newstate(), luaD_protectedparser(), and luaD_protectedparser().

◆ luaZ_resetbuffer

#define luaZ_resetbuffer ( buff)    ((buff)->n = 0)

◆ luaZ_resizebuffer

#define luaZ_resizebuffer ( L,
buff,
size )
Value:
(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
(buff)->buffsize = size)
#define luaM_reallocvector(L, v, oldn, n, t)

Definition at line 39 of file lua-5.1.5/src/lzio.h.

39#define luaZ_resizebuffer(L, buff, size) \
40 (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
41 (buff)->buffsize = size)

Referenced by checkSizes(), luaX_setinput(), luaX_setinput(), luaZ_openspace(), save(), save(), save(), and save().

◆ luaZ_sizebuffer

#define luaZ_sizebuffer ( buff)    ((buff)->buffsize)

Definition at line 33 of file lua-5.1.5/src/lzio.h.

Referenced by checkSizes(), save(), save(), and save().

◆ zgetc

#define zgetc ( z)    (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))

Definition at line 22 of file lua-5.1.5/src/lzio.h.

Referenced by f_parser(), f_parser(), f_parser(), and loadByte().

Typedef Documentation

◆ Mbuffer

typedef struct Mbuffer Mbuffer

◆ ZIO

typedef struct Zio ZIO

Definition at line 18 of file lua-5.1.5/src/lzio.h.

Function Documentation

◆ luaZ_fill()

LUAI_FUNC int luaZ_fill ( ZIO * z)

Definition at line 21 of file lua-5.1.5/src/lzio.c.

21 {
22 size_t size;
23 lua_State *L = z->L;
24 const char *buff;
25 lua_unlock(L);
26 buff = z->reader(L, z->data, &size);
27 lua_lock(L);
28 if (buff == NULL || size == 0) return EOZ;
29 z->n = size - 1;
30 z->p = buff;
31 return char2int(*(z->p++));
32}
#define NULL
Definition gmacros.h:924
#define lua_unlock(L)
#define lua_lock(L)
#define EOZ
#define char2int(c)
void * data
lua_Reader reader
lua_State * L
const char * p

◆ luaZ_init()

LUAI_FUNC void luaZ_init ( lua_State * L,
ZIO * z,
lua_Reader reader,
void * data )

Definition at line 48 of file lua-5.1.5/src/lzio.c.

48 {
49 z->L = L;
50 z->reader = reader;
51 z->data = data;
52 z->n = 0;
53 z->p = NULL;
54}
static const char * reader(lua_State *L, void *ud, size_t *size)

◆ luaZ_lookahead()

LUAI_FUNC int luaZ_lookahead ( ZIO * z)

Definition at line 35 of file lua-5.1.5/src/lzio.c.

35 {
36 if (z->n == 0) {
37 if (luaZ_fill(z) == EOZ)
38 return EOZ;
39 else {
40 z->n++; /* luaZ_fill removed first byte; put back it */
41 z->p--;
42 }
43 }
44 return char2int(*z->p);
45}
int luaZ_fill(ZIO *z)

References char2int, EOZ, luaZ_fill(), Zio::n, and Zio::p.

Referenced by f_parser(), and luaZ_read().

◆ luaZ_openspace()

LUAI_FUNC char * luaZ_openspace ( lua_State * L,
Mbuffer * buff,
size_t n )

Definition at line 74 of file lua-5.1.5/src/lzio.c.

74 {
75 if (n > buff->buffsize) {
76 if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;
77 luaZ_resizebuffer(L, buff, n);
78 }
79 return buff->buffer;
80}
#define LUA_MINBUFFER
#define luaZ_resizebuffer(L, buff, size)

◆ luaZ_read()

LUAI_FUNC size_t luaZ_read ( ZIO * z,
void * b,
size_t n )

Definition at line 58 of file lua-5.1.5/src/lzio.c.

58 {
59 while (n) {
60 size_t m;
61 if (luaZ_lookahead(z) == EOZ)
62 return n; /* return number of missing bytes */
63 m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
64 memcpy(b, z->p, m);
65 z->n -= m;
66 z->p += m;
67 b = (char *)b + m;
68 n -= m;
69 }
70 return 0;
71}
int luaZ_lookahead(ZIO *z)