Also, calls to luaL_openlib() and to luaL_register() should be changed according to its second argument.

Calls such as luaL_openlib(L, NULL, lreg, x); should be rewritten to luaL_setfuncs(L, lreg, x);.

Calls such as luaL_openlib(L, name, lreg, x); should be carefully rewritten because a global table with the given name will be searched and possibly created.

Calls such as luaL_register(L, NULL, lreg); should be rewritten to luaL_setfuncs(L, lreg, 0);.

Calls such as luaL_register(L, name, lreg); should be carefully rewritten because a global table with the given name will be searched and possibly created.
When possible, it should be rewritten to luaL_setfuncs(L, lreg, 0);