From a2b0230c719266806435c54504f83ed7c0534d5c Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 29 Aug 2021 18:31:50 -0700 Subject: [PATCH] Scripting: Add some helper macros --- include/mgba/script/types.h | 12 ++++++++++++ src/script/test/types.c | 17 ++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/include/mgba/script/types.h b/include/mgba/script/types.h index 39af96ddb..948a50d8f 100644 --- a/include/mgba/script/types.h +++ b/include/mgba/script/types.h @@ -155,6 +155,18 @@ CXX_GUARD_START .call = _binding_ ## NAME \ }; +#define mSCRIPT_MAKE(TYPE, FIELD, VALUE) (struct mScriptValue) { \ + .type = (TYPE), \ + .refs = mSCRIPT_VALUE_UNREF, \ + .value = { \ + .FIELD = (VALUE) \ + }, \ + } \ + +#define mSCRIPT_MAKE_S32(VALUE) mSCRIPT_MAKE(mSCRIPT_TYPE_MS_S32, s32, VALUE) +#define mSCRIPT_MAKE_U32(VALUE) mSCRIPT_MAKE(mSCRIPT_TYPE_MS_U32, u32, VALUE) +#define mSCRIPT_MAKE_F32(VALUE) mSCRIPT_MAKE(mSCRIPT_TYPE_MS_F32, f32, VALUE) + enum { mSCRIPT_TYPE_VOID = 0, mSCRIPT_TYPE_SINT, diff --git a/src/script/test/types.c b/src/script/test/types.c index 7ccd24091..efd3701aa 100644 --- a/src/script/test/types.c +++ b/src/script/test/types.c @@ -180,21 +180,8 @@ M_TEST_DEFINE(hashTableBasic) { assert_int_equal(intValue->value.s32, 0); assert_int_equal(intValue->refs, 1); - struct mScriptValue intKey = { - .type = mSCRIPT_TYPE_MS_S32, - .value = { - .s32 = 1234 - }, - .refs = mSCRIPT_VALUE_UNREF - }; - - struct mScriptValue badKey = { - .type = mSCRIPT_TYPE_MS_S32, - .value = { - .s32 = 1235 - }, - .refs = mSCRIPT_VALUE_UNREF - }; + struct mScriptValue intKey = mSCRIPT_MAKE_S32(1234); + struct mScriptValue badKey = mSCRIPT_MAKE_S32(1235); assert_true(mScriptTableInsert(table, &intKey, intValue)); assert_int_equal(intValue->refs, 2);