mirror of https://github.com/mgba-emu/mgba.git
Scripting: Fix passing mSTList/Table from Lua back into the runtime
This commit is contained in:
parent
282a033df2
commit
045a2c96dc
|
@ -84,14 +84,6 @@ void mScriptContextFillPool(struct mScriptContext* context, struct mScriptValue*
|
|||
if (value->refs == mSCRIPT_VALUE_UNREF) {
|
||||
return;
|
||||
}
|
||||
switch (value->type->base) {
|
||||
case mSCRIPT_TYPE_SINT:
|
||||
case mSCRIPT_TYPE_UINT:
|
||||
case mSCRIPT_TYPE_FLOAT:
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
struct mScriptValue* poolEntry = mScriptListAppend(&context->refPool);
|
||||
poolEntry->type = mSCRIPT_TYPE_MS_WRAPPER;
|
||||
|
|
|
@ -679,8 +679,16 @@ struct mScriptValue* _luaCoerce(struct mScriptEngineContextLua* luaContext, bool
|
|||
}
|
||||
luaL_getmetatable(luaContext->lua, "mSTStruct");
|
||||
if (!lua_rawequal(luaContext->lua, -1, -2)) {
|
||||
lua_pop(luaContext->lua, 2);
|
||||
break;
|
||||
lua_pop(luaContext->lua, 1);
|
||||
luaL_getmetatable(luaContext->lua, "mSTList");
|
||||
if (!lua_rawequal(luaContext->lua, -1, -2)) {
|
||||
lua_pop(luaContext->lua, 1);
|
||||
luaL_getmetatable(luaContext->lua, "mSTTable");
|
||||
if (!lua_rawequal(luaContext->lua, -1, -2)) {
|
||||
lua_pop(luaContext->lua, 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
lua_pop(luaContext->lua, 2);
|
||||
value = lua_touserdata(luaContext->lua, -1);
|
||||
|
|
|
@ -811,6 +811,48 @@ M_TEST_DEFINE(linkedList) {
|
|||
mScriptContextDeinit(&context);
|
||||
}
|
||||
|
||||
M_TEST_DEFINE(listConvert) {
|
||||
SETUP_LUA;
|
||||
|
||||
struct mScriptValue* list = mScriptValueAlloc(mSCRIPT_TYPE_MS_LIST);
|
||||
|
||||
assert_true(lua->setGlobal(lua, "l", list));
|
||||
TEST_PROGRAM("assert(l)");
|
||||
|
||||
struct mScriptValue* val = lua->getGlobal(lua, "l");
|
||||
assert_non_null(val);
|
||||
if (val->type->base == mSCRIPT_TYPE_WRAPPER) {
|
||||
val = mScriptValueUnwrap(val);
|
||||
}
|
||||
assert_ptr_equal(val->type, mSCRIPT_TYPE_MS_LIST);
|
||||
assert_ptr_equal(val->value.list, list->value.list);
|
||||
mScriptValueDeref(val);
|
||||
mScriptValueDeref(list);
|
||||
|
||||
mScriptContextDeinit(&context);
|
||||
}
|
||||
|
||||
M_TEST_DEFINE(tableConvert) {
|
||||
SETUP_LUA;
|
||||
|
||||
struct mScriptValue* list = mScriptValueAlloc(mSCRIPT_TYPE_MS_TABLE);
|
||||
|
||||
assert_true(lua->setGlobal(lua, "l", list));
|
||||
TEST_PROGRAM("assert(l)");
|
||||
|
||||
struct mScriptValue* val = lua->getGlobal(lua, "l");
|
||||
assert_non_null(val);
|
||||
if (val->type->base == mSCRIPT_TYPE_WRAPPER) {
|
||||
val = mScriptValueUnwrap(val);
|
||||
}
|
||||
assert_ptr_equal(val->type, mSCRIPT_TYPE_MS_TABLE);
|
||||
assert_ptr_equal(val->value.table, list->value.table);
|
||||
mScriptValueDeref(val);
|
||||
mScriptValueDeref(list);
|
||||
|
||||
mScriptContextDeinit(&context);
|
||||
}
|
||||
|
||||
M_TEST_SUITE_DEFINE_SETUP_TEARDOWN(mScriptLua,
|
||||
cmocka_unit_test(create),
|
||||
cmocka_unit_test(loadGood),
|
||||
|
@ -831,4 +873,6 @@ M_TEST_SUITE_DEFINE_SETUP_TEARDOWN(mScriptLua,
|
|||
cmocka_unit_test(tableIterate),
|
||||
cmocka_unit_test(callList),
|
||||
cmocka_unit_test(linkedList),
|
||||
cmocka_unit_test(listConvert),
|
||||
cmocka_unit_test(tableConvert),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue