lua-users home
lua-l archive

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

> No, table.sort() is not part of the minimal core that is exposed by
> the C API, is it part of the standard libraries. Some of the standard
> library functions are just simple wrappers around core functions, but
> not all of them - table.sort() is not, also table.insert(),
> string.rep(), string.reverse(), etc.

table.insert () is too simple to make it API function.
And so are string.rep (), string.reverse ()

I understand the idea not to bloat API.
On the other hand the situation may be reversed:
every tool or library using array sorting would have to
copy-paste the sorting routine and that is bloating the code
(which isn't kinda Lua spirit).

So my point is "why duplicate that much code if it is already there?"
auxsort () can be rewritten to work fine for various stack situations.
So it would be placed outside ltablib.c and put somewhere else.
And the second problem after API bloating here is luaL_checkstack(L, 40, "");
40 is too much for an API function:)

Anyway, having sorting function inside luaL_* stuff isn't too scary for Lua API.