Example #1
0
void Sound::luaBindings(sol::state &lua) {

    lua.new_usertype<Properties>("SoundProperties",

        sol::base_classes, sol::bases<Touchable>(),

        "playState", &Properties::playState,
        "loop", &Properties::loop,
        "volume", &Properties::volume,
        "maxDistance", &Properties::maxDistance,
        "rolloffFactor", &Properties::rolloffFactor,
        "referenceDistance", &Properties::referenceDistance,
        "priority", &Properties::priority
    );
    
    lua.new_usertype<Sound>("Sound",

        sol::constructors<sol::types<std::string, std::string>>(),

        "PlayState", sol::var(lua.create_table_with(
                "Play", PlayState::Play,
                "Pause", PlayState::Pause,
                "Stop", PlayState::Stop
            )),
            
        "name", &Sound::name,
        "pause", &Sound::pause,
        "play", &Sound::play,
        "stop", &Sound::stop,

        "properties", sol::readonly(&Sound::m_properties)
    );
}
Example #2
0
		benchmark() {

			sol_state.set_function("simple_math", &benchmark_core::simple_math);

			reg(nonius::benchmark("sol_1.1.0", [this] {
				auto& sol_lua = this->sol_state;
				int result = 0;
				static size_t iteration_index = 1;
				for (size_t i = 0, end = NUM_ITERATIONS*iteration_index; i < end; ++i) {
					sol::function test = sol_lua["simple_math"];
					result += test.call<int>(42);
				}
				++iteration_index;
				return result;
			}));

			reg(nonius::benchmark("sol_1.1.0_cached", [this] {
				auto& sol_lua = this->sol_state;
				int result = 0;
				sol::function test = sol_lua["simple_math"];
				static size_t iteration_index = 1;
				for (size_t i = 0, end = NUM_ITERATIONS*iteration_index; i < end; ++i) {
					result += test.call<int>(42);
				}
				++iteration_index;
				return result;
			}));
		}
Example #3
0
  static void luaBinding(sol::state &lua) {
  	lua.new_usertype<WebDriver>("WebDriver",
      "getDriverAddress",&WebDriver::getDriverAddress,
      "setDriverAddress",&WebDriver::setDriverAddress,
      "getSession",&WebDriver::getSession,
      "setSession",&WebDriver::setSession,
      "newSession", &WebDriver::newSession,
      "go", &WebDriver::go,
      "getCurrentURL",&WebDriver::getCurrentURL,
      "getPageSource", &WebDriver::getPageSource,
      "takeScreenshot", &WebDriver::takeScreenshot,
      "executeScript", &WebDriver::executeScript,
      "executeScriptFromFile", &WebDriver::executeScriptFromFile,
      "deleteSession", &WebDriver::deleteSession
  	);

    lua["webDriver"] = lua.create_table_with(
      "chrome",chromeWebDriver,
      "fireFox",fireFoxWebDriver
    );
  }
Example #4
0
void OgreLightComponent::luaBindings(
    sol::state &lua
){

    lua.new_usertype<Properties>("OgreLightComponentProperties",

        sol::base_classes, sol::bases<Touchable>(),

        "attenuationConstant", &Properties::attenuationConstant,
        "attenuationLinear", &Properties::attenuationLinear,
        "attenuationRange", &Properties::attenuationRange,
        "attenuationQuadratic", &Properties::attenuationQuadratic,
        "diffuseColour", &Properties::diffuseColour,
        "specularColour", &Properties::specularColour,
        "spotlightFalloff", &Properties::spotlightFalloff,
        "spotlightInnerAngle", &Properties::spotlightInnerAngle,
        "spotlightNearClipDistance", &Properties::spotlightNearClipDistance,
        "spotlightOuterAngle", &Properties::spotlightOuterAngle,
        "type", &Properties::type
    );
    
    lua.new_usertype<OgreLightComponent>("OgreLightComponent",

        "new", sol::factories([](){
                return std::make_unique<OgreLightComponent>();
            }),

        COMPONENT_BINDINGS(OgreLightComponent),

        "setRange", &OgreLightComponent::setRange,
        "properties", sol::readonly(&OgreLightComponent::m_properties),

        "LightTypes", sol::var(lua.create_table_with(
                "LT_POINT", Ogre::Light::LT_POINT,
                "LT_DIRECTIONAL", Ogre::Light::LT_DIRECTIONAL,
                "LT_SPOTLIGHT", Ogre::Light::LT_SPOTLIGHT
            ))
    );
}
main_menu_setup::main_menu_setup(
	sol::state& lua,
	const main_menu_settings settings
) {
	try {
		menu_theme.emplace(settings.menu_theme_path);
	}
	catch (const std::runtime_error& err) {
		LOG("Warning: could not load the main menu theme:\n%x", err.what());
	}

	query_latest_news(settings.latest_news_url);

	if (settings.skip_credits) {
		gui.show = true;
	}

	const auto menu_config_patch_path = "content/menu/config.lua";

	try {
		auto pfr = lua.do_string(augs::file_to_string(menu_config_patch_path));
		
		if (pfr.valid()) {
			menu_config_patch = pfr;
		}
		else {
			LOG("Warning: problem loading %x: \n%x.", menu_config_patch_path, pfr.operator std::string());
		}
	}
	catch (const augs::file_open_error& err) {
		LOG("Failed to load %x:\n%x\nMenu will apply no patch to config.", menu_config_patch_path, err.what());
	}

	if (menu_theme) {
		menu_theme_source.bind_buffer(*menu_theme);
		menu_theme_source.set_direct_channels(true);
		menu_theme_source.set_spatialize(false);
		menu_theme_source.seek_to(static_cast<float>(settings.start_menu_music_at_secs));
		menu_theme_source.set_gain(0.f);
		menu_theme_source.play();
	}

	// TODO: actually load a cosmos with its resources from a file/folder
	const bool is_intro_scene_available = settings.menu_intro_scene_intercosm_path.string().size() > 0;

	auto& cosm = intro.world;

	if (is_intro_scene_available) {
#if BUILD_TEST_SCENES
		intro.make_test_scene(lua, { false, 60 }, ruleset);
		viewed_character_id = cosm[mode.lookup(mode.add_player({ ruleset, cosm }, faction_type::RESISTANCE))].get_id();
#endif
	}

	const bool is_recording_available = is_intro_scene_available && false;
	initial_step_number = cosm.get_total_steps_passed();

	for (auto& m : gui.root.buttons) {
		m.hover_highlight_maximum_distance = 10.f;
		m.hover_highlight_duration_ms = 300.f;
	}

	gui.root.buttons[main_menu_button_type::CONNECT_TO_OFFICIAL_UNIVERSE].set_appearing_caption("Login to official universe");
	gui.root.buttons[main_menu_button_type::BROWSE_UNOFFICIAL_UNIVERSES].set_appearing_caption("Browse unofficial universes");
	gui.root.buttons[main_menu_button_type::HOST_UNIVERSE].set_appearing_caption("Host universe");
	gui.root.buttons[main_menu_button_type::CONNECT_TO_UNIVERSE].set_appearing_caption("Connect to universe");
	gui.root.buttons[main_menu_button_type::LOCAL_UNIVERSE].set_appearing_caption("Local universe");
	gui.root.buttons[main_menu_button_type::EDITOR].set_appearing_caption("Editor");
	gui.root.buttons[main_menu_button_type::SETTINGS].set_appearing_caption("Settings");
	gui.root.buttons[main_menu_button_type::CREATORS].set_appearing_caption("Founders");
	gui.root.buttons[main_menu_button_type::QUIT].set_appearing_caption("Quit");

	if (is_recording_available) {
		while (cosm.get_total_seconds_passed() < settings.rewind_intro_scene_by_secs) {
			//const auto entropy = cosmic_entropy(director.get_entropy_for_step(cosm.get_total_steps_passed() - initial_step_number), cosm);
			mode.advance(
				{ ruleset, cosm },
				mode_entropy(),
				solver_callbacks(),
				solve_settings()
			);
		}
	}
}
Example #6
0
        f.~factory_test();
        ++num_killed;
    }
};

int factory_test::num_saved = 0;
int factory_test::num_killed = 0;
const int factory_test::true_a = 156;

bool something() {
    return true;
}

TEST_CASE("table/traversal", "ensure that we can chain requests and tunnel down into a value if we desire") {

    sol::state lua;
    int begintop = 0, endtop = 0;

    sol::function scriptload = lua.load("t1 = {t2 = {t3 = 24}};");
    scriptload();
    {
        test_stack_guard g(lua.lua_state(), begintop, endtop);
        int traversex24 = lua.traverse_get<int>("t1", "t2", "t3");
        REQUIRE(traversex24 == 24);
    } REQUIRE(begintop == endtop);

    {
        test_stack_guard g(lua.lua_state(), begintop, endtop);
        int x24 = lua["t1"]["t2"]["t3"];
        REQUIRE(x24 == 24);
    } REQUIRE(begintop == endtop);
Example #7
0
};

int plop_xyz(int x, int y, std::string z) {
	INFO(x << " " << y << " " << z);
	return 11;
}

TEST_CASE("tables/as-enums", "Making sure enums can be put in and gotten out as values") {
	enum direction {
		up,
		down,
		left,
		right
	};
	
	sol::state lua;
	lua.open_libraries(sol::lib::base);

	lua["direction"] = lua.create_table_with(
		"up", direction::up,
		"down", direction::down,
		"left", direction::left,
		"right", direction::right
	);

	sol::object obj = lua["direction"]["up"];
	bool isdir = obj.is<direction>();
	REQUIRE(isdir);
	auto dir = obj.as<direction>();
	REQUIRE(dir == direction::up);
}
Example #8
0
// -----------------------------------------------------------------------------
// Registers the Game namespace with lua
// -----------------------------------------------------------------------------
void registerGameNamespace(sol::state& lua)
{
	auto game         = lua.create_table("Game");
	game["ThingType"] = [](int type) { return Game::configuration().thingType(type); };
}
Example #9
0
void Keyboard::luaBindings(
    sol::state &lua
){
    lua.new_usertype<Keyboard::KeyEvent>("KeyboardKeyEvent",

        "key", sol::readonly(&Keyboard::KeyEvent::key),
        "alt", sol::readonly(&Keyboard::KeyEvent::alt),
        "ctrl", sol::readonly(&Keyboard::KeyEvent::ctrl),
        "shift", sol::readonly(&Keyboard::KeyEvent::shift),
        "pressed", sol::readonly(&Keyboard::KeyEvent::pressed)
    );
    
    lua.new_usertype<Keyboard>("Keyboard",

        "new", sol::no_constructor,

        "isKeyDown", &Keyboard::isKeyDown,
        "wasKeyPressed", &Keyboard::wasKeyPressed,
        "wasKeyReleased", &Keyboard::wasKeyReleased
    );

    // This cannot be a template because template recursion goes too deep
    auto table = lua.create_table();

    table.set("KC_UNASSIGNED", OIS::KC_UNASSIGNED);
    table.set("KC_ESCAPE", OIS::KC_ESCAPE);
    table.set("KC_1", OIS::KC_1);
    table.set("KC_2", OIS::KC_2);
    table.set("KC_3", OIS::KC_3);
    table.set("KC_4", OIS::KC_4);
    table.set("KC_5", OIS::KC_5);
    table.set("KC_6", OIS::KC_6);
    table.set("KC_7", OIS::KC_7);
    table.set("KC_8", OIS::KC_8);
    table.set("KC_9", OIS::KC_9);
    table.set("KC_0", OIS::KC_0);
    table.set("KC_MINUS", OIS::KC_MINUS);
    table.set("KC_EQUALS", OIS::KC_EQUALS);
    table.set("KC_BACK", OIS::KC_BACK);
    table.set("KC_TAB", OIS::KC_TAB);
    table.set("KC_Q", OIS::KC_Q);
    table.set("KC_W", OIS::KC_W);
    table.set("KC_E", OIS::KC_E);
    table.set("KC_R", OIS::KC_R);
    table.set("KC_T", OIS::KC_T);
    table.set("KC_Y", OIS::KC_Y);
    table.set("KC_U", OIS::KC_U);
    table.set("KC_I", OIS::KC_I);
    table.set("KC_O", OIS::KC_O);
    table.set("KC_P", OIS::KC_P);
    table.set("KC_LBRACKET", OIS::KC_LBRACKET);
    table.set("KC_RBRACKET", OIS::KC_RBRACKET);
    table.set("KC_RETURN", OIS::KC_RETURN);
    table.set("KC_LCONTROL", OIS::KC_LCONTROL);
    table.set("KC_A", OIS::KC_A);
    table.set("KC_S", OIS::KC_S);
    table.set("KC_D", OIS::KC_D);
    table.set("KC_F", OIS::KC_F);
    table.set("KC_G", OIS::KC_G);
    table.set("KC_H", OIS::KC_H);
    table.set("KC_J", OIS::KC_J);
    table.set("KC_K", OIS::KC_K);
    table.set("KC_L", OIS::KC_L);
    table.set("KC_SEMICOLON", OIS::KC_SEMICOLON);
    table.set("KC_APOSTROPHE", OIS::KC_APOSTROPHE);
    table.set("KC_GRAVE", OIS::KC_GRAVE);
    table.set("KC_LSHIFT", OIS::KC_LSHIFT);
    table.set("KC_BACKSLASH", OIS::KC_BACKSLASH);
    table.set("KC_Z", OIS::KC_Z);
    table.set("KC_X", OIS::KC_X);
    table.set("KC_C", OIS::KC_C);
    table.set("KC_V", OIS::KC_V);
    table.set("KC_B", OIS::KC_B);
    table.set("KC_N", OIS::KC_N);
    table.set("KC_M", OIS::KC_M);
    table.set("KC_COMMA", OIS::KC_COMMA);
    table.set("KC_PERIOD", OIS::KC_PERIOD);
    table.set("KC_SLASH", OIS::KC_SLASH);
    table.set("KC_RSHIFT", OIS::KC_RSHIFT);
    table.set("KC_MULTIPLY", OIS::KC_MULTIPLY);
    table.set("KC_LMENU", OIS::KC_LMENU);
    table.set("KC_SPACE", OIS::KC_SPACE);
    table.set("KC_CAPITAL", OIS::KC_CAPITAL);
    table.set("KC_F1", OIS::KC_F1);
    table.set("KC_F2", OIS::KC_F2);
    table.set("KC_F3", OIS::KC_F3);
    table.set("KC_F4", OIS::KC_F4);
    table.set("KC_F5", OIS::KC_F5);
    table.set("KC_F6", OIS::KC_F6);
    table.set("KC_F7", OIS::KC_F7);
    table.set("KC_F8", OIS::KC_F8);
    table.set("KC_F9", OIS::KC_F9);
    table.set("KC_F10", OIS::KC_F10);
    table.set("KC_NUMLOCK", OIS::KC_NUMLOCK);
    table.set("KC_SCROLL", OIS::KC_SCROLL);
    table.set("KC_NUMPAD7", OIS::KC_NUMPAD7);
    table.set("KC_NUMPAD8", OIS::KC_NUMPAD8);
    table.set("KC_NUMPAD9", OIS::KC_NUMPAD9);
    table.set("KC_SUBTRACT", OIS::KC_SUBTRACT);
    table.set("KC_NUMPAD4", OIS::KC_NUMPAD4);
    table.set("KC_NUMPAD5", OIS::KC_NUMPAD5);
    table.set("KC_NUMPAD6", OIS::KC_NUMPAD6);
    table.set("KC_ADD", OIS::KC_ADD);
    table.set("KC_NUMPAD1", OIS::KC_NUMPAD1);
    table.set("KC_NUMPAD2", OIS::KC_NUMPAD2);
    table.set("KC_NUMPAD3", OIS::KC_NUMPAD3);
    table.set("KC_NUMPAD0", OIS::KC_NUMPAD0);
    table.set("KC_DECIMAL", OIS::KC_DECIMAL);
    table.set("KC_OEM_102", OIS::KC_OEM_102);
    table.set("KC_F11", OIS::KC_F11);
    table.set("KC_F12", OIS::KC_F12);
    table.set("KC_F13", OIS::KC_F13);
    table.set("KC_F14", OIS::KC_F14);
    table.set("KC_F15", OIS::KC_F15);
    table.set("KC_KANA", OIS::KC_KANA);
    table.set("KC_ABNT_C1", OIS::KC_ABNT_C1);
    table.set("KC_CONVERT", OIS::KC_CONVERT);
    table.set("KC_NOCONVERT", OIS::KC_NOCONVERT);
    table.set("KC_YEN", OIS::KC_YEN);
    table.set("KC_ABNT_C2", OIS::KC_ABNT_C2);
    table.set("KC_NUMPADEQUALS", OIS::KC_NUMPADEQUALS);
    table.set("KC_PREVTRACK", OIS::KC_PREVTRACK);
    table.set("KC_AT", OIS::KC_AT);
    table.set("KC_COLON", OIS::KC_COLON);
    table.set("KC_UNDERLINE", OIS::KC_UNDERLINE);
    table.set("KC_KANJI", OIS::KC_KANJI);
    table.set("KC_STOP", OIS::KC_STOP);
    table.set("KC_AX", OIS::KC_AX);
    table.set("KC_UNLABELED", OIS::KC_UNLABELED);
    table.set("KC_NEXTTRACK", OIS::KC_NEXTTRACK);
    table.set("KC_NUMPADENTER", OIS::KC_NUMPADENTER);
    table.set("KC_RCONTROL", OIS::KC_RCONTROL);
    table.set("KC_MUTE", OIS::KC_MUTE);
    table.set("KC_CALCULATOR", OIS::KC_CALCULATOR);
    table.set("KC_PLAYPAUSE", OIS::KC_PLAYPAUSE);
    table.set("KC_MEDIASTOP", OIS::KC_MEDIASTOP);
    table.set("KC_VOLUMEDOWN", OIS::KC_VOLUMEDOWN);
    table.set("KC_VOLUMEUP", OIS::KC_VOLUMEUP);
    table.set("KC_WEBHOME", OIS::KC_WEBHOME);
    table.set("KC_NUMPADCOMMA", OIS::KC_NUMPADCOMMA);
    table.set("KC_DIVIDE", OIS::KC_DIVIDE);
    table.set("KC_SYSRQ", OIS::KC_SYSRQ);
    table.set("KC_RMENU", OIS::KC_RMENU);
    table.set("KC_PAUSE", OIS::KC_PAUSE);
    table.set("KC_HOME", OIS::KC_HOME);
    table.set("KC_UP", OIS::KC_UP);
    table.set("KC_PGUP", OIS::KC_PGUP);
    table.set("KC_LEFT", OIS::KC_LEFT);
    table.set("KC_RIGHT", OIS::KC_RIGHT);
    table.set("KC_END", OIS::KC_END);
    table.set("KC_DOWN", OIS::KC_DOWN);
    table.set("KC_PGDOWN", OIS::KC_PGDOWN);
    table.set("KC_INSERT", OIS::KC_INSERT);
    table.set("KC_DELETE", OIS::KC_DELETE);
    table.set("KC_LWIN", OIS::KC_LWIN);
    table.set("KC_RWIN", OIS::KC_RWIN);
    table.set("KC_APPS", OIS::KC_APPS);
    table.set("KC_POWER", OIS::KC_POWER);
    table.set("KC_SLEEP", OIS::KC_SLEEP);
    table.set("KC_WAKE", OIS::KC_WAKE);
    table.set("KC_WEBSEARCH", OIS::KC_WEBSEARCH);
    table.set("KC_WEBFAVORITES", OIS::KC_WEBFAVORITES);
    table.set("KC_WEBREFRESH", OIS::KC_WEBREFRESH);
    table.set("KC_WEBSTOP", OIS::KC_WEBSTOP);
    table.set("KC_WEBFORWARD", OIS::KC_WEBFORWARD);
    table.set("KC_WEBBACK", OIS::KC_WEBBACK);
    table.set("KC_MYCOMPUTER", OIS::KC_MYCOMPUTER);
    table.set("KC_MAIL", OIS::KC_MAIL);
    table.set("KC_MEDIASELECT", OIS::KC_MEDIASELECT);
    
    lua["KEYCODE"] = table;

}