# HG changeset patch # User jbe # Date 1447506931 -3600 # Node ID 11ef7ab67e43bed1758c2f403a5ce9e378926f68 # Parent 7674d59521f8a93e334964702e7cd5ced16cbd97 Added mutability state handlers in mondelefant_atom_connector.lua and prepare its usage in mondelefant_native.c diff -r 7674d59521f8 -r 11ef7ab67e43 libraries/mondelefant/mondelefant_atom_connector.lua --- a/libraries/mondelefant/mondelefant_atom_connector.lua Sat Nov 14 02:11:44 2015 +0100 +++ b/libraries/mondelefant/mondelefant_atom_connector.lua Sat Nov 14 14:15:31 2015 +0100 @@ -179,6 +179,22 @@ end end + +function mondelefant.save_mutability_state(value) + local jsontype = json.type(value) + if jsontype == "object" or jsontype == "array" then + return tostring(value) + end +end + +function mondelefant.verify_mutability_state(value, state) + if state and tostring(value) ~= state then + return true + else + return false + end +end + return _M diff -r 7674d59521f8 -r 11ef7ab67e43 libraries/mondelefant/mondelefant_native.c --- a/libraries/mondelefant/mondelefant_native.c Sat Nov 14 02:11:44 2015 +0100 +++ b/libraries/mondelefant/mondelefant_native.c Sat Nov 14 14:15:31 2015 +0100 @@ -1140,68 +1140,70 @@ lua_replace(L, 3); // get output converter to stack position 4: lua_getfield(L, 1, "output_converter"); + // get mutability state saver to stack position 5: + lua_getfield(L, 1, "save_mutability_state"); // apply output converters and fill "_data" table according to column names: for (command_idx = 0; command_idx < command_count; command_idx++) { int mode; mode = modes[command_idx]; - lua_rawgeti(L, 3, command_idx+1); // raw result at stack position 5 - if (lua_toboolean(L, 5)) { - lua_getfield(L, 5, "_column_info"); // column_info list at position 6 + lua_rawgeti(L, 3, command_idx+1); // raw result at stack position 6 + if (lua_toboolean(L, 6)) { + lua_getfield(L, 6, "_column_info"); // column_info list at position 7 #if LUA_VERSION_NUM >= 502 - cols = lua_rawlen(L, 6); + cols = lua_rawlen(L, 7); #else - cols = lua_objlen(L, 6); + cols = lua_objlen(L, 7); #endif if (mode == MONDELEFANT_QUERY_MODE_LIST) { #if LUA_VERSION_NUM >= 502 - rows = lua_rawlen(L, 5); + rows = lua_rawlen(L, 6); #else - rows = lua_objlen(L, 5); + rows = lua_objlen(L, 6); #endif for (row = 0; row < rows; row++) { - lua_rawgeti(L, 5, row+1); // row at stack position 7 - lua_getfield(L, 7, "_data"); // _data table at stack position 8 + lua_rawgeti(L, 6, row+1); // row at stack position 8 + lua_getfield(L, 8, "_data"); // _data table at stack position 9 for (col = 0; col < cols; col++) { - lua_rawgeti(L, 6, col+1); // this column info at position 9 - lua_getfield(L, 9, "field_name"); // 10 + lua_rawgeti(L, 7, col+1); // this column info at position 10 + lua_getfield(L, 10, "field_name"); // 11 if (lua_toboolean(L, 4)) { lua_pushvalue(L, 4); // output-converter lua_pushvalue(L, 1); // connection - lua_rawgeti(L, 7, col+1); // raw-value - lua_pushvalue(L, 9); // this column info - lua_call(L, 3, 1); // converted value at position 11 + lua_rawgeti(L, 8, col+1); // raw-value + lua_pushvalue(L, 10); // this column info + lua_call(L, 3, 1); // converted value at position 12 } else { - lua_rawgeti(L, 7, col+1); // raw-value at position 11 + lua_rawgeti(L, 8, col+1); // raw-value at position 12 } - lua_pushvalue(L, 11); // 12 - lua_rawseti(L, 7, col+1); - lua_rawset(L, 8); - lua_settop(L, 8); + lua_pushvalue(L, 12); // 13 + lua_rawseti(L, 8, col+1); + lua_rawset(L, 9); + lua_settop(L, 9); } - lua_settop(L, 6); + lua_settop(L, 7); } } else { - lua_getfield(L, 5, "_data"); // _data table at stack position 7 + lua_getfield(L, 6, "_data"); // _data table at stack position 8 for (col = 0; col < cols; col++) { - lua_rawgeti(L, 6, col+1); // this column info at position 8 - lua_getfield(L, 8, "field_name"); // 9 + lua_rawgeti(L, 7, col+1); // this column info at position 9 + lua_getfield(L, 9, "field_name"); // 10 if (lua_toboolean(L, 4)) { lua_pushvalue(L, 4); // output-converter lua_pushvalue(L, 1); // connection - lua_rawgeti(L, 5, col+1); // raw-value - lua_pushvalue(L, 8); // this column info - lua_call(L, 3, 1); // converted value at position 10 + lua_rawgeti(L, 6, col+1); // raw-value + lua_pushvalue(L, 9); // this column info + lua_call(L, 3, 1); // converted value at position 11 } else { - lua_rawgeti(L, 5, col+1); // raw-value at position 10 + lua_rawgeti(L, 6, col+1); // raw-value at position 11 } - lua_pushvalue(L, 10); // 11 - lua_rawseti(L, 5, col+1); - lua_rawset(L, 7); - lua_settop(L, 7); + lua_pushvalue(L, 11); // 12 + lua_rawseti(L, 6, col+1); + lua_rawset(L, 8); + lua_settop(L, 8); } } } - lua_settop(L, 4); + lua_settop(L, 5); } // return nil as first result value, followed by result lists/objects: lua_settop(L, 3);