示例#1
0
ScScript *ScEngine::runScript(const char *filename, BaseScriptHolder *owner) {
	byte *compBuffer;
	uint32 compSize;

	// get script from cache
	compBuffer = getCompiledScript(filename, &compSize);
	if (!compBuffer) {
		return nullptr;
	}

	// add new script
	ScScript *script = new ScScript(_gameRef, this);
	bool ret = script->create(filename, compBuffer, compSize, owner);
	if (DID_FAIL(ret)) {
		_gameRef->LOG(ret, "Error running script '%s'...", filename);
		delete script;
		return nullptr;
	} else {
		// publish the "self" pseudo-variable
		ScValue val(_gameRef);
		if (owner) {
			val.setNative(owner, true);
		} else {
			val.setNULL();
		}

		script->_globals->setProp("self", &val);
		script->_globals->setProp("this", &val);

		_scripts.add(script);

		return script;
	}
}
示例#2
0
文件: script.cpp 项目: bSr43/scummvm
ScScript *ScScript::invokeEventHandler(const Common::String &eventName, bool unbreakable) {
	//if (_state!=SCRIPT_PERSISTENT) return nullptr;

	uint32 pos = getEventPos(eventName);
	if (!pos) {
		return nullptr;
	}
#if EXTENDED_DEBUGGER_ENABLED == true
	// TODO: Not pretty
	DebuggableScEngine* debuggableEngine;
	debuggableEngine = dynamic_cast<DebuggableScEngine*>(_engine);
	assert(debuggableEngine);
	ScScript *thread = new DebuggableScript(_gameRef,  debuggableEngine);
#else
	ScScript *thread = new ScScript(_gameRef,  _engine);
#endif
	if (thread) {
		bool ret = thread->createThread(this, pos, eventName);
		if (DID_SUCCEED(ret)) {
			thread->_unbreakable = unbreakable;
			_engine->_scripts.add(thread);
			return thread;
		} else {
			delete thread;
			return nullptr;
		}
	} else {
		return nullptr;
	}

}
示例#3
0
bool ScScript::finishThreads() {
	for (uint32 i = 0; i < _engine->_scripts.size(); i++) {
		ScScript *scr = _engine->_scripts[i];
		if (scr->_thread && scr->_state != SCRIPT_FINISHED && scr->_owner == _owner && scumm_stricmp(scr->_filename, _filename) == 0) {
			scr->finish(true);
		}
	}
	return STATUS_OK;
}
示例#4
0
ScScript *BaseScriptHolder::invokeMethodThread(const char *methodName) {
	for (int i = _scripts.size() - 1; i >= 0; i--) {
		if (_scripts[i]->canHandleMethod(methodName)) {

			ScScript *thread = new ScScript(_gameRef,  _scripts[i]->_engine);
			if (thread) {
				bool ret = thread->createMethodThread(_scripts[i], methodName);
				if (DID_SUCCEED(ret)) {
					_scripts[i]->_engine->_scripts.add(thread);
					return thread;
				} else {
					delete thread;
				}
			}
		}
	}
	return NULL;
}
示例#5
0
ScScript *ScScript::invokeEventHandler(const Common::String &eventName, bool unbreakable) {
	//if (_state!=SCRIPT_PERSISTENT) return nullptr;

	uint32 pos = getEventPos(eventName);
	if (!pos) {
		return nullptr;
	}

	ScScript *thread = new ScScript(_gameRef,  _engine);
	if (thread) {
		bool ret = thread->createThread(this, pos, eventName);
		if (DID_SUCCEED(ret)) {
			thread->_unbreakable = unbreakable;
			_engine->_scripts.add(thread);
			return thread;
		} else {
			delete thread;
			return nullptr;
		}
	} else {
		return nullptr;
	}

}