Browse Source

lua_pushstring/pushlstring return string

pull/9/head
Roberto Ierusalimschy 18 years ago
parent
commit
619be354c8
  1. 17
      lapi.c
  2. 5
      ltests.c
  3. 12
      lua.h

17
lapi.c

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 2.58 2006/10/17 20:00:07 roberto Exp roberto $
** $Id: lapi.c,v 2.59 2007/02/07 14:28:00 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -415,20 +415,25 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
}
LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
TString *ts;
lua_lock(L);
luaC_checkGC(L);
setsvalue2s(L, L->top, luaS_newlstr(L, s, len));
ts = luaS_newlstr(L, s, len);
setsvalue2s(L, L->top, ts);
api_incr_top(L);
lua_unlock(L);
return getstr(ts);
}
LUA_API void lua_pushstring (lua_State *L, const char *s) {
if (s == NULL)
LUA_API const char *lua_pushstring (lua_State *L, const char *s) {
if (s == NULL) {
lua_pushnil(L);
return NULL;
}
else
lua_pushlstring(L, s, strlen(s));
return lua_pushlstring(L, s, strlen(s));
}

5
ltests.c

@ -1,5 +1,5 @@
/*
** $Id: ltests.c,v 2.40 2006/10/10 17:40:17 roberto Exp roberto $
** $Id: ltests.c,v 2.41 2007/04/10 12:17:52 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@ -892,7 +892,8 @@ static int testC (lua_State *L) {
}
else if EQ("tostring") {
const char *s = lua_tostring(L1, getindex);
lua_pushstring(L1, s);
const char *s1 = lua_pushstring(L1, s);
lua_assert((s == NULL && s1 == NULL) || (strcmp)(s, s1) == 0);
}
else if EQ("objsize") {
lua_pushinteger(L1, lua_objlen(L1, getindex));

12
lua.h

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.223 2006/11/30 11:25:40 roberto Exp roberto $
** $Id: lua.h,v 1.224 2007/02/07 17:54:52 roberto Exp roberto $
** Lua - An Extensible Extension Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@ -158,11 +158,11 @@ LUA_API const void *(lua_topointer) (lua_State *L, int idx);
/*
** push functions (C -> stack)
*/
LUA_API void (lua_pushnil) (lua_State *L);
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l);
LUA_API void (lua_pushstring) (lua_State *L, const char *s);
LUA_API void (lua_pushnil) (lua_State *L);
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l);
LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
va_list argp);
LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);

Loading…
Cancel
Save