lua-users home
lua-l archive

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


On Thu, Jan 28, 2021 at 12:46 PM Viacheslav Usov <via.usov@gmail.com> wrote:
>
>
> In my opinion, the buffers should be deprecated as a public API and
> reserved strictly for Lua itself.

The buffers work fine if you follow the rules. While you're filling
the contents of the buffer it may use extra stack slots, so you should
refer to stack entries created before the buffer object is initialized
with absolute indices only, and only do stack balanced operation
sequences between buffer API calls.

The reason the buffer API is a bit tricky to use is that it only uses
an extra stack slot if your string grows beyond a certain size,
shorter strings are stored inside the luaL_Buffer object.
An easier API could always use a single stack slot, but that would
incur garbage collector overhead even for tiny strings.

-- 
Gé