diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-04-17 10:19:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-04-17 10:19:53 -0300 |
commit | 619be354c8e38b53d36930dc6f7f1242cd2d853f (patch) | |
tree | d3d82ba3deecf1ec6d52e384879f1233b445ab09 | |
parent | 94d40f3980d4f13ed33d1c23fcc8c7aafbd7be59 (diff) | |
download | lua-619be354c8e38b53d36930dc6f7f1242cd2d853f.tar.gz lua-619be354c8e38b53d36930dc6f7f1242cd2d853f.tar.bz2 lua-619be354c8e38b53d36930dc6f7f1242cd2d853f.zip |
lua_pushstring/pushlstring return string
-rw-r--r-- | lapi.c | 17 | ||||
-rw-r--r-- | ltests.c | 5 | ||||
-rw-r--r-- | lua.h | 12 |
3 files changed, 20 insertions, 14 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.58 2006/10/17 20:00:07 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.59 2007/02/07 14:28:00 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -415,20 +415,25 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { | |||
415 | } | 415 | } |
416 | 416 | ||
417 | 417 | ||
418 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { | 418 | LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { |
419 | TString *ts; | ||
419 | lua_lock(L); | 420 | lua_lock(L); |
420 | luaC_checkGC(L); | 421 | luaC_checkGC(L); |
421 | setsvalue2s(L, L->top, luaS_newlstr(L, s, len)); | 422 | ts = luaS_newlstr(L, s, len); |
423 | setsvalue2s(L, L->top, ts); | ||
422 | api_incr_top(L); | 424 | api_incr_top(L); |
423 | lua_unlock(L); | 425 | lua_unlock(L); |
426 | return getstr(ts); | ||
424 | } | 427 | } |
425 | 428 | ||
426 | 429 | ||
427 | LUA_API void lua_pushstring (lua_State *L, const char *s) { | 430 | LUA_API const char *lua_pushstring (lua_State *L, const char *s) { |
428 | if (s == NULL) | 431 | if (s == NULL) { |
429 | lua_pushnil(L); | 432 | lua_pushnil(L); |
433 | return NULL; | ||
434 | } | ||
430 | else | 435 | else |
431 | lua_pushlstring(L, s, strlen(s)); | 436 | return lua_pushlstring(L, s, strlen(s)); |
432 | } | 437 | } |
433 | 438 | ||
434 | 439 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.40 2006/10/10 17:40:17 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.41 2007/04/10 12:17:52 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -892,7 +892,8 @@ static int testC (lua_State *L) { | |||
892 | } | 892 | } |
893 | else if EQ("tostring") { | 893 | else if EQ("tostring") { |
894 | const char *s = lua_tostring(L1, getindex); | 894 | const char *s = lua_tostring(L1, getindex); |
895 | lua_pushstring(L1, s); | 895 | const char *s1 = lua_pushstring(L1, s); |
896 | lua_assert((s == NULL && s1 == NULL) || (strcmp)(s, s1) == 0); | ||
896 | } | 897 | } |
897 | else if EQ("objsize") { | 898 | else if EQ("objsize") { |
898 | lua_pushinteger(L1, lua_objlen(L1, getindex)); | 899 | lua_pushinteger(L1, lua_objlen(L1, getindex)); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.223 2006/11/30 11:25:40 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.224 2007/02/07 17:54:52 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
5 | ** See Copyright Notice at the end of this file | 5 | ** See Copyright Notice at the end of this file |
@@ -158,11 +158,11 @@ LUA_API const void *(lua_topointer) (lua_State *L, int idx); | |||
158 | /* | 158 | /* |
159 | ** push functions (C -> stack) | 159 | ** push functions (C -> stack) |
160 | */ | 160 | */ |
161 | LUA_API void (lua_pushnil) (lua_State *L); | 161 | LUA_API void (lua_pushnil) (lua_State *L); |
162 | LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); | 162 | LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); |
163 | LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); | 163 | LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); |
164 | LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); | 164 | LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l); |
165 | LUA_API void (lua_pushstring) (lua_State *L, const char *s); | 165 | LUA_API const char *(lua_pushstring) (lua_State *L, const char *s); |
166 | LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, | 166 | LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, |
167 | va_list argp); | 167 | va_list argp); |
168 | LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); | 168 | LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); |