diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-04-24 14:41:41 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-04-24 14:41:41 -0300 |
| commit | c65605151c5a335baf0a9ea251b19df5b2d3a905 (patch) | |
| tree | e85f4f108e452abe87f0f30e137e4f0fa5bb45f3 /lauxlib.h | |
| parent | 3da34a5fa70a51f0cf06d677a4f07b470693260c (diff) | |
| download | lua-c65605151c5a335baf0a9ea251b19df5b2d3a905.tar.gz lua-c65605151c5a335baf0a9ea251b19df5b2d3a905.tar.bz2 lua-c65605151c5a335baf0a9ea251b19df5b2d3a905.zip | |
New function 'luaL_addgsub'
Added a new function 'luaL_addgsub', similar to 'luaL_gsub' but that
adds its result directly to a preexisting buffer, avoiding the creation
of one extra intermediate string. Also added two simple macros,
'luaL_bufflen' and 'luaL_buffaddr', to query the current length
and the contents address of a buffer.
Diffstat (limited to 'lauxlib.h')
| -rw-r--r-- | lauxlib.h | 16 |
1 files changed, 12 insertions, 4 deletions
| @@ -19,6 +19,8 @@ | |||
| 19 | #define LUA_GNAME "_G" | 19 | #define LUA_GNAME "_G" |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | typedef struct luaL_Buffer luaL_Buffer; | ||
| 23 | |||
| 22 | 24 | ||
| 23 | /* extra error code for 'luaL_loadfilex' */ | 25 | /* extra error code for 'luaL_loadfilex' */ |
| 24 | #define LUA_ERRFILE (LUA_ERRERR+1) | 26 | #define LUA_ERRFILE (LUA_ERRERR+1) |
| @@ -99,8 +101,10 @@ LUALIB_API lua_State *(luaL_newstate) (void); | |||
| 99 | 101 | ||
| 100 | LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx); | 102 | LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx); |
| 101 | 103 | ||
| 102 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, | 104 | LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s, |
| 103 | const char *r); | 105 | const char *p, const char *r); |
| 106 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, | ||
| 107 | const char *p, const char *r); | ||
| 104 | 108 | ||
| 105 | LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); | 109 | LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); |
| 106 | 110 | ||
| @@ -155,7 +159,7 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, | |||
| 155 | ** ======================================================= | 159 | ** ======================================================= |
| 156 | */ | 160 | */ |
| 157 | 161 | ||
| 158 | typedef struct luaL_Buffer { | 162 | struct luaL_Buffer { |
| 159 | char *b; /* buffer address */ | 163 | char *b; /* buffer address */ |
| 160 | size_t size; /* buffer size */ | 164 | size_t size; /* buffer size */ |
| 161 | size_t n; /* number of characters in buffer */ | 165 | size_t n; /* number of characters in buffer */ |
| @@ -164,7 +168,11 @@ typedef struct luaL_Buffer { | |||
| 164 | LUAI_MAXALIGN; /* ensure maximum alignment for buffer */ | 168 | LUAI_MAXALIGN; /* ensure maximum alignment for buffer */ |
| 165 | char b[LUAL_BUFFERSIZE]; /* initial buffer */ | 169 | char b[LUAL_BUFFERSIZE]; /* initial buffer */ |
| 166 | } init; | 170 | } init; |
| 167 | } luaL_Buffer; | 171 | }; |
| 172 | |||
| 173 | |||
| 174 | #define luaL_bufflen(bf) ((bf)->n) | ||
| 175 | #define luaL_buffaddr(bf) ((bf)->b) | ||
| 168 | 176 | ||
| 169 | 177 | ||
| 170 | #define luaL_addchar(B,c) \ | 178 | #define luaL_addchar(B,c) \ |
