diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2025-10-17 13:53:35 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2025-10-17 13:53:35 -0300 |
| commit | b352217b8498a5ed8f6c954b3da365fcbb89751f (patch) | |
| tree | 4a2a7feb7bcf9d0144af6923807904b9bc0e4037 /manual | |
| parent | 9c66903cc55388006a833f0f3911ea81fa86edea (diff) | |
| download | lua-b352217b8498a5ed8f6c954b3da365fcbb89751f.tar.gz lua-b352217b8498a5ed8f6c954b3da365fcbb89751f.tar.bz2 lua-b352217b8498a5ed8f6c954b3da365fcbb89751f.zip | |
Standard allocator function added to the API
That makes easier to redefine luaL_newstate.
Diffstat (limited to 'manual')
| -rw-r--r-- | manual/manual.of | 28 |
1 files changed, 19 insertions, 9 deletions
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}. | |||
| 3079 | In particular, the allocator returns @id{NULL} | 3079 | In particular, the allocator returns @id{NULL} |
| 3080 | if and only if it cannot fulfill the request. | 3080 | if and only if it cannot fulfill the request. |
| 3081 | 3081 | ||
| 3082 | Here is a simple implementation for the @x{allocator function}. | 3082 | Here is a simple implementation for the @x{allocator function}, |
| 3083 | It is used in the auxiliary library by @Lid{luaL_newstate}. | 3083 | corresponding to the function @Lid{luaL_alloc} from the |
| 3084 | auxiliary library. | ||
| 3084 | @verbatim{ | 3085 | @verbatim{ |
| 3085 | static void *l_alloc (void *ud, void *ptr, size_t osize, | 3086 | void *luaL_alloc (void *ud, void *ptr, size_t osize, |
| 3086 | size_t nsize) { | 3087 | size_t nsize) { |
| 3087 | (void)ud; (void)osize; /* not used */ | 3088 | (void)ud; (void)osize; /* not used */ |
| 3088 | if (nsize == 0) { | 3089 | if (nsize == 0) { |
| 3089 | free(ptr); | 3090 | free(ptr); |
| @@ -5988,9 +5989,8 @@ it does not run it. | |||
| 5988 | @apii{0,0,-} | 5989 | @apii{0,0,-} |
| 5989 | 5990 | ||
| 5990 | Returns a value with a weak attempt for randomness. | 5991 | Returns a value with a weak attempt for randomness. |
| 5991 | (It produces that value based on the current date and time | 5992 | The parameter @id{L} can be @id{NULL} |
| 5992 | and the address of an internal variable, | 5993 | if there is no Lua state available. |
| 5993 | in case the machine has Address Space Layout Randomization.) | ||
| 5994 | 5994 | ||
| 5995 | } | 5995 | } |
| 5996 | 5996 | ||
| @@ -6046,8 +6046,9 @@ with @id{tname} in the registry. | |||
| 6046 | @apii{0,0,-} | 6046 | @apii{0,0,-} |
| 6047 | 6047 | ||
| 6048 | Creates a new Lua state. | 6048 | Creates a new Lua state. |
| 6049 | It calls @Lid{lua_newstate} with an | 6049 | It calls @Lid{lua_newstate} with @Lid{luaL_alloc} as |
| 6050 | allocator based on the @N{ISO C} allocation functions | 6050 | the allocator function and the result of @T{luaL_makeseed(NULL)} |
| 6051 | as the seed, | ||
| 6051 | and then sets a warning function and a panic function @see{C-error} | 6052 | and then sets a warning function and a panic function @see{C-error} |
| 6052 | that print messages to the standard error output. | 6053 | that print messages to the standard error output. |
| 6053 | 6054 | ||
| @@ -6272,6 +6273,15 @@ in the registry @seeC{luaL_newmetatable}. | |||
| 6272 | } | 6273 | } |
| 6273 | 6274 | ||
| 6274 | @APIEntry{ | 6275 | @APIEntry{ |
| 6276 | void *luaL_alloc (void *ud, void *ptr, size_t osize, size_t nsize);| | ||
| 6277 | |||
| 6278 | A standard allocator function for Lua @seeF{lua_Alloc}, | ||
| 6279 | built on top of the C functions @id{realloc} and @id{free}. | ||
| 6280 | |||
| 6281 | } | ||
| 6282 | |||
| 6283 | |||
| 6284 | @APIEntry{ | ||
| 6275 | typedef struct luaL_Stream { | 6285 | typedef struct luaL_Stream { |
| 6276 | FILE *f; | 6286 | FILE *f; |
| 6277 | lua_CFunction closef; | 6287 | lua_CFunction closef; |
