diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-09 13:14:46 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-04-09 13:14:46 -0300 |
commit | 9100f7479afabc4bb2926c619b5ef09693cf9a94 (patch) | |
tree | ed07e9aa37c8f7f4d8282d4d21670c85ea9b6a6c /lauxlib.h | |
parent | 055104f5b6a0264974c5d9f2a55499420a1c9c2a (diff) | |
download | lua-9100f7479afabc4bb2926c619b5ef09693cf9a94.tar.gz lua-9100f7479afabc4bb2926c619b5ef09693cf9a94.tar.bz2 lua-9100f7479afabc4bb2926c619b5ef09693cf9a94.zip |
new implementation for Generic Buffer manipulation (using userdata as
temporary buffer space)
Diffstat (limited to 'lauxlib.h')
-rw-r--r-- | lauxlib.h | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.h,v 1.100 2010/01/21 16:49:21 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.101 2010/03/17 21:37:37 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -122,28 +122,31 @@ LUALIB_API int (luaL_cpcall) (lua_State *L, lua_CFunction f, int nargs, | |||
122 | ** ======================================================= | 122 | ** ======================================================= |
123 | */ | 123 | */ |
124 | 124 | ||
125 | |||
126 | |||
127 | typedef struct luaL_Buffer { | 125 | typedef struct luaL_Buffer { |
128 | char *p; /* current position in buffer */ | 126 | char *b; /* buffer address */ |
129 | int lvl; /* number of strings in the stack (level) */ | 127 | size_t size; /* buffer size */ |
128 | size_t n; /* number of characters in buffer */ | ||
130 | lua_State *L; | 129 | lua_State *L; |
131 | char buffer[LUAL_BUFFERSIZE]; | 130 | char initb[LUAL_BUFFERSIZE]; /* initial buffer */ |
132 | } luaL_Buffer; | 131 | } luaL_Buffer; |
133 | 132 | ||
133 | |||
134 | #define luaL_addchar(B,c) \ | 134 | #define luaL_addchar(B,c) \ |
135 | ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ | 135 | ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \ |
136 | (*(B)->p++ = (char)(c))) | 136 | ((B)->b[(B)->n++] = (c))) |
137 | 137 | ||
138 | #define luaL_addsize(B,n) ((B)->p += (n)) | 138 | #define luaL_addsize(B,s) ((B)->n += (s)) |
139 | 139 | ||
140 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); | 140 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); |
141 | LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); | 141 | LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz); |
142 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); | 142 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); |
143 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); | 143 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); |
144 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); | 144 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); |
145 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); | 145 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); |
146 | LUALIB_API void luaL_pushresultsize (luaL_Buffer *B, size_t sz); | ||
147 | LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz); | ||
146 | 148 | ||
149 | #define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE) | ||
147 | 150 | ||
148 | /* }====================================================== */ | 151 | /* }====================================================== */ |
149 | 152 | ||