Пример #1
0
void csp::InitializeOpLua( lua::LuaState& state )
{
	InitializeCspObject( state, "CspOperation", cspOperationGlobals, cspOperationFunctions );

	lua::LuaStackValue metatable = PushCspMetatable( state.InternalState(), cspOperationFunctions );

	lua::LuaStack stack = state.GetStack();
	
	stack.PushInteger( WorkResult::FINISH );
	stack.SetField( metatable, "Finish" );
	
	stack.PushInteger( WorkResult::YIELD );
	stack.SetField( metatable, "Yield" );

	stack.Pop(1);
}
Пример #2
0
void PlatformerComponent::registerComponent(lua::LuaState& state)
{
    meta::MetadataStore::registerClass<PlatformerComponent>("PlatformerComponent")
        .declareAttribute("max_walking_speed", &PlatformerComponent::maxSpeed)
        .declareAttribute("max_jumping_speed", &PlatformerComponent::maxJumpingSpeed)
        .declareAttribute("max_falling_speed", &PlatformerComponent::maxFallingSpeed)
        .declareAttribute("acceleration", &PlatformerComponent::acceleration)
        .declareAttribute("deceleration", &PlatformerComponent::deceleration)
        .declareAttribute("gravity", &PlatformerComponent::gravity)
        .declareAttribute("wants_to_jump", &PlatformerComponent::wantsToJump)
        .declareAttribute("wants_to_go_left", &PlatformerComponent::wantsToGoLeft)
        .declareAttribute("wants_to_go_right", &PlatformerComponent::wantsToGoRight)
        .declareAttribute("on_idle", &PlatformerComponent::onIdleFunc)
        .declareAttribute("on_start_walking", &PlatformerComponent::onWalkingFunc)
        .declareAttribute("on_start_jumping", &PlatformerComponent::onJumpingFunc)
        .declareAttribute("on_start_falling", &PlatformerComponent::onFallingFunc)
        .declareAttribute("on_turn_right", &PlatformerComponent::onTurnRightFunc)
        .declareAttribute("on_turn_left", &PlatformerComponent::onTurnLeftFunc)
        .setExtraLoadFunction([](PlatformerComponent* c, const sol::object& luaObject) {
            c->movementStateCallbacks.registerCallback(State::Idle, c->onIdleFunc);
            c->movementStateCallbacks.registerCallback(State::Walking, c->onWalkingFunc);
            c->movementStateCallbacks.registerCallback(State::Jumping, c->onJumpingFunc);
            c->movementStateCallbacks.registerCallback(State::Falling, c->onFallingFunc);

            c->directionStateCallbacks.registerCallback(Direction::Right, c->onTurnRightFunc);
            c->directionStateCallbacks.registerCallback(Direction::Left, c->onTurnLeftFunc);
        });

    lua::EntityHandle::declareComponent<PlatformerComponent>("Platformer");

    state.getState().new_usertype<PlatformerComponent>("platformer_component" //TODO: Replace the name here
        //TODO: Register the properties here
    );
}
Пример #3
0
void csp::InitTests( lua::LuaState& state )
{
    lua::LuaStack& stack = state.GetStack();
    lua::LuaStackValue globals = stack.PushGlobalTable();

    InitializeCspObjectEnv( state, "TestSuite", testSuiteGlobals, testSuiteFunctions, globals );

    stack.Pop(1);
}
Пример #4
0
void RenderComponent::registerComponent(lua::LuaState& state)
{
    meta::MetadataStore::registerClass<RenderComponent>("RenderComponent")
        .declareAttribute("texture", &RenderComponent::textureName)
        .declareAttribute("current_animation", &RenderComponent::currentAnimation)
        .declareAttribute("animations", &RenderComponent::animations)
        .declareAttribute("flipped", &RenderComponent::flipped)
        .declareAttribute("on_animation_changed", &RenderComponent::onAnimationChangedFunc)
        .declareAttribute("on_animation_end", &RenderComponent::onAnimationEndFunc);

    lua::EntityHandle::declareComponent<RenderComponent>("Render");

    state.getState().new_usertype<RenderComponent>("render_component" //TODO: Replace the name here
        //TODO: Register the properties here
    );
}
Пример #5
0
void CustomDataComponent::registerComponent(lua::LuaState& state)
{
    meta::MetadataStore::registerClass<CustomDataComponent>()
        .setExtraLoadFunction([](CustomDataComponent* CustomData, const sol::object& luaObject)
        {
            if(luaObject.is<sol::table>())
            {
                sol::table luaTable = luaObject.as<sol::table>();
                luaTable.for_each([&](const sol::object& key, const sol::object& value)
                {
                    if(!key.is<std::string>())
                    {
                        std::cout << "[Lua/Error] CustomDataComponent table keys must be strings!" << std::endl;
                        return;
                    }
                    if(!value.is<boost::any>())
                    {
                        std::cout << "[Lua/Error] CustomDataComponent table value must be boost::any (constructed with XXX_value(...) lua function)!" << std::endl;
                        return;
                    }

                    CustomData->setValue(key.as<std::string>(), value.as<boost::any>());
                });
            }
            else
            {
                std::cout << "[Lua/Error] Can't load CustomDataComponent: not a table!" << std::endl;
            }
        });

    lua::EntityHandle::declareComponent<CustomDataComponent>("CustomData");

    state.getState().new_usertype<CustomDataComponent>("data_component",
        "has_value", &CustomDataComponent::hasValue,
        "get_value", &CustomDataComponent::getValue,
        "set_value", &CustomDataComponent::setValue
    );
}