diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-05-16 16:21:11 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-05-16 16:21:11 -0300 |
commit | da32450c3d4c8abd3fd6709692859a12a8886511 (patch) | |
tree | a75289cd092dd6cbd9e454c9689de3b9c4d5de33 /lauxlib.c | |
parent | a2b78aad49388c1fd5286773085ef8a35545faa6 (diff) | |
download | lua-da32450c3d4c8abd3fd6709692859a12a8886511.tar.gz lua-da32450c3d4c8abd3fd6709692859a12a8886511.tar.bz2 lua-da32450c3d4c8abd3fd6709692859a12a8886511.zip |
new API function `lua_tolstring'
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.129 2005/02/23 17:30:22 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.130 2005/03/16 16:58:41 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 | */ |
@@ -158,9 +158,8 @@ LUALIB_API void luaL_checkany (lua_State *L, int narg) { | |||
158 | 158 | ||
159 | 159 | ||
160 | LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { | 160 | LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { |
161 | const char *s = lua_tostring(L, narg); | 161 | const char *s = lua_tolstring(L, narg, len); |
162 | if (!s) tag_error(L, narg, LUA_TSTRING); | 162 | if (!s) tag_error(L, narg, LUA_TSTRING); |
163 | if (len) *len = lua_strlen(L, narg); | ||
164 | return s; | 163 | return s; |
165 | } | 164 | } |
166 | 165 | ||
@@ -497,9 +496,10 @@ LUALIB_API void luaL_pushresult (luaL_Buffer *B) { | |||
497 | 496 | ||
498 | LUALIB_API void luaL_addvalue (luaL_Buffer *B) { | 497 | LUALIB_API void luaL_addvalue (luaL_Buffer *B) { |
499 | lua_State *L = B->L; | 498 | lua_State *L = B->L; |
500 | size_t vl = lua_strlen(L, -1); | 499 | size_t vl; |
500 | const char *s = lua_tolstring(L, -1, &vl); | ||
501 | if (vl <= bufffree(B)) { /* fit into buffer? */ | 501 | if (vl <= bufffree(B)) { /* fit into buffer? */ |
502 | memcpy(B->p, lua_tostring(L, -1), vl); /* put it there */ | 502 | memcpy(B->p, s, vl); /* put it there */ |
503 | B->p += vl; | 503 | B->p += vl; |
504 | lua_pop(L, 1); /* remove from stack */ | 504 | lua_pop(L, 1); /* remove from stack */ |
505 | } | 505 | } |