avoid using API functions inside the core

This commit is contained in:
Roberto Ierusalimschy 2015-04-06 09:23:48 -03:00
parent 48d0674c2e
commit 67bf789462
1 changed files with 10 additions and 12 deletions

22
lapi.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lapi.c,v 2.247 2015/03/06 19:49:50 roberto Exp roberto $ ** $Id: lapi.c,v 2.248 2015/03/28 19:14:47 roberto Exp roberto $
** Lua API ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -434,9 +434,8 @@ LUA_API const void *lua_topointer (lua_State *L, int idx) {
case LUA_TCCL: return clCvalue(o); case LUA_TCCL: return clCvalue(o);
case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o))); case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));
case LUA_TTHREAD: return thvalue(o); case LUA_TTHREAD: return thvalue(o);
case LUA_TUSERDATA: case LUA_TUSERDATA: return getudatamem(uvalue(o));
case LUA_TLIGHTUSERDATA: case LUA_TLIGHTUSERDATA: return pvalue(o);
return lua_touserdata(L, idx);
default: return NULL; default: return NULL;
} }
} }
@ -485,20 +484,19 @@ LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) {
LUA_API const char *lua_pushstring (lua_State *L, const char *s) { LUA_API const char *lua_pushstring (lua_State *L, const char *s) {
if (s == NULL) { lua_lock(L);
lua_pushnil(L); if (s == NULL)
return NULL; setnilvalue(L->top);
}
else { else {
TString *ts; TString *ts;
lua_lock(L);
luaC_checkGC(L); luaC_checkGC(L);
ts = luaS_new(L, s); ts = luaS_new(L, s);
setsvalue2s(L, L->top, ts); setsvalue2s(L, L->top, ts);
api_incr_top(L); s = getstr(ts); /* internal copy's address */
lua_unlock(L);
return getstr(ts);
} }
api_incr_top(L);
lua_unlock(L);
return s;
} }