예제 #1
0
int loader(lua_State *L)
{
	std::string modulename = luax_tostring(L, 1);

	for (char &c : modulename)
	{
		if (c == '.')
			c = '/';
	}

	auto *inst = instance();
	for (std::string element : inst->getRequirePath())
	{
		size_t pos = element.find('?');
		if (pos != std::string::npos)
			element.replace(pos, 1, modulename);

		if (inst->isFile(element.c_str()))
		{
			lua_pop(L, 1);
			lua_pushstring(L, element.c_str());
			return w_load(L);
		}
	}

	std::string errstr = "\n\tno '%s' in LOVE game directories.";

	lua_pushfstring(L, errstr.c_str(), modulename.c_str());
	return 1;
}
예제 #2
0
void LuaThread::threadFunction()
{
	this->retain();
	error.clear();

	lua_State *L = luaL_newstate();
	luaL_openlibs(L);

#ifdef LOVE_BUILD_STANDALONE
	luax_preload(L, luaopen_love, "love");
	luax_require(L, "love");
	lua_pop(L, 1);
#endif // LOVE_BUILD_STANDALONE

	luax_require(L, "love.thread");
	lua_pop(L, 1);

	// We load love.filesystem by default, since require still exists without it
	// but won't load files from the proper paths. love.filesystem also must be
	// loaded before using any love function that can take a filepath argument.
	luax_require(L, "love.filesystem");
	lua_pop(L, 1);

	if (luaL_loadbuffer(L, (const char *) code->getData(), code->getSize(), name.c_str()) != 0)
		error = luax_tostring(L, -1);
	else
	{
		int pushedargs = (int) args.size();

		for (int i = 0; i < pushedargs; i++)
			args[i].toLua(L);

		args.clear();

		if (lua_pcall(L, pushedargs, 0, 0) != 0)
			error = luax_tostring(L, -1);
	}

	lua_close(L);

	if (!error.empty())
		onError();

	this->release();
}
예제 #3
0
파일: LuaThread.cpp 프로젝트: joedrago/love
void LuaThread::threadFunction()
{
	this->retain();
	lua_State * L = lua_open();
	luaL_openlibs(L);
#ifdef LOVE_BUILD_STANDALONE
	love::luax_preload(L, luaopen_love, "love");
	luaopen_love(L);
#endif // LOVE_BUILD_STANDALONE
	luaopen_love_thread(L);
	if (luaL_loadbuffer(L, (const char *) code->getData(), code->getSize(), name.c_str()) != 0)
		error = luax_tostring(L, -1);
	else
		if (lua_pcall(L, 0, 0, 0) != 0)
			error = luax_tostring(L, -1);
	lua_close(L);
	this->release();
}