From b352217b8498a5ed8f6c954b3da365fcbb89751f Mon Sep 17 00:00:00 2001 From: Roberto I Date: Fri, 17 Oct 2025 13:53:35 -0300 Subject: Standard allocator function added to the API That makes easier to redefine luaL_newstate. --- manual/manual.of | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'manual/manual.of') diff --git a/manual/manual.of b/manual/manual.of index beea41f9..ad273d62 100644 --- a/manual/manual.of +++ b/manual/manual.of @@ -3079,11 +3079,12 @@ the allocator must behave like @id{realloc}. In particular, the allocator returns @id{NULL} if and only if it cannot fulfill the request. -Here is a simple implementation for the @x{allocator function}. -It is used in the auxiliary library by @Lid{luaL_newstate}. +Here is a simple implementation for the @x{allocator function}, +corresponding to the function @Lid{luaL_alloc} from the +auxiliary library. @verbatim{ -static void *l_alloc (void *ud, void *ptr, size_t osize, - size_t nsize) { +void *luaL_alloc (void *ud, void *ptr, size_t osize, + size_t nsize) { (void)ud; (void)osize; /* not used */ if (nsize == 0) { free(ptr); @@ -5988,9 +5989,8 @@ it does not run it. @apii{0,0,-} Returns a value with a weak attempt for randomness. -(It produces that value based on the current date and time -and the address of an internal variable, -in case the machine has Address Space Layout Randomization.) +The parameter @id{L} can be @id{NULL} +if there is no Lua state available. } @@ -6046,8 +6046,9 @@ with @id{tname} in the registry. @apii{0,0,-} Creates a new Lua state. -It calls @Lid{lua_newstate} with an -allocator based on the @N{ISO C} allocation functions +It calls @Lid{lua_newstate} with @Lid{luaL_alloc} as +the allocator function and the result of @T{luaL_makeseed(NULL)} +as the seed, and then sets a warning function and a panic function @see{C-error} that print messages to the standard error output. @@ -6271,6 +6272,15 @@ in the registry @seeC{luaL_newmetatable}. } +@APIEntry{ +void *luaL_alloc (void *ud, void *ptr, size_t osize, size_t nsize);| + +A standard allocator function for Lua @seeF{lua_Alloc}, +built on top of the C functions @id{realloc} and @id{free}. + +} + + @APIEntry{ typedef struct luaL_Stream { FILE *f; -- cgit v1.2.3-55-g6feb