//! (static)
std::pair<bool, ObjRef> loadAndExecute(Runtime & runtime, const std::string & filename) {
	ObjRef script;
	try {
		script = loadScriptFile(filename);
	} catch (Exception * error) {
		std::cerr << "\nError occurred while loading file '" << filename << "':\n" << error->toString() << std::endl;
		return std::make_pair(false, error);
	}
	bool success = true;
	ObjRef result;
	try {
		runtime.executeObj(script.get());
		result = runtime.getResult();
		if(runtime.getState() == Runtime::STATE_EXCEPTION) {
			std::cout << "\nException caught (1):\n" << result.toString() << std::endl;
			success = false;
		}
	} catch (Object * o) {
		result = o;
		std::cout << "\nException caught (2):\n" << result.toString() << std::endl;
		success = false;
	} catch (...) {
		std::cout << "\nCaught unknown C++ exception." << std::endl;
		success = false;
	}
	return std::make_pair(success, result);
}
Beispiel #2
0
void RuntimeJsImpl::onStartDebuger(const rapidjson::Document& dArgParse, rapidjson::Document& dReplyParse)
{
    if (loadScriptFile(ConfigParser::getInstance()->getEntryFile()))
    {
        dReplyParse.AddMember("code",0,dReplyParse.GetAllocator());
    }
    else
    {
        dReplyParse.AddMember("code",1,dReplyParse.GetAllocator());
    }
}
Beispiel #3
0
void RuntimeJsImpl::startScript(const std::string& path)
{
    loadScriptFile(path);
}