From 840e2806b57ced7ffbad40b334bab226de574a67 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 16 Jun 2022 23:40:11 -0700 Subject: [PATCH] Scripting: Basic void type bringup --- include/mgba/script/types.h | 2 ++ src/script/engines/lua.c | 6 ++++++ src/script/types.c | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/include/mgba/script/types.h b/include/mgba/script/types.h index 471d78524..7acb0c365 100644 --- a/include/mgba/script/types.h +++ b/include/mgba/script/types.h @@ -174,6 +174,8 @@ extern const struct mScriptType mSTWeakref; extern const struct mScriptType mSTStringWrapper; extern const struct mScriptType mSTListWrapper; +extern struct mScriptValue mScriptValueNull; + struct mScriptType; struct mScriptValue { const struct mScriptType* type; diff --git a/src/script/engines/lua.c b/src/script/engines/lua.c index f5adfcdd5..24ceefec8 100644 --- a/src/script/engines/lua.c +++ b/src/script/engines/lua.c @@ -320,6 +320,9 @@ struct mScriptValue* _luaCoerce(struct mScriptEngineContextLua* luaContext, bool const void* buffer; struct mScriptValue* value = NULL; switch (lua_type(luaContext->lua, -1)) { + case LUA_TNIL: + value = &mScriptValueNull; + break; case LUA_TNUMBER: #if LUA_VERSION_NUM >= 503 if (lua_isinteger(luaContext->lua, -1)) { @@ -398,6 +401,9 @@ bool _luaWrap(struct mScriptEngineContextLua* luaContext, struct mScriptValue* v bool ok = true; struct mScriptValue* newValue; switch (value->type->base) { + case mSCRIPT_TYPE_VOID: + lua_pushnil(luaContext->lua); + break; case mSCRIPT_TYPE_SINT: if (value->type->size <= 4) { lua_pushinteger(luaContext->lua, value->value.s32); diff --git a/src/script/types.c b/src/script/types.c index 52d0425b6..ae1108ae1 100644 --- a/src/script/types.c +++ b/src/script/types.c @@ -239,6 +239,11 @@ const struct mScriptType mSTWeakref = { .hash = NULL, }; +struct mScriptValue mScriptValueNull = { + .type = &mSTVoid, + .refs = mSCRIPT_VALUE_UNREF +}; + DEFINE_VECTOR(mScriptList, struct mScriptValue) void _allocList(struct mScriptValue* val) {