webmcp

diff libraries/mondelefant/mondelefant_native.c @ 375:fb98b17056e5

Proper support for mutable data types (JSON objects/arrays) in table columns
author jbe
date Sat Nov 14 15:44:53 2015 +0100 (2015-11-14)
parents 11ef7ab67e43
children 4bcedf32b089
line diff
     1.1 --- a/libraries/mondelefant/mondelefant_native.c	Sat Nov 14 14:15:31 2015 +0100
     1.2 +++ b/libraries/mondelefant/mondelefant_native.c	Sat Nov 14 15:44:53 2015 +0100
     1.3 @@ -1141,7 +1141,9 @@
     1.4    // get output converter to stack position 4:
     1.5    lua_getfield(L, 1, "output_converter");
     1.6    // get mutability state saver to stack position 5:
     1.7 -  lua_getfield(L, 1, "save_mutability_state");
     1.8 +  lua_getfield(L, LUA_REGISTRYINDEX, MONDELEFANT_MODULE_REGKEY);
     1.9 +  lua_getfield(L, -1, "save_mutability_state");
    1.10 +  lua_replace(L, -2);
    1.11    // apply output converters and fill "_data" table according to column names:
    1.12    for (command_idx = 0; command_idx < command_count; command_idx++) {
    1.13      int mode;
    1.14 @@ -1163,19 +1165,27 @@
    1.15          for (row = 0; row < rows; row++) {
    1.16            lua_rawgeti(L, 6, row+1);  // row at stack position 8
    1.17            lua_getfield(L, 8, "_data");  // _data table at stack position 9
    1.18 +          lua_getfield(L, 8, "_dirty");  // _dirty table at stack position 10
    1.19            for (col = 0; col < cols; col++) {
    1.20 -            lua_rawgeti(L, 7, col+1);  // this column info at position 10
    1.21 -            lua_getfield(L, 10, "field_name");  // 11
    1.22 +            lua_rawgeti(L, 7, col+1);  // this column info at position 11
    1.23 +            lua_getfield(L, 11, "field_name");  // 12
    1.24              if (lua_toboolean(L, 4)) {
    1.25                lua_pushvalue(L, 4);  // output-converter
    1.26                lua_pushvalue(L, 1);  // connection
    1.27                lua_rawgeti(L, 8, col+1);  // raw-value
    1.28 -              lua_pushvalue(L, 10);  // this column info
    1.29 -              lua_call(L, 3, 1);  // converted value at position 12
    1.30 +              lua_pushvalue(L, 11);  // this column info
    1.31 +              lua_call(L, 3, 1);  // converted value at position 13
    1.32              } else {
    1.33 -              lua_rawgeti(L, 8, col+1);  // raw-value at position 12
    1.34 +              lua_rawgeti(L, 8, col+1);  // raw-value at position 13
    1.35              }
    1.36 -            lua_pushvalue(L, 12);  // 13
    1.37 +            if (lua_toboolean(L, 5)) {  // handle mutable values?
    1.38 +              lua_pushvalue(L, 12);  // copy of field name
    1.39 +              lua_pushvalue(L, 5);  // mutability state saver function
    1.40 +              lua_pushvalue(L, 13);  // copy of value
    1.41 +              lua_call(L, 1, 1);  // calculated mutability state of value
    1.42 +              lua_rawset(L, 10);  // store mutability state in _dirty table
    1.43 +            }
    1.44 +            lua_pushvalue(L, 13);  // 14
    1.45              lua_rawseti(L, 8, col+1);
    1.46              lua_rawset(L, 9);
    1.47              lua_settop(L, 9);
    1.48 @@ -1184,19 +1194,27 @@
    1.49          }
    1.50        } else {
    1.51          lua_getfield(L, 6, "_data");  // _data table at stack position 8
    1.52 +        lua_getfield(L, 6, "_dirty");  // _dirty table at stack position 9
    1.53          for (col = 0; col < cols; col++) {
    1.54 -          lua_rawgeti(L, 7, col+1);  // this column info at position 9
    1.55 -          lua_getfield(L, 9, "field_name");  // 10
    1.56 +          lua_rawgeti(L, 7, col+1);  // this column info at position 10
    1.57 +          lua_getfield(L, 10, "field_name");  // 11
    1.58            if (lua_toboolean(L, 4)) {
    1.59              lua_pushvalue(L, 4);  // output-converter
    1.60              lua_pushvalue(L, 1);  // connection
    1.61              lua_rawgeti(L, 6, col+1);  // raw-value
    1.62 -            lua_pushvalue(L, 9);  // this column info
    1.63 -            lua_call(L, 3, 1);  // converted value at position 11
    1.64 +            lua_pushvalue(L, 10);  // this column info
    1.65 +            lua_call(L, 3, 1);  // converted value at position 12
    1.66            } else {
    1.67 -            lua_rawgeti(L, 6, col+1);  // raw-value at position 11
    1.68 +            lua_rawgeti(L, 6, col+1);  // raw-value at position 12
    1.69            }
    1.70 -          lua_pushvalue(L, 11);  // 12
    1.71 +          if (lua_toboolean(L, 5)) {  // handle mutable values?
    1.72 +            lua_pushvalue(L, 11);  // copy of field name
    1.73 +            lua_pushvalue(L, 5);  // mutability state saver function
    1.74 +            lua_pushvalue(L, 12);  // copy of value
    1.75 +            lua_call(L, 1, 1);  // calculated mutability state of value
    1.76 +            lua_rawset(L, 9);  // store mutability state in _dirty table
    1.77 +          }
    1.78 +          lua_pushvalue(L, 12);  // 13
    1.79            lua_rawseti(L, 6, col+1);
    1.80            lua_rawset(L, 8);
    1.81            lua_settop(L, 8);

Impressum / About Us