Scripting: Allow null values to be wrapped in Lua as nil

This commit is contained in:
Vicki Pfau 2022-05-16 16:39:44 -07:00
parent 304a8d1655
commit 93cadacb18
1 changed files with 12 additions and 0 deletions

View File

@ -241,14 +241,26 @@ struct mScriptValue* _luaCoerce(struct mScriptEngineContextLua* luaContext) {
}
bool _luaWrap(struct mScriptEngineContextLua* luaContext, struct mScriptValue* value) {
if (!value) {
lua_pushnil(luaContext->lua);
return true;
}
uint32_t weakref;
bool needsWeakref = false;
if (value->type == mSCRIPT_TYPE_MS_WRAPPER) {
value = mScriptValueUnwrap(value);
if (!value) {
lua_pushnil(luaContext->lua);
return true;
}
}
if (value->type == mSCRIPT_TYPE_MS_WEAKREF) {
weakref = value->value.u32;
value = mScriptContextAccessWeakref(luaContext->d.context, value);
if (!value) {
lua_pushnil(luaContext->lua);
return true;
}
needsWeakref = true;
}
bool ok = true;