fix bug and possible segfault in Lua integration (wrong check of reclaimed state)