The luaL_register will crash when the number of registered libs is bigger than a threshold, 43 for my test.
Each luaL_register is probably leaving a value on the Lua-C stack and so
what you're seeing is a stack overflow.
If you need to do this, you need to reserve enough space for the stack
by calling lua_checkstack or luaL_checkstack.