aboutsummaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-11-09 17:05:42 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-11-09 17:05:42 -0300
commit024f9064f1b43758eb36aba52547edc0312bf4ba (patch)
tree9d8609112058e885196a581f0736fbdd94f7f94d /manual
parent7f4906f565ab9f8b1125107a3abae3d759f3ecf2 (diff)
downloadlua-024f9064f1b43758eb36aba52547edc0312bf4ba.tar.gz
lua-024f9064f1b43758eb36aba52547edc0312bf4ba.tar.bz2
lua-024f9064f1b43758eb36aba52547edc0312bf4ba.zip
External strings
Strings can use external buffers to store their contents.
Diffstat (limited to 'manual')
-rw-r--r--manual/manual.of34
1 files changed, 34 insertions, 0 deletions
diff --git a/manual/manual.of b/manual/manual.of
index 3eab69fa..9d6a7fd9 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -3908,6 +3908,40 @@ This function is equivalent to @Lid{lua_pushcclosure} with no upvalues.
3908 3908
3909} 3909}
3910 3910
3911@APIEntry{const char *(lua_pushextlstring) (lua_State *L,
3912 const char *s, size_t len, lua_Alloc falloc, void *ud);|
3913@apii{0,1,m}
3914
3915Creates an @emphx{external string},
3916that is, a string that uses memory not managed by Lua.
3917The pointer @id{s} points to the exernal buffer
3918holding the string content,
3919and @id{len} is the length of the string.
3920The string should have a zero at its end,
3921that is, the condition @T{s[len] == '\0'} should hold.
3922
3923If @id{falloc} is different from @id{NULL},
3924that function will be called by Lua
3925when the external buffer is no longer needed.
3926The contents of the buffer should not change before this call.
3927The function will be called with the given @id{ud},
3928the string @id{s} as the block,
3929the length plus one (to account for the ending zero) as the old size,
3930and 0 as the new size.
3931
3932Lua always @x{internalizes} strings with lengths up to 40 characters.
3933So, for strings in that range,
3934this function will immediately internalize the string
3935and call @id{falloc} to free the buffer.
3936
3937Even when using an external buffer,
3938Lua still has to allocate a header for the string.
3939In case of a memory-allocation error,
3940Lua will call @id{falloc} before raising the error.
3941
3942}
3943
3944
3911@APIEntry{const char *lua_pushfstring (lua_State *L, const char *fmt, ...);| 3945@APIEntry{const char *lua_pushfstring (lua_State *L, const char *fmt, ...);|
3912@apii{0,1,v} 3946@apii{0,1,v}
3913 3947