On Mon, 4 Mar 2024 at 13:02, Sainan <
sai...@calamity.gg> wrote:
>
> Hi, I was trying to implement a table.clear function that's O(1) instead
> of O(n) time (inspired by a post on this mailing list from a while ago),
> and my initial idea for this was to simply use luaH_resize like so:
>
> static int tclear (lua_State *L) {
> luaL_checktype(L, 1, LUA_TTABLE);
> luaH_resize(L, hvalue(index2value(L, 1)), 0, 0);
luaH_resize is not part of the C API. It is an internal function. Only
the functions documented in the Lua manual (
https://www.lua.org/manual/5.4/manual.html#4 ) are part of the API
(literally the _Application Programmer_ Interface -- other functions
such as luaH_* and other undocumented prefixes are not intended for
us, application programmers, they are for the Lua VM developers. They
often offer more brittle interfaces that are meant for internal use
only, avoiding extra consistency checks because the VM code can
control all its uses).
-- Hisham