Ejemplo n.º 1
0
void outputFunc(std::string file, std::string func, const std::string& str, std::vector<any> args)
{
    LuaState ls;
    openUtilExtendLibs(ls.getState());

    int err = ls.parseFile(file);
    if (0 != err)
    {
        printLine(luaGetError(ls.getState(), err));
        return;
    }

    luaGetGlobal(ls.getState(), func);

    luaPushString(ls.getState(), str);
    for (size_t i=0; i<args.size(); ++i)
        luaPushAny(ls.getState(), args[i]);

    err = luaCallFunc(ls.getState(), 1 + args.size() , 0);
    if (0 != err)
    {
        printLine(luaGetError(ls.getState(), err));
        return;
    }

    luaPop(ls.getState(), -1);
}
Ejemplo n.º 2
0
void PositionComponent::registerComponent(LuaState& state)
{
    //Register loading infos
    meta::MetadataStore::registerClass<PositionComponent>("PositionComponent")
        .declareAttribute<float>("x", &PositionComponent::x)
        .declareAttribute<float>("y", &PositionComponent::y)
        .declareAttribute<float>("z", &PositionComponent::z)
        .declareAttribute<float>("width", &PositionComponent::width)
        .declareAttribute<float>("height", &PositionComponent::height);

    EntityHandle::declareComponent<PositionComponent>("position");

    //Register to lua
    state.getState().new_usertype<PositionComponent>("position_component",
        "x", &PositionComponent::x,
        "y", &PositionComponent::y,
        "z", &PositionComponent::z,
        "width", &PositionComponent::width,
        "height", &PositionComponent::height,
        "old_x", sol::readonly(&PositionComponent::oldX),
        "old_y", sol::readonly(&PositionComponent::oldY),
        "old_width", sol::readonly(&PositionComponent::oldWidth),
        "old_height", sol::readonly(&PositionComponent::oldHeight)
    );
    state.declareComponentGetter<PositionComponent>("position");
}
Ejemplo n.º 3
0
void LevelState::registerClass(LuaState& luaState)
{
    sol::constructors<> ctor;
    sol::usertype<LevelState> levelLuaClass(ctor,
        "create_new_entity", &LevelState::lua_createNewEntity,
        "get_entities", &LevelState::lua_getEntities
    );
    luaState.getState().set_usertype("level_state", levelLuaClass);
}
Ejemplo n.º 4
0
void ColliderComponent::registerComponent(LuaState& state)
{
    meta::MetadataStore::registerClass<ColliderComponent>();

    EntityHandle::declareComponent<ColliderComponent>("collider");

    state.getState().new_usertype<ColliderComponent>("collider_component" //TODO: Replace the name here
        //TODO: Register the properties here
    );
    state.declareComponentGetter<ColliderComponent>("collider");
}
Ejemplo n.º 5
0
void WeatherMgr::Init(LuaState &lua)
{
    lua.getState()->new_usertype<WeatherMgr>("WeatherMgr",
                                             "current", sol::property(&WeatherMgr::getCurrent, &WeatherMgr::setCurrent),
                                             "next", sol::property(&WeatherMgr::getNext, &WeatherMgr::setNext),
                                             "transitionFactor", sol::property(&WeatherMgr::getTransition, &WeatherMgr::setTransition),
                                             "updateTime", sol::property(&WeatherMgr::getUpdate, &WeatherMgr::setUpdate),
                                             "copy", &WeatherMgr::copy,
                                             "setWeather", &WeatherMgr::setWeather,
                                             "request", &WeatherMgr::requestWeather
    );
}
void CustomBehaviorComponent::registerComponent(LuaState& state)
{
    meta::MetadataStore::registerClass<CustomBehaviorComponent>("CustomBehaviorComponent")
    .declareAttribute<sol::function>("on_update", &CustomBehaviorComponent::updateFunction);

    EntityHandle::declareComponent<CustomBehaviorComponent>("custom_behavior");

    state.getState().new_usertype<CustomBehaviorComponent>("custom_behavior_component",
            "on_update", &CustomBehaviorComponent::updateFunction
                                                          );
    state.declareComponentGetter<CustomBehaviorComponent>("custom_behavior");
}
Ejemplo n.º 7
0
void EntityHandle::registerClass(LuaState &state)
{
    state.getState().new_usertype<EntityHandle>("entity_handle",
        "remove_entity", &EntityHandle::removeEntity,
        "has_component", &EntityHandle::hasComponent,
        "get_attribute", &EntityHandle::getAttributeAsAny,
        "set_attribute", &EntityHandle::setAttributeAsAny,
        "get_table_attribute", &EntityHandle::getAttributeAsLuaTable,
        "set_table_attribute", &EntityHandle::setAttributeAsLuaTable,
        "get_custom_data", &EntityHandle::getCustomData,
        "write_to_console", &EntityHandle::writeToConsole
    );
}
Ejemplo n.º 8
0
void PlatformComponent::registerComponent(LuaState& state)
{
    meta::MetadataStore::registerClass<PlatformComponent>("PlatformComponent")
        .declareAttribute("activated", &PlatformComponent::activated)
        .declareAttribute("on_hit", &PlatformComponent::onHitFunc)
        .setExtraLoadFunction([](PlatformComponent* platform, const sol::object& luaObject)
        {
            const sol::object& platformTypeLua = luaObject.as<sol::table>().get<sol::object>("platform_type");
            if(platformTypeLua.is<std::string>())
            {
                platform->setPlatformTypeAsString(platformTypeLua.as<std::string>());
            }
        });

    EntityHandle::declareComponent<PlatformComponent>("platform");

    state.getState().new_usertype<PlatformComponent>("platform_component",
        "activated", &PlatformComponent::activated,
        "platform_type", sol::property(&PlatformComponent::getPlatformTypeAsString, &PlatformComponent::setPlatformTypeAsString),
        "on_hit", &PlatformComponent::onHitFunc
    );
    state.declareComponentGetter<PlatformComponent>("platform");
}
Ejemplo n.º 9
0
void Player::Init(LuaState &lua)
{
    lua.getState()->new_usertype<Player>("Player",
                                         "getPosition", &NetActor::getPosition,
                                         "setPosition", &NetActor::setPosition,
                                         "getRotation", &NetActor::getRotation,
                                         "setRotation", &NetActor::setRotation,
                                         "setMomentum", &NetActor::setMomentum,

                                         "getHealth", &NetActor::getHealth,
                                         "setHealth", &NetActor::setHealth,
                                         "getMagicka", &NetActor::getMagicka,
                                         "setMagicka", &NetActor::setMagicka,
                                         "getFatigue", &NetActor::getFatigue,
                                         "setFatigue", &NetActor::setFatigue,

                                         "getCell", &NetActor::getCell,
                                         "getInventory", &NetActor::getInventory,

                                         "getPreviousCellPos", &Player::getPreviousCellPos,

                                         "kick", &Player::kick,
                                         "ban", &Player::ban,
                                         "address", sol::property(&Player::getIP),

                                         "getAvgPing", &Player::getAvgPing,

                                         "message", &Player::message,
                                         "joinChannel", &Player::joinChannel,
                                         "cleanChannel", &Player::cleanChannel,
                                         "renameChannel", &Player::renameChannel,
                                         "closeChannel", &Player::closeChannel,
                                         "leaveChannel", &Player::leaveChannel,
                                         "setChannel", &Player::setChannel,
                                         "isChannelOpen", &Player::isChannelOpen,

                                         "pid", sol::readonly_property(&Player::id),
                                         "guid", sol::readonly_property(&Player::getGUID),

                                         "name", sol::property(&Player::getName, &Player::setName),
                                         "setCharGenStages", &Player::setCharGenStages,
                                         "level", sol::property(&Player::getLevel, &Player::setLevel),
                                         "gender", sol::property(&Player::getGender, &Player::setGender),
                                         "race", sol::property(&Player::getRace, &Player::setRace),
                                         "head", sol::property(&Player::getHead, &Player::setHead),
                                         "hair", sol::property(&Player::getHair, &Player::setHair),
                                         "birthsign", sol::property(&Player::getBirthsign, &Player::setBirthsign),
                                         "setResetStats", &Player::setResetStats,

                                         "bounty", sol::property(&Player::getBounty, &Player::setBounty),
                                         "reputation", sol::property(&Player::getReputation, &Player::setReputation),
                                         "levelProgress", sol::property(&Player::getLevelProgress, &Player::setLevelProgress),
                                         "creatureRefId", sol::property(&Player::getCreatureRefId, &Player::setCreatureRefId),
                                         "displayCreatureName",  sol::property(&Player::getCreatureNameDisplayState, &Player::setCreatureNameDisplayState),

                                         "resurrect", &Player::resurrect,
                                         "jail", &Player::jail,
                                         "werewolf",  sol::property(&Player::getWerewolfState, &Player::setWerewolfState),
                                         "scale", sol::property(&Player::getScale, &Player::setScale),

                                         "getAttribute", &Player::getAttribute,
                                         "setAttribute", &Player::setAttribute,

                                         "getSkill", &Player::getSkill,
                                         "setSkill", &Player::setSkill,

                                         "getSkillIncrease", &Player::getSkillIncrease,
                                         "setSkillIncrease", &Player::setSkillIncrease,

                                         "getClass", &Player::getCharClass,
                                         "getSettings", &Player::getSettings,
                                         "getBooks", &Player::getBooks,
                                         "getGUI", &Player::getGUI,
                                         "getDialogue", &Player::getDialogue,
                                         "getFactions", &Player::getFactions,
                                         "getQuests", &Player::getQuests,
                                         "getSpells", &Player::getSpells,
                                         "getQuickKeys", &Player::getQuickKeys,
                                         "getWeatherMgr", &Player::getWeatherMgr,

                                         "getMark", &Player::getMark,
                                         "setMark", &Player::setMark,

                                         "getSelectedSpell", &Player::getSelectedSpell,
                                         "setSelectedSpell", &Player::setSelectedSpell,

                                         "cellStateSize", &Player::cellStateSize,
                                         "getCellState", &Player::getCellState,

                                         "setAuthority", &Player::setAuthority,

                                         "storedData", &Player::storedData,
                                         "customData", &Player::customData,
                                         "markedForDeletion", sol::property(&Player::isMarkedForDeletion)
    );

    lua.getState()->new_enum("ChannelAction",
                            "createChannel", 0,
                            "joinChannel", 1,
                            "closeChannel", 2,
                            "leaveChannel", 3);
}