fix lookup of globals created by on_state_create

* Postponed _G scan for function lookup database to after
on_state_create invocation
* Fixed a crash when USE_DEBUG_SPEW == 1