当前位置: 首页>>代码示例>>C++>>正文


C++ CScriptBuilder类代码示例

本文整理汇总了C++中CScriptBuilder的典型用法代码示例。如果您正苦于以下问题:C++ CScriptBuilder类的具体用法?C++ CScriptBuilder怎么用?C++ CScriptBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CScriptBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: asCreateScriptEngine

bool CommonAPI::InitAS()
{
	engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL);
	RegisterStdString(engine);

	RegisterAPI();

	CScriptBuilder builder;

	if(builder.StartNewModule(engine, "MyModule") < 0)
		FILE_LOG(logERROR) << "Unrecoverable error while starting a new module.";

	string scriptPath = exePath.substr(0, exePath.find_last_of(".")).append(".tes");

	if(builder.AddSectionFromFile(scriptPath.c_str()) < 0)
		FILE_LOG(logERROR) << "Unable to load script." << scriptPath;
	else
		FILE_LOG(logINFO) << "Script " << scriptPath << " loaded successfully.";

	if(builder.BuildModule() < 0)
		FILE_LOG(logERROR) << "Please correct the errors in the script and try again.";

	
	module = engine->GetModule("MyModule");

	return true;
}
开发者ID:lenny93,项目名称:TouchEnabler,代码行数:28,代码来源:common.cpp

示例2: TestExecuteScript

bool TestExecuteScript()
{
	bool fail = false;
	COutStream out;

	engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);
	
	RegisterStdString(engine);
	engine->RegisterGlobalFunction("void assert(bool)", asFUNCTION(Assert), asCALL_GENERIC);

	CScriptBuilder builder;

	int r = builder.StartNewModule(engine, 0);
	if( r >= 0 )
		r = builder.AddSectionFromFile("scripts/TestExecuteScript.as");
	if( r >= 0 )
		r = builder.BuildModule();
	if( r >= 0 )
	{
		fail = ExecuteScript();
	}

	engine->Release();
	engine = NULL;

	return fail;
}
开发者ID:Naddiseo,项目名称:Angelscript-fork,代码行数:28,代码来源:testexecutescript.cpp

示例3: load_and_build_script

bool ASXEngine::load_and_build_script(const std::string& filename, const std::string& moduleName)
{
    CScriptBuilder builder;
    if(builder.StartNewModule(m_engine, moduleName.c_str()) < 0) return false;
    if(builder.AddSectionFromFile(filename.c_str()) < 0) return false;
    return builder.BuildModule() == 0;
}
开发者ID:sgolodetz,项目名称:hesperus2,代码行数:7,代码来源:ASXEngine.cpp

示例4: LoadScript

//======================================================================
HSISCRIPT CScriptInt::LoadScript(const std::string& szScriptName)
{
	//Load script

	if ((!this->m_bInitialized) || (!szScriptName.length()))
		return SI_INVALID_ID;

	CScriptBuilder oScriptBuilder;

	//Start new module
	if (AS_FAILED(oScriptBuilder.StartNewModule(this->m_pScriptEngine, szScriptName.c_str())))
		return SI_INVALID_ID;

	//Add script file to module
	if (AS_FAILED(oScriptBuilder.AddSectionFromFile((/*this->m_szScriptPath +*/ szScriptName/* + ".as"*/).c_str())))
		return SI_INVALID_ID;

	//Build script module
	if (AS_FAILED(oScriptBuilder.BuildModule()))
		return SI_INVALID_ID;

	//Setup struct
	si_script_s sScriptData;
	sScriptData.szName = szScriptName;
	sScriptData.pModule = this->m_pScriptEngine->GetModule(szScriptName.c_str()); //Get pointer to script module
	if (!sScriptData.pModule)
		return SI_INVALID_ID;
	
	//Add to list
	this->m_vScripts.push_back(sScriptData);
	
	return this->m_vScripts.size() - 1; //Return entry ID
}
开发者ID:sk0r-Czybik,项目名称:sk0r_Spaceshooter,代码行数:34,代码来源:scriptint.cpp

示例5: CreateFromFile

	bool cSqScript::CreateFromFile(const tString& asFileName)
	{
		CScriptBuilder builder;

		builder.StartNewModule(mpScriptEngine,msModuleName.c_str());

		if(builder.AddSectionFromFile(asFileName.c_str())<0)
		{
			Error("Couldn't add script '%s'!\n",asFileName.c_str());
			return false;
		}

		if(builder.BuildModule()<0)
		{
			Error("Couldn't build script '%s'!\n",asFileName.c_str());
			Log("------- SCRIPT OUTPUT BEGIN --------------------------\n");
			mpScriptOutput->Display();
			mpScriptOutput->Clear();
			Log("------- SCRIPT OUTPUT END ----------------------------\n");
			return false;
		}
		mpScriptOutput->Clear();

		return true;
	}
开发者ID:Naddiseo,项目名称:HPL1Engine,代码行数:25,代码来源:SqScript.cpp

示例6: LoadScript

//************************************
// Method:    LoadScript
// FullName:  ScriptEngine::LoadScript
// Access:    public 
// Returns:   bool
// Qualifier:
// Parameter: const char * filename  Name of the scripted file to load
//************************************
bool ScriptEngine::LoadScript(const char* filename, const char* module)
{
	CScriptBuilder builder;

	bool OK = builder.StartNewModule(m_engine, module) > 0;
	OK = OK && (builder.AddSectionFromFile(filename) > 0);
	OK = OK && (builder.BuildModule() > 0);

	return OK;
}
开发者ID:Nuclearfossil,项目名称:wanton,代码行数:18,代码来源:ScriptEngine.cpp

示例7: Test

bool Test()
{
	bool fail = false;
	int r = 0;
	COutStream out;

	// TODO: Preprocessor directives should be alone on the line

	asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

	engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL);

	// Test the parse token method
	asETokenClass t = engine->ParseToken("!is");
	if( t != asTC_KEYWORD )
		fail = true;

	// Compile a script with meta data strings
	CScriptBuilder builder;
	builder.DefineWord("COMPILE");
	r = builder.BuildScriptFromMemory(engine, 0, script);
#if AS_PROCESS_METADATA == 1
	if( r < 0 )
		fail = true;

	int funcId = engine->GetModule(0)->GetFunctionIdByName("func1");
	string metadata = builder.GetMetadataStringForFunc(funcId);
	if( metadata != " my meta data test " )
		fail = true;

	funcId = engine->GetModule(0)->GetFunctionIdByName("func2");
	metadata = builder.GetMetadataStringForFunc(funcId);
	if( metadata != " test['hello'] " )
		fail = true;

	int typeId = engine->GetModule(0)->GetTypeIdByDecl("MyClass");
	metadata = builder.GetMetadataStringForType(typeId);
	if( metadata != " myclass " )
		fail = true;

	typeId = engine->GetModule(0)->GetTypeIdByDecl("MyIntf");
	metadata = builder.GetMetadataStringForType(typeId);
	if( metadata != " myintf " )
		fail = true;

	int varIdx = engine->GetModule(0)->GetGlobalVarIndexByName("g_var");
	metadata = builder.GetMetadataStringForVar(varIdx);
	if( metadata != " init " )
		fail = true;

	varIdx = engine->GetModule(0)->GetGlobalVarIndexByName("g_obj");
	metadata = builder.GetMetadataStringForVar(varIdx);
	if( metadata != " var of type myclass " )
		fail = true;
#endif

	engine->Release();

	return fail;
}
开发者ID:svn2github,项目名称:AngelscriptMirror,代码行数:60,代码来源:test_metadata.cpp

示例8: load

NEPHILIM_NS_BEGIN

bool ASXModuleBuilder::load(ASXEngine& engine, const String& filename, const String& module)
{
	CScriptBuilder builder;
	builder.StartNewModule(engine.get(), module.c_str());
	builder.AddSectionFromFile(filename.c_str());
	if(builder.BuildModule() > 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
开发者ID:GrimshawA,项目名称:Nephilim,代码行数:16,代码来源:ASXModuleBuilder.cpp

示例9: CompileScript

int CompileScript(asIScriptEngine *engine)
{
	int r;

	// The builder is a helper class that will load the script file, 
	// search for #include directives, and load any included files as 
	// well.
	CScriptBuilder builder;

	// Build the script. If there are any compiler messages they will
	// be written to the message stream that we set right after creating the 
	// script engine. If there are no errors, and no warnings, nothing will
	// be written to the stream.
	r = builder.StartNewModule(engine, 0);
	if( r < 0 )
	{
		cout << "Failed to start new module" << endl;
		return r;
	}
	r = builder.AddSectionFromFile("script.as");
	if( r < 0 )
	{
		cout << "Failed to add script file" << endl;
		return r;
	}
	r = builder.BuildModule();
	if( r < 0 )
	{
		cout << "Failed to build the module" << endl;
		return r;
	}
	
	// The engine doesn't keep a copy of the script sections after Build() has
	// returned. So if the script needs to be recompiled, then all the script
	// sections must be added again.

	// If we want to have several scripts executing at different times but 
	// that have no direct relation with each other, then we can compile them
	// into separate script modules. Each module use their own namespace and 
	// scope, so function names, and global variables will not conflict with
	// each other.

	return 0;
}
开发者ID:trigger-happy,项目名称:M_dependencies,代码行数:44,代码来源:main.cpp

示例10: CompileScript

int CompileScript(asIScriptEngine *engine, const char *scriptFile)
{
	int r;

	CScriptBuilder builder;
	r = builder.StartNewModule(engine, "build");
	if( r < 0 ) return -1;

	r = builder.AddSectionFromFile(scriptFile);
	if( r < 0 ) return -1;

	r = builder.BuildModule();
	if( r < 0 )
	{
		engine->WriteMessage(scriptFile, 0, 0, asMSGTYPE_ERROR, "Script failed to build");
		return -1;
	}

	engine->WriteMessage(scriptFile, 0, 0, asMSGTYPE_INFORMATION, "Script successfully built");

	return 0;
}
开发者ID:BrentChua,项目名称:Pulse-Tec,代码行数:22,代码来源:main.cpp

示例11: run

void run(GLFWwindow* window, std::string const& scriptFile)
{
  asIScriptEngine* engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
  anglhck::registerToEngine(engine);

  RegisterStdString(engine);
  engine->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(print), asCALL_CDECL);

  CScriptBuilder builder;
  builder.StartNewModule(engine, "MyModule");
  builder.AddSectionFromFile(scriptFile);
  builder.BuildModule();
  asIScriptModule *mod = engine->GetModule("MyModule");
  asIScriptFunction *func = mod->GetFunctionByDecl("void main()");
  asIScriptContext *ctx = engine->CreateContext();
  ctx->Prepare(func);
  int ret = ctx->Execute();

  if( ret == asEXECUTION_EXCEPTION )
  {
    std::cout << ctx->GetExceptionString() << std::endl;
  }
}
开发者ID:Cloudef,项目名称:anglhck,代码行数:23,代码来源:anglhck.cpp

示例12: CompileScript

int CompileScript(asIScriptEngine *engine, const char *scriptFile)
{
	int r;

	// We will only initialize the global variables once we're 
	// ready to execute, so disable the automatic initialization
	engine->SetEngineProperty(asEP_INIT_GLOBAL_VARS_AFTER_BUILD, false);

	CScriptBuilder builder;
	r = builder.StartNewModule(engine, "script");
	if( r < 0 ) return -1;

	r = builder.AddSectionFromFile(scriptFile);
	if( r < 0 ) return -1;

	r = builder.BuildModule();
	if( r < 0 )
	{
		engine->WriteMessage(scriptFile, 0, 0, asMSGTYPE_ERROR, "Script failed to build");
		return -1;
	}

	return 0;
}
开发者ID:galexcode,项目名称:ParabolaEngine,代码行数:24,代码来源:main.cpp

示例13: if

bool ScriptManager::loadFromMemory(const std::string& name, const void* data, size_t len, ScriptType type)
{
	std::string lower;
	std::transform(name.begin(), name.end(), std::back_inserter(lower), ::tolower);

	if (type == Type_Autodetect)
	{
		if (lower.substr(lower.size() - 4) == ".asb")
			type = Type_Bytecode;
		else if (lower.substr(lower.size() - 3) == ".as")
			type = Type_Text;
		else
			return false;
	}

	bool reload = mScripts.count(lower) > 0;

	std::list<asIScriptObject*> changes;

	asIScriptModule* module = mEngine->GetModule(lower.c_str(), asGM_ONLY_IF_EXISTS);
	CSerializer serial;

	if (reload && module)
	{
		for (auto& reg : mSerializers)
			serial.AddUserType(reg.second(), reg.first);

		for (auto it = mChangeNotice.begin(); it != mChangeNotice.end();)
		{
			if (it->second.WeakRef->Get())
			{
				it->second.WeakRef->Release();
				it = mChangeNotice.erase(it);
				continue;
			}

			auto* obj = it->first;

			if (obj->GetObjectType()->GetModule() == module)
			{
				serial.AddExtraObjectToStore(obj);

				changes.push_back(it->first);
			}

			++it;
		}

		serial.Store(module);
	}

	BytecodeStore bcode;
	if (type == Type_Text)
	{
		static const char* scratchName = "!!ScratchSpace!!";
		CScriptBuilder builder;

		for (auto& def : mDefines)
			builder.DefineWord(def.c_str());

		builder.StartNewModule(mEngine, scratchName);

		for (auto& callback : mPreLoadCallbacks)
			if (!callback.second(builder.GetModule()))
			{
				mEngine->DiscardModule(scratchName);
				return false;
			}

		builder.AddSectionFromMemory(lower.c_str(), (const char*)data, len);

		int r = builder.BuildModule();
		if (r < 0)
		{
#ifndef NDEBUG
			puts(ASException::GetMessage(r));
#endif
			return false;
		}

#ifdef NDEBUG
		builder.GetModule()->SaveByteCode(&bcode, true);
#else
		builder.GetModule()->SaveByteCode(&bcode, false);
#endif

		mEngine->DiscardModule(scratchName);
	}
	else
	{
		bcode = BytecodeStore((const char*)data, len);
	}

	if (module)
		module->Discard();

	module = mEngine->GetModule(lower.c_str(), asGM_ALWAYS_CREATE);

	// FIXME? Preload callbacks can not act on bytecode anyway
	/*
//.........这里部分代码省略.........
开发者ID:ace13,项目名称:AngelscriptMP,代码行数:101,代码来源:ScriptManager.cpp

示例14: AddScripts

	bool AddScripts( CScriptBuilder& builder ) override
	{
		//Assumes the working directory is <repo>/working_dir
		return builder.AddSectionFromFile( "../tests/test_MySQL.as" ) >= 0;
	}
开发者ID:SamVanheer,项目名称:ASSQL,代码行数:5,代码来源:Main.cpp

示例15: RegisterDefinedWords

static void RegisterDefinedWords(const std::vector<gs2d::str_type::string>& definedWords, CScriptBuilder& builder, const bool isTesting)
{
	#if defined(_DEBUG) || defined(DEBUG)
		builder.DefineWord("DEBUG");
	#endif
	#ifdef ANDROID
		builder.DefineWord("ANDROID");
	#endif
	#ifdef APPLE_IOS
		builder.DefineWord("APPLE_IOS");
	#endif
	#ifdef MACOSX
		builder.DefineWord("MACOSX");
	#endif
	#ifdef WIN32
		builder.DefineWord("WINDOWS");
	#endif
	#ifdef LINUX
		builder.DefineWord("LINUX");
	#endif
	#if defined(APPLE_IOS) || defined(ANDROID)
		builder.DefineWord("MOBILE");
		builder.DefineWord("MOBILE_DEVICE");
		builder.DefineWord("HANDHELD");
		builder.DefineWord("HANDHELD_DEVICE");
	#endif
	#if defined(WIN32) || defined(MACOSX) || defined(LINUX)
		builder.DefineWord("DESKTOP");
	#endif

	if (isTesting)
	{
		builder.DefineWord("TESTING");
	}

	// register custom words (defined in the app.enml)
	for (std::size_t t = 0; t < definedWords.size(); t++)
	{
		builder.DefineWord(definedWords[t].c_str());
	}
}
开发者ID:mattguest,项目名称:ethanon,代码行数:41,代码来源:ETHEngine.cpp


注:本文中的CScriptBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。