# HG changeset patch # User jbe # Date 1571507145 -7200 # Node ID a93ba2a3858a1c89304e62c465b72f7159d8e774 # Parent a886e263b534cae593cf37e5a060896c413e777b Fix handling when setting 1:1 referenced objects diff -r a886e263b534 -r a93ba2a3858a libraries/mondelefant/mondelefant_native.c --- a/libraries/mondelefant/mondelefant_native.c Sat Oct 19 18:55:24 2019 +0200 +++ b/libraries/mondelefant/mondelefant_native.c Sat Oct 19 19:45:45 2019 +0200 @@ -1781,6 +1781,21 @@ lua_pushvalue(L, 2); // 8 lua_call(L, 2, 1); // 6 if (!lua_isnil(L, 6)) { + // special handling of 1:1 references (primary side): + lua_getfield(L, 6, "mode"); // 7 + if (!strcmp(lua_tostring(L, 7) || "", "11")) { + lua_getfield(L, 6, "primary"); // 8 + if (lua_toboolean(L, 8)) { + if (!lua_isnil(L, 3)) { + // set backward reference: + lua_getfield(L, 6, "backref"); // 9 + lua_pushvalue(L, 1); // 10 + lua_settable(L, 3); + } + // do nothing else: + return 0; + } + } // store object in _ref table (use false for nil): // TODO: use special object instead of false lua_getfield(L, 1, "_ref"); // 7 lua_pushvalue(L, 2); // 8 @@ -1788,6 +1803,19 @@ else lua_pushvalue(L, 3); // 9 lua_settable(L, 7); lua_settop(L, 6); + // special handling of 1:1 references (secondary side): + lua_getfield(L, 6, "mode"); // 7 + if (!strcmp(lua_tostring(L, 7) || "", "11")) { + lua_settop(L, 6); + if (!lua_isnil(L, 3)) { + // store object in other _ref table (use false for nil): // TODO: use special object instead of false + lua_getfield(L, 3, "_ref"); // 7 + lua_getfield(L, 6, "backref"); // 8 + lua_pushvalue(L, 1); // 9 + lua_settable(L, 7); + } + } + lua_settop(L, 6); // delete referencing key from _data table: lua_getfield(L, 6, "this_key"); // 7 if (lua_isnil(L, 7)) {