diff options
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.254 2015/08/25 18:50:37 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.255 2015/09/09 13:45:50 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 | */ |
@@ -472,15 +472,15 @@ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { | |||
472 | 472 | ||
473 | 473 | ||
474 | /* | 474 | /* |
475 | ** Pushes on the stack a string with given length. Even when 'len' == 0, | 475 | ** Pushes on the stack a string with given length. Avoid using 's' when |
476 | ** 's' cannot be NULL due to later use of 'memcmp' and 'memcpy'. | 476 | ** 'len' == 0 (as 's' can be NULL in that case), due to later use of |
477 | ** 'memcmp' and 'memcpy'. | ||
477 | */ | 478 | */ |
478 | LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { | 479 | LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { |
479 | TString *ts; | 480 | TString *ts; |
480 | lua_lock(L); | 481 | lua_lock(L); |
481 | luaC_checkGC(L); | 482 | luaC_checkGC(L); |
482 | api_check(L, s != NULL, "pointer cannot be NULL"); | 483 | ts = (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len); |
483 | ts = luaS_newlstr(L, s, len); | ||
484 | setsvalue2s(L, L->top, ts); | 484 | setsvalue2s(L, L->top, ts); |
485 | api_incr_top(L); | 485 | api_incr_top(L); |
486 | lua_unlock(L); | 486 | lua_unlock(L); |