本文整理汇总了C++中CScriptBuilder::GetModule方法的典型用法代码示例。如果您正苦于以下问题:C++ CScriptBuilder::GetModule方法的具体用法?C++ CScriptBuilder::GetModule怎么用?C++ CScriptBuilder::GetModule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CScriptBuilder
的用法示例。
在下文中一共展示了CScriptBuilder::GetModule方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadFromMemory
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
/*
//.........这里部分代码省略.........