webmcp

changeset 544:a93ba2a3858a

Fix handling when setting 1:1 referenced objects
author jbe
date Sat Oct 19 19:45:45 2019 +0200 (2019-10-19)
parents a886e263b534
children 80c16991a770
files libraries/mondelefant/mondelefant_native.c
line diff
     1.1 --- a/libraries/mondelefant/mondelefant_native.c	Sat Oct 19 18:55:24 2019 +0200
     1.2 +++ b/libraries/mondelefant/mondelefant_native.c	Sat Oct 19 19:45:45 2019 +0200
     1.3 @@ -1781,6 +1781,21 @@
     1.4      lua_pushvalue(L, 2);  // 8
     1.5      lua_call(L, 2, 1);  // 6
     1.6      if (!lua_isnil(L, 6)) {
     1.7 +      // special handling of 1:1 references (primary side):
     1.8 +      lua_getfield(L, 6, "mode");  // 7
     1.9 +      if (!strcmp(lua_tostring(L, 7) || "", "11")) {
    1.10 +        lua_getfield(L, 6, "primary");  // 8
    1.11 +        if (lua_toboolean(L, 8)) {
    1.12 +          if (!lua_isnil(L, 3)) {
    1.13 +            // set backward reference:
    1.14 +            lua_getfield(L, 6, "backref");  // 9
    1.15 +            lua_pushvalue(L, 1);  // 10
    1.16 +            lua_settable(L, 3);
    1.17 +          }
    1.18 +          // do nothing else:
    1.19 +          return 0;
    1.20 +        }
    1.21 +      }
    1.22        // store object in _ref table (use false for nil):  // TODO: use special object instead of false
    1.23        lua_getfield(L, 1, "_ref");  // 7
    1.24        lua_pushvalue(L, 2);  // 8
    1.25 @@ -1788,6 +1803,19 @@
    1.26        else lua_pushvalue(L, 3);  // 9
    1.27        lua_settable(L, 7);
    1.28        lua_settop(L, 6);
    1.29 +      // special handling of 1:1 references (secondary side):
    1.30 +      lua_getfield(L, 6, "mode");  // 7
    1.31 +      if (!strcmp(lua_tostring(L, 7) || "", "11")) {
    1.32 +        lua_settop(L, 6);
    1.33 +        if (!lua_isnil(L, 3)) {
    1.34 +          // store object in other _ref table (use false for nil):  // TODO: use special object instead of false
    1.35 +          lua_getfield(L, 3, "_ref");  // 7
    1.36 +          lua_getfield(L, 6, "backref");  // 8
    1.37 +          lua_pushvalue(L, 1);  // 9
    1.38 +          lua_settable(L, 7);
    1.39 +        }
    1.40 +      }
    1.41 +      lua_settop(L, 6);
    1.42        // delete referencing key from _data table:
    1.43        lua_getfield(L, 6, "this_key");  // 7
    1.44        if (lua_isnil(L, 7)) {

Impressum / About Us