Implements support for registering types and functions in AngelScript externally.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-05-02 11:53:12 +02:00
parent 9b125503ee
commit e17a8e016b
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 24 additions and 0 deletions

View File

@ -32,3 +32,14 @@ export uint8_t PkmnLib_AngelScriptResolver_LoadByteCodeFromMemory(AngelScriptRes
size_t size) { size_t size) {
Try(p->LoadByteCodeFromMemory(memory, size);) Try(p->LoadByteCodeFromMemory(memory, size);)
} }
export uint8_t PkmnLib_AngelScriptResolver_RegisterType(AngelScriptResolver* p, const char* typeName) {
Try(p->RegisterType(typeName);)
}
export uint8_t PkmnLib_AngelScriptResolver_RegisterTypeMethod(AngelScriptResolver* p, const char* typeName,
const char* decl, void*(func)(void*)) {
Try(p->RegisterTypeMethod(typeName, decl, func);)
}
export uint8_t PkmnLib_AngelScriptResolver_RegisterGlobalMethod(AngelScriptResolver* p, const char* decl,
void*(func)(void*)) {
Try(p->RegisterGlobalMethod(decl, func);)
}

View File

@ -55,6 +55,19 @@ public:
return _typeDatabase; return _typeDatabase;
} }
void RegisterType(const char* type) {
int r = _engine->RegisterObjectType(type, 0, asOBJ_REF | asOBJ_NOCOUNT);
Assert(r >= 0);
}
void RegisterTypeMethod(const char* type, const char* decl, void*(func)(void*)) {
int r = _engine->RegisterObjectMethod(type, decl, asFunctionPtr(func), asCALL_CDECL_OBJFIRST);
Assert(r >= 0);
}
void RegisterGlobalMethod(const char* decl, void*(func)(void*)) {
auto r = _engine->RegisterGlobalFunction("decl", asFunctionPtr(func), asCALL_CDECL);
Assert(r >= 0);
}
asITypeInfo* GetBaseType(const ConstString& name) { asITypeInfo* GetBaseType(const ConstString& name) {
asITypeInfo* t = nullptr; asITypeInfo* t = nullptr;
if (!_baseTypes.TryGet(name, t)) { if (!_baseTypes.TryGet(name, t)) {