lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> The manual does not say how to release the space occupied by a
> luaL_Buiffer.  Presumably luaL_pushresult() will reclaim resources.
> The manual does not say how to handle errors.  Looking through mailing
> lists/etc, it looks like simply returning from the function in which
> the buffer was created will reclaim resources … but the manual does
> not say so..

The manual also does not say how to release the space occupied by a
table or by a string or by a coroutine. This is true for everything in
Lua. Like everything else, buffers are subject to garbage collection and
their space will be eventually released.


> Second, is there an “approved” way to determine the current size
> of a liuaL_Buffer.  I see that there is a field, n, in the structure
> that is the :”number of characters in the buffer”. Is this field
> guaranteed to always be there? (If so, can it be documented?). If not,
> can a function be added to retrieve the current size?  I have a use
> are where I need to ensure that the string does not grow “too big”
> - so I’d like to be able to find the current length in a manner
> that is formally part of the API.  (Alternatively, a way to limit the
> buffer’s maximum size would be ok - except then all the functions
> that add values to the buffer need to return a status… this seems to
> break the existing api/etc.

Again, that does not match the way Lua is tipically used. There is
no "approved" way to determine the current size of a table (or a
coroutine) nor a way to limit its size.

Note that, unlike tables, buffers are implemented outside Lua, in the
auxiliary library. (In Lua 5.4, the entire implementation takes less
than 200 lines of code.) If you have those specific needs, you might
consider writing your own buffers, so that you can tune it as you like.

-- Roberto