コード例 #1
0
ファイル: RedexResources.cpp プロジェクト: 272152441/redex
/**
 * Return a list of all the .so files in /lib
 */
std::vector<std::string> find_native_library_files(const std::string& apk_directory) {
  std::vector<std::string> native_library_files;
  std::string lib_root = apk_directory + std::string("/lib");
  std::string library_extension(".so");

  path_t lib(lib_root);

  if (exists(lib) && is_directory(lib)) {
    for (auto it = rdir_iterator(lib); it != rdir_iterator(); ++it) {
      auto const& entry = *it;
      path_t entry_path = entry.path();
      if (is_regular_file(entry_path) &&
          ends_with(entry_path.filename().string().c_str(),
                    library_extension.c_str())) {
        native_library_files.push_back(entry_path.string());
      }
    }
  }
  return native_library_files;
}
コード例 #2
0
	int extloader(lua_State * L)
	{
		const char * filename = lua_tostring(L, -1);
		std::string tokenized_name(filename);
		std::string tokenized_function(filename);

		for (unsigned int i = 0; i < tokenized_name.size(); i++)
		{
			if (tokenized_name[i] == '.')
			{
				tokenized_name[i] = '/';
				tokenized_function[i] = '_';
			}
		}

		tokenized_name += library_extension();

		void * handle = SDL_LoadObject((std::string(instance->getAppdataDirectory()) + LOVE_PATH_SEPARATOR LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR + tokenized_name).c_str());
		if (!handle && instance->isRelease())
			handle = SDL_LoadObject((std::string(instance->getSaveDirectory()) + LOVE_PATH_SEPARATOR + tokenized_name).c_str());

		if (!handle)
		{
			lua_pushfstring(L, "\n\tno extension \"%s\" in LOVE paths.\n", filename);
			return 1;
		}

		void * func = SDL_LoadFunction(handle, ("loveopen_" + tokenized_function).c_str());
		if (!func)
			func = SDL_LoadFunction(handle, ("luaopen_" + tokenized_function).c_str());

		if (!func)
		{
			SDL_UnloadObject(handle);
			lua_pushfstring(L, "\n\textension \"%s\" is incompatible.\n", filename);
			return 1;
		}

		lua_pushcfunction(L, (lua_CFunction) func);
		return 1;
	}
コード例 #3
0
int extloader(lua_State *L)
{
	const char *filename = lua_tostring(L, -1);
	std::string tokenized_name(filename);
	std::string tokenized_function(filename);

	for (unsigned int i = 0; i < tokenized_name.size(); i++)
	{
		if (tokenized_name[i] == '.')
		{
			tokenized_name[i] = '/';
			tokenized_function[i] = '_';
		}
	}

	tokenized_name += library_extension();

	void *handle = nullptr;

	// If the game is fused, try looking for the DLL in the game's read paths.
	if (instance()->isFused())
	{
		try
		{
			std::string dir = instance()->getRealDirectory(tokenized_name.c_str());

			// We don't want to look in the game's source, because it can be a
			// zip sometimes and a folder other times.
			if (dir.find(instance()->getSource()) == std::string::npos)
				handle = SDL_LoadObject((dir + LOVE_PATH_SEPARATOR + tokenized_name).c_str());
		}
		catch (love::Exception &)
		{
			// Nothing...
		}
	}

	if (!handle)
	{
		std::string path = std::string(instance()->getAppdataDirectory()) + LOVE_PATH_SEPARATOR LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR + tokenized_name;
		handle = SDL_LoadObject(path.c_str());
	}

	if (!handle)
	{
		lua_pushfstring(L, "\n\tno file '%s' in LOVE paths.", tokenized_name.c_str());
		return 1;
	}

	void *func = SDL_LoadFunction(handle, ("loveopen_" + tokenized_function).c_str());
	if (!func)
		func = SDL_LoadFunction(handle, ("luaopen_" + tokenized_function).c_str());

	if (!func)
	{
		SDL_UnloadObject(handle);
		lua_pushfstring(L, "\n\tC library '%s' is incompatible.", tokenized_name.c_str());
		return 1;
	}

	lua_pushcfunction(L, (lua_CFunction) func);
	return 1;
}