diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-11-09 17:05:42 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-11-09 17:05:42 -0300 |
| commit | 024f9064f1b43758eb36aba52547edc0312bf4ba (patch) | |
| tree | 9d8609112058e885196a581f0736fbdd94f7f94d /lapi.c | |
| parent | 7f4906f565ab9f8b1125107a3abae3d759f3ecf2 (diff) | |
| download | lua-024f9064f1b43758eb36aba52547edc0312bf4ba.tar.gz lua-024f9064f1b43758eb36aba52547edc0312bf4ba.tar.bz2 lua-024f9064f1b43758eb36aba52547edc0312bf4ba.zip | |
External strings
Strings can use external buffers to store their contents.
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 14 |
1 files changed, 14 insertions, 0 deletions
| @@ -535,6 +535,20 @@ LUA_API const char *lua_pushlstring (lua_State *L, const char *s, size_t len) { | |||
| 535 | } | 535 | } |
| 536 | 536 | ||
| 537 | 537 | ||
| 538 | LUA_API const char *lua_pushextlstring (lua_State *L, | ||
| 539 | const char *s, size_t len, lua_Alloc falloc, void *ud) { | ||
| 540 | TString *ts; | ||
| 541 | lua_lock(L); | ||
| 542 | api_check(L, s[len] == '\0', "string not ending with zero"); | ||
| 543 | ts = luaS_newextlstr (L, s, len, falloc, ud); | ||
| 544 | setsvalue2s(L, L->top.p, ts); | ||
| 545 | api_incr_top(L); | ||
| 546 | luaC_checkGC(L); | ||
| 547 | lua_unlock(L); | ||
| 548 | return getstr(ts); | ||
| 549 | } | ||
| 550 | |||
| 551 | |||
| 538 | LUA_API const char *lua_pushstring (lua_State *L, const char *s) { | 552 | LUA_API const char *lua_pushstring (lua_State *L, const char *s) { |
| 539 | lua_lock(L); | 553 | lua_lock(L); |
| 540 | if (s == NULL) | 554 | if (s == NULL) |
