mirror of https://github.com/mgba-emu/mgba.git
Scripting: Lua nullity fixes
This commit is contained in:
parent
dfd772d2ca
commit
17ef84804b
|
@ -738,7 +738,19 @@ bool _luaWrap(struct mScriptEngineContextLua* luaContext, struct mScriptValue* v
|
|||
}
|
||||
break;
|
||||
case mSCRIPT_TYPE_STRING:
|
||||
lua_pushlstring(luaContext->lua, value->value.string->buffer, value->value.string->size);
|
||||
if (!value->value.string) {
|
||||
lua_pushnil(luaContext->lua);
|
||||
break;
|
||||
}
|
||||
if (value->type == mSCRIPT_TYPE_MS_STR) {
|
||||
lua_pushlstring(luaContext->lua, value->value.string->buffer, value->value.string->size);
|
||||
break;
|
||||
}
|
||||
if (value->type == mSCRIPT_TYPE_MS_CHARP) {
|
||||
lua_pushstring(luaContext->lua, value->value.copaque);
|
||||
break;
|
||||
}
|
||||
ok = false;
|
||||
break;
|
||||
case mSCRIPT_TYPE_LIST:
|
||||
newValue = lua_newuserdata(luaContext->lua, sizeof(*newValue));
|
||||
|
@ -769,6 +781,10 @@ bool _luaWrap(struct mScriptEngineContextLua* luaContext, struct mScriptValue* v
|
|||
mScriptValueDeref(value);
|
||||
break;
|
||||
case mSCRIPT_TYPE_OBJECT:
|
||||
if (!value->value.opaque) {
|
||||
lua_pushnil(luaContext->lua);
|
||||
break;
|
||||
}
|
||||
newValue = lua_newuserdata(luaContext->lua, sizeof(*newValue));
|
||||
if (needsWeakref) {
|
||||
*newValue = mSCRIPT_MAKE(WEAKREF, weakref);
|
||||
|
|
|
@ -371,15 +371,23 @@ M_TEST_DEFINE(callCFunc) {
|
|||
|
||||
mScriptContextDeinit(&context);
|
||||
}
|
||||
M_TEST_DEFINE(globalStructNull) {
|
||||
M_TEST_DEFINE(globalNull) {
|
||||
SETUP_LUA;
|
||||
|
||||
struct Test s = {};
|
||||
|
||||
struct mScriptValue* val;
|
||||
struct mScriptValue a;
|
||||
|
||||
LOAD_PROGRAM("assert(a)");
|
||||
|
||||
a = mSCRIPT_MAKE_CHARP("hello");
|
||||
assert_true(lua->setGlobal(lua, "a", &a));
|
||||
assert_true(lua->run(lua));
|
||||
|
||||
a = mSCRIPT_MAKE_CHARP(NULL);
|
||||
assert_true(lua->setGlobal(lua, "a", &a));
|
||||
assert_false(lua->run(lua));
|
||||
|
||||
a = mSCRIPT_MAKE_S(Test, &s);
|
||||
assert_true(lua->setGlobal(lua, "a", &a));
|
||||
assert_true(lua->run(lua));
|
||||
|
@ -728,7 +736,7 @@ M_TEST_SUITE_DEFINE_SETUP_TEARDOWN(mScriptLua,
|
|||
cmocka_unit_test(rootScope),
|
||||
cmocka_unit_test(callLuaFunc),
|
||||
cmocka_unit_test(callCFunc),
|
||||
cmocka_unit_test(globalStructNull),
|
||||
cmocka_unit_test(globalNull),
|
||||
cmocka_unit_test(globalStructFieldGet),
|
||||
cmocka_unit_test(globalStructFieldSet),
|
||||
cmocka_unit_test(globalStructMethods),
|
||||
|
|
Loading…
Reference in New Issue