Skip to content
Snippets Groups Projects
Commit 21599ec5 authored by Alexander Turenko's avatar Alexander Turenko Committed by Igor Munkin
Browse files

box/lua: eliminate luaL_register*() usages in box

The idea of the refactoring is described in a previous commit.

The change is straightforward:

* Use `luaL_findtable()` to find/create a nested table in `_G`.
* Use `luaL_setfuncs()` to assign functions to a table.
* Use `luaT_newmodule()` to register a module for `require()`.

`require('box.internal.<...>')` calls are replaced with
`box.internal.<...>`, because `box` submodules are not registered as
modules anymore (IOW, are not placed into `package.loaded`).

However `_G.box == require('box')`, it remains unchanged.

One may wonder why fourth argument of `luaL_findtable()` (size hint for
the hash part of the table) is always zero in the added calls. It is an
effect of the following points:

* Those calls are not on hot paths and, moreover, there is no sense to
  use `luaL_findtable()` with a string literal as the second argument on
  a hot path (no sense to parse the string literal in runtime if a
  performance is the goal).
* Using `lengthof()` macro would add more code to read for a human (the
  argument itself, a line carry to fit 80 symbols, an inclusion of
  trivia/util.h) at no gain.
* A hardcoded array length is a developer's stress factor: it looks like
  it requires an update at a change of the array. So zero is better.

Part of #7774

NO_DOC=user visible behavior is unchanged, pure refactoring change
NO_TEST=see NO_DOC
NO_CHANGELOG=see NO_DOC
parent 2d2ff7e0
No related branches found
No related tags found
No related merge requests found
Showing with 45 additions and 50 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment