Esempio n. 1
0
bool ScriptInterface::LoadScript(const VfsPath& filename, const std::string& code)
{

	JSAutoRequest rq(m->m_cx);
	JS::RootedObject global(m->m_cx, m->m_glob);
	utf16string codeUtf16(code.begin(), code.end());
	uint lineNo = 1;
	// CompileOptions does not copy the contents of the filename string pointer.
	// Passing a temporary string there will cause undefined behaviour, so we create a separate string to avoid the temporary.
	std::string filenameStr(utf8_from_wstring(filename.string()));

	JS::CompileOptions options(m->m_cx);
	options.setFileAndLine(filenameStr.c_str(), lineNo);
	options.setCompileAndGo(true);

	JS::RootedFunction func(m->m_cx,
	JS_CompileUCFunction(m->m_cx, global, NULL, 0, NULL,
			reinterpret_cast<const jschar*> (codeUtf16.c_str()), (uint)(codeUtf16.length()), options)
	);
	if (!func)
		return false;

	JS::RootedValue rval(m->m_cx);
	return JS_CallFunction(m->m_cx, JS::NullPtr(), func, JS::HandleValueArray::empty(), &rval);
}
void ClientHandler::SendOpenFileCommand(CefRefPtr<CefBrowser> browser, const CefString &filename) {
  std::string filenameStr(filename);
  // FIXME: Use SendJSCommand once it supports parameters
  std::string cmd = "require('command/CommandManager').execute('file.addToWorkingSet',{fullPath:'" + filenameStr + "'})";
  browser->GetMainFrame()->ExecuteJavaScript(CefString(cmd.c_str()),
                                browser->GetMainFrame()->GetURL(), 0);
}
Esempio n. 3
0
Sound::Sound(const char *filename) 
{
	std::string filenameStr(filename);
	
	if(soundPool.find(filenameStr) != soundPool.end())
		chunk = soundPool[filenameStr];
	else
		chunk = soundPool[filenameStr] = Mix_LoadWAV(filename);
}
Esempio n. 4
0
int output(lua_State *L)
{
	int args = lua_gettop(L);
	assert(0 < args);
	const char* filename = lua_tostring(L, 1);
	LuaOutput& output = getLuaOutput(L);
	int result = 0;
	if (filename)
	{
		std::string filenameStr(filename);
		std::map<std::string, CodeStream>::iterator ics = output.cstreams.find(filenameStr);
		std::map<std::string, std::fstream*>::iterator ifs = output.fstreams.find(filenameStr);

		if (ifs == output.fstreams.end())
			ifs = output.fstreams.insert(std::make_pair(filenameStr, new std::fstream)).first;

		std::fstream& file = *ifs->second;

		if (ics == output.cstreams.end())
			ics = output.cstreams.insert(std::make_pair(filenameStr, CodeStream(file, std::string("")))).first;

		if (!file.is_open())
		{
			boost::filesystem::path path(filename);
			path.remove_filename();
			boost::filesystem::create_directories(path);
			file.open(filename, std::ios::out);

		}
		if (file.is_open()) output.current = &ics->second;
		else
		{
			lua_pushfstring(L, "could not open file `%s'", filename);
			output.current = 0;
			result = 1;
		}
	}
	else
	{
		output.current = &output.stdoutstream;
	}

	return result;
}
Esempio n. 5
0
bool includeFile(SpriteNode* node, TiXmlElement* includeNode, SpriteBlock* &oldSibling)
{
	string filenameStr("buildings/include/");
	filenameStr.append(includeNode->Attribute("file"));

	TiXmlDocument doc( filenameStr.c_str() );
	bool loadOkay = doc.LoadFile();
	TiXmlHandle hDoc(&doc);
	TiXmlElement* elemParent;
	if(!loadOkay)
	{
		contentError("Include failed",includeNode);
		WriteErr("File load failed: %s\n",filenameStr.c_str());
		WriteErr("Line %d: %s\n",doc.ErrorRow(),doc.ErrorDesc());
		return false;
	}
	elemParent = hDoc.FirstChildElement("include").Element();
	if( elemParent == NULL)
	{
		contentError("Main <include> node not present",&doc);
		return false;
	}
	TiXmlElement* elemNode =  elemParent->FirstChildElement();
	if (elemNode == NULL)
	{
		contentError("Empty include",elemParent);
		return false;
	}
	while (elemNode)
	{ 
		if (!readNode(node, elemNode, elemParent, oldSibling))
			return false;
		elemNode = elemNode->NextSiblingElement();
	}
	return true;
}