Fix is_main checks for lua5.2

In lua5.2 package.loaded will be filled only when the module returns.
Therefore this cannot be used anymore to main-module checks.

I provided a more portable solution (hopefully).