Fixes narray::Length not being a property in angelscript.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2021-09-25 18:33:12 +02:00
parent 9fd88f6192
commit 1e10d25dbd
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 11 additions and 2 deletions

View File

@ -35,7 +35,7 @@ public:
Ensure(engine->RegisterObjectBehaviour("narray<T>", asBEHAVE_RELEASE, "void f()", Ensure(engine->RegisterObjectBehaviour("narray<T>", asBEHAVE_RELEASE, "void f()",
asMETHOD(NativeArray, Release), asCALL_THISCALL)); asMETHOD(NativeArray, Release), asCALL_THISCALL));
Ensure(engine->RegisterObjectMethod("narray<T>", "uint64 Length() const", asMETHOD(NativeArray, Length), Ensure(engine->RegisterObjectMethod("narray<T>", "uint64 get_Length() const property", asMETHOD(NativeArray, Length),
asCALL_THISCALL) >= 0); asCALL_THISCALL) >= 0);
Ensure(engine->RegisterObjectMethod("narray<T>", "const T@ At(uint64 index) const", asMETHOD(NativeArray, At), Ensure(engine->RegisterObjectMethod("narray<T>", "const T@ At(uint64 index) const", asMETHOD(NativeArray, At),
asCALL_THISCALL) >= 0); asCALL_THISCALL) >= 0);

View File

@ -11,14 +11,17 @@
static std::unordered_map<const char*, const char*> _scripts = std::unordered_map<const char*, const char*>{ static std::unordered_map<const char*, const char*> _scripts = std::unordered_map<const char*, const char*>{
AS_CLASS(blankScript, ), AS_CLASS(blankScript, ),
AS_CLASS(initializeScript, R"( AS_CLASS(initializeScript, R"(
uint64 length = 0;
bool boolValue = false; bool boolValue = false;
int64 intValue = 0; int64 intValue = 0;
constString stringValue; constString stringValue;
void OnInitialize(const narray<EffectParameter@>@ parameters) override { void OnInitialize(const narray<EffectParameter@>@ parameters) override {
length = parameters.Length;
boolValue = parameters[0].AsBool(); boolValue = parameters[0].AsBool();
intValue = parameters[1].AsInt(); intValue = parameters[1].AsInt();
stringValue = parameters[2].AsString(); stringValue = parameters[2].AsString();
} }
uint64 GetLength() { return length; }
bool GetBoolValue() { return boolValue; } bool GetBoolValue() { return boolValue; }
int64 GetIntValue() { return intValue; } int64 GetIntValue() { return intValue; }
constString GetStringValue() { return stringValue; } constString GetStringValue() { return stringValue; }
@ -138,8 +141,14 @@ TEST_CASE("Invoke OnInitialize script function") {
script->OnInitialize(parameters); script->OnInitialize(parameters);
auto ctxPool = script->GetContextPool(); auto ctxPool = script->GetContextPool();
auto ctx = ctxPool->RequestContext();
auto ctx = ctxPool->RequestContext();
script->PrepareMethod("GetLength"_cnc, ctx);
REQUIRE(ctx->Execute() == asEXECUTION_FINISHED);
REQUIRE_EQ((uint64_t)ctx->GetReturnQWord(), 3);
ctxPool->ReturnContextToPool(ctx);
ctx = ctxPool->RequestContext();
script->PrepareMethod("GetBoolValue"_cnc, ctx); script->PrepareMethod("GetBoolValue"_cnc, ctx);
REQUIRE(ctx->Execute() == asEXECUTION_FINISHED); REQUIRE(ctx->Execute() == asEXECUTION_FINISHED);
REQUIRE((bool)ctx->GetReturnDWord()); REQUIRE((bool)ctx->GetReturnDWord());