I'm actually surprised and sort-of sad that luaL_requiref doesn't check
package.loaded. I had assumed it did, but I wrote out your test and it
confirmed what you said.
The safest solution IMO would be to write your luaopen_* to be resilient
(or a no-op) in the face of redundant requires. If all they do are
assignments to the global environment, this level of safety is easy to
attain. I'd be curious to hear if this wasn't the case for you. :)
I guess I treat require's "load only once" ultimately as a very strong hint
rather than as a fundamental guarantee - it's just too easy for the
programmer to break. In my experience, the most common "require didn't
honor its contract" problems are when a loaded file overwrites one of its
own stateful globals (causing some weird fissure in what I assumed were
immutable globals), but this is really my own fault for not treating global
state with more suspicion.
-- Aaron