TS-1634: reimplement Lua state management to support reload