void LuaLevelEngine::loadNPCClass(int id, const QString &path)
{
    if(shouldShutdown())
        return;

    luabind::object _G = luabind::globals(getNativeState());
    if(luabind::type(_G["npc_class_table"]) != LUA_TTABLE){
        _G["npc_class_table"] = luabind::newtable(getNativeState());
    }

    if(luabind::type(_G["npc_class_table"][id]) != LUA_TNIL)
        return;

    _G["npc_class_table"][id] = loadClassAPI(path);
}
void LuaLevelEngine::destoryLuaNpc(LVL_Npc *npc)
{
    try {
        luabind::call_function<void>(getNativeState(), "__destroy_luanpc", npc);
    } catch (luabind::error& error){
        postLateShutdownError(error);
        return;
    }
}
LVL_Npc *LuaLevelEngine::createLuaNpc(unsigned int id)
{
    try {
        return luabind::call_function<LVL_Npc*>(getNativeState(), "__create_luanpc", id);
    } catch (luabind::error& error){
        postLateShutdownError(error);
        return nullptr;
    }
}
LVL_Player *LuaLevelEngine::createLuaPlayer()
{
    try {
        return luabind::call_function<LVL_Player*>(getNativeState(), "__create_luaplayer");
    } catch (luabind::error& error){
        postLateShutdownError(error);
        return nullptr;
    }
}
void LuaLevelEngine::onBindAll()
{
    luabind::module(getNativeState())[
        Binding_Level_Class_PhysObj::bindToLua(),
        Binding_Level_Class_InAreaDetector::bindToLua(),
        Binding_Level_Class_PlayerPosDetector::bindToLua(),
        Binding_Level_ClassWrapper_LVL_Player::bindToLua(),
        Binding_Level_ClassWrapper_LVL_NPC::bindToLua(),
        Binding_Level_GlobalFuncs_Player::bindToLua(),
        Binding_Level_GlobalFuncs_NPC::bindToLua()
    ];

    {
        luabind::object _G = luabind::globals(getNativeState());
        if(luabind::type(_G["bases"]) != LUA_TTABLE){
            _G["bases"] = luabind::newtable(getNativeState());
        }

        _G["bases"]["npc"] = loadClassAPI(m_npcBaseClassPath);
        _G["bases"]["player"] = loadClassAPI(m_playerBaseClassPath);
    }

}
void LuaTitleScreenEngine::onBindAll()
{
    Binding_Global_Constants::bindToLua(getNativeState());
}