AngelScript UniqueModule type

This commit is contained in:
Jack Andersen 2015-07-16 14:02:19 -10:00
parent 4252bd6e39
commit 050085cc6d
5 changed files with 70 additions and 13 deletions

View File

@ -30,7 +30,7 @@ public:
HECL::Database::IDataSpec* ds = entry->m_factory(HECL::Database::TOOL_EXTRACT);
if (ds)
{
if (ds->canExtract(m_einfo, m_reps))
if (ds->canExtract(*m_info.project, m_einfo, m_reps))
m_dataSpecs.emplace_back(ds);
else
delete ds;

@ -1 +1 @@
Subproject commit 94a6707dd32e6aed988c7606c6c28836a398ad6d
Subproject commit 94d84d8991dd0c6b5fdb5557476eb4c3421d7b09

View File

@ -12,6 +12,7 @@
#include <memory>
#include <atomic>
#include <stdexcept>
#include <fstream>
#include <stdint.h>
#include <assert.h>
@ -110,11 +111,46 @@ public:
};
struct ASStringType : ASType<std::string>
{
ASStringType();
};
{ASStringType();};
extern ASStringType asSTRINGTYPE;
/**
* @brief AngelScript Module Wrapper designed for HECL usage
*
* Behaves similarly to unique_ptr. Move construction/assignment only
* Implicit conversion is supplied for seamless usage as a module reference
*/
class ASUniqueModule
{
AngelScript::asIScriptModule* m_mod;
ASUniqueModule() {m_mod = nullptr;}
ASUniqueModule(AngelScript::asIScriptModule* mod) : m_mod(mod) {}
public:
~ASUniqueModule() {if (m_mod) m_mod->Discard();}
ASUniqueModule(ASUniqueModule&& other) = default;
ASUniqueModule(ASUniqueModule& other) = delete;
ASUniqueModule& operator=(ASUniqueModule&& other) = default;
ASUniqueModule& operator=(ASUniqueModule& other) = delete;
inline operator AngelScript::asIScriptModule&() {return *m_mod;}
inline operator bool() {return m_mod != nullptr;}
static ASUniqueModule CreateFromCode(const char* module, const char* code)
{
AngelScript::asIScriptModule* mod = asENGINE->GetModule(module, AngelScript::asGM_ALWAYS_CREATE);
assert(mod);
assert(mod->AddScriptSection(module, code) >= 0);
if (mod->Build() >= 0)
return ASUniqueModule(mod);
else
return ASUniqueModule();
}
static ASUniqueModule CreateFromPath(const ProjectPath& path)
{
std::string asStr;
std::ifstream(path.getAbsolutePath()) >> asStr;
return CreateFromCode(path.getRelativePathUTF8().c_str(), asStr.c_str());
}
};
extern LogVisor::LogModule LogModule;
/**
@ -179,9 +215,9 @@ public:
std::vector<ExtractReport> childOpts;
};
virtual bool canExtract(const ExtractPassInfo& info, std::vector<ExtractReport>& reps)
{(void)info;LogModule.report(LogVisor::Error, "not implemented");return false;}
virtual void doExtract(const Project& project, const ExtractPassInfo& info)
virtual bool canExtract(Project& project, const ExtractPassInfo& info, std::vector<ExtractReport>& reps)
{(void)project;(void)info;LogModule.report(LogVisor::Error, "not implemented");return false;}
virtual void doExtract(Project& project, const ExtractPassInfo& info)
{(void)project;(void)info;}
/**
@ -294,7 +330,7 @@ protected:
typedef std::function<void(const void* data, size_t len)> FDataAppender;
/**
* @brief Optional private method implemented by CProjectObject subclasses to cook objects
* @brief Optional private method implemented by subclasses to cook objects
* @param dataAppender subclass calls this function zero or more times to provide cooked-data linearly
* @param endianness byte-order to target
* @param platform data-formats to target
@ -304,7 +340,7 @@ protected:
* Part of the cooking process may include embedding database-refs to dependencies.
* This method should store the 64-bit value provided by IDataObject::id() when doing this.
*/
virtual bool _cookObject(FDataAppender dataAppender,
virtual bool cookObject(FDataAppender dataAppender,
DataEndianness endianness, DataPlatform platform)
{(void)dataAppender;(void)endianness;(void)platform;return true;}
@ -318,9 +354,16 @@ protected:
* Dependencies registered via this method will eventually have this method called on themselves
* as well. This is a non-recursive operation, no need for subclasses to implement recursion-control.
*/
virtual void _gatherDeps(FDepAdder depAdder)
virtual void gatherDeps(FDepAdder depAdder)
{(void)depAdder;}
/**
* @brief Get a packagable FourCC representation of the object's type
* @return FourCC of the type
*/
virtual FourCC getType() const
{return FourCC("NULL");}
public:
ObjectBase(const SystemString& path)
: m_path(path) {}

View File

@ -327,7 +327,7 @@ protected:
#endif
ProjectPath() {}
bool _canonAbsPath(const SystemString& path, bool& needsMake);
inline void _makeDir() const {MakeDir(getAbsolutePath());}
inline void _makeDir() const {MakeDir(m_absPath);}
public:
/**
* @brief Construct a project subpath representation within another subpath

View File

@ -8,6 +8,18 @@ namespace Database
/* Centralized AngelScript engine */
AngelScript::asIScriptEngine* asENGINE = nullptr;
/* AngelScript Logger */
static LogVisor::LogModule Log("AngelScript");
static void MessageCallback(const AngelScript::asSMessageInfo* msg, void*)
{
LogVisor::Level lv = LogVisor::Error;
if (msg->type == AngelScript::asMSGTYPE_WARNING)
lv = LogVisor::Warning;
else if (msg->type == AngelScript::asMSGTYPE_INFORMATION)
lv = LogVisor::Info;
Log.reportSource(lv, msg->section, msg->row, msg->message);
}
static bool InitEntered = false;
void InitASEngine()
{
@ -15,6 +27,8 @@ void InitASEngine()
return;
InitEntered = true;
assert(asENGINE = AngelScript::asCreateScriptEngine(ANGELSCRIPT_VERSION));
assert(asENGINE->SetEngineProperty(AngelScript::asEP_COPY_SCRIPT_SECTIONS, false) >= 0);
assert(asENGINE->SetMessageCallback(AngelScript::asFUNCTION(MessageCallback), nullptr, AngelScript::asCALL_CDECL) >= 0);
}
}