webmcp
changeset 374:11ef7ab67e43
Added mutability state handlers in mondelefant_atom_connector.lua and prepare its usage in mondelefant_native.c
author | jbe |
---|---|
date | Sat Nov 14 14:15:31 2015 +0100 (2015-11-14) |
parents | 7674d59521f8 |
children | fb98b17056e5 |
files | libraries/mondelefant/mondelefant_atom_connector.lua libraries/mondelefant/mondelefant_native.c |
line diff
1.1 --- a/libraries/mondelefant/mondelefant_atom_connector.lua Sat Nov 14 02:11:44 2015 +0100 1.2 +++ b/libraries/mondelefant/mondelefant_atom_connector.lua Sat Nov 14 14:15:31 2015 +0100 1.3 @@ -179,6 +179,22 @@ 1.4 end 1.5 end 1.6 1.7 + 1.8 +function mondelefant.save_mutability_state(value) 1.9 + local jsontype = json.type(value) 1.10 + if jsontype == "object" or jsontype == "array" then 1.11 + return tostring(value) 1.12 + end 1.13 +end 1.14 + 1.15 +function mondelefant.verify_mutability_state(value, state) 1.16 + if state and tostring(value) ~= state then 1.17 + return true 1.18 + else 1.19 + return false 1.20 + end 1.21 +end 1.22 + 1.23 return _M 1.24 1.25
2.1 --- a/libraries/mondelefant/mondelefant_native.c Sat Nov 14 02:11:44 2015 +0100 2.2 +++ b/libraries/mondelefant/mondelefant_native.c Sat Nov 14 14:15:31 2015 +0100 2.3 @@ -1140,68 +1140,70 @@ 2.4 lua_replace(L, 3); 2.5 // get output converter to stack position 4: 2.6 lua_getfield(L, 1, "output_converter"); 2.7 + // get mutability state saver to stack position 5: 2.8 + lua_getfield(L, 1, "save_mutability_state"); 2.9 // apply output converters and fill "_data" table according to column names: 2.10 for (command_idx = 0; command_idx < command_count; command_idx++) { 2.11 int mode; 2.12 mode = modes[command_idx]; 2.13 - lua_rawgeti(L, 3, command_idx+1); // raw result at stack position 5 2.14 - if (lua_toboolean(L, 5)) { 2.15 - lua_getfield(L, 5, "_column_info"); // column_info list at position 6 2.16 + lua_rawgeti(L, 3, command_idx+1); // raw result at stack position 6 2.17 + if (lua_toboolean(L, 6)) { 2.18 + lua_getfield(L, 6, "_column_info"); // column_info list at position 7 2.19 #if LUA_VERSION_NUM >= 502 2.20 - cols = lua_rawlen(L, 6); 2.21 + cols = lua_rawlen(L, 7); 2.22 #else 2.23 - cols = lua_objlen(L, 6); 2.24 + cols = lua_objlen(L, 7); 2.25 #endif 2.26 if (mode == MONDELEFANT_QUERY_MODE_LIST) { 2.27 #if LUA_VERSION_NUM >= 502 2.28 - rows = lua_rawlen(L, 5); 2.29 + rows = lua_rawlen(L, 6); 2.30 #else 2.31 - rows = lua_objlen(L, 5); 2.32 + rows = lua_objlen(L, 6); 2.33 #endif 2.34 for (row = 0; row < rows; row++) { 2.35 - lua_rawgeti(L, 5, row+1); // row at stack position 7 2.36 - lua_getfield(L, 7, "_data"); // _data table at stack position 8 2.37 + lua_rawgeti(L, 6, row+1); // row at stack position 8 2.38 + lua_getfield(L, 8, "_data"); // _data table at stack position 9 2.39 for (col = 0; col < cols; col++) { 2.40 - lua_rawgeti(L, 6, col+1); // this column info at position 9 2.41 - lua_getfield(L, 9, "field_name"); // 10 2.42 + lua_rawgeti(L, 7, col+1); // this column info at position 10 2.43 + lua_getfield(L, 10, "field_name"); // 11 2.44 if (lua_toboolean(L, 4)) { 2.45 lua_pushvalue(L, 4); // output-converter 2.46 lua_pushvalue(L, 1); // connection 2.47 - lua_rawgeti(L, 7, col+1); // raw-value 2.48 - lua_pushvalue(L, 9); // this column info 2.49 - lua_call(L, 3, 1); // converted value at position 11 2.50 + lua_rawgeti(L, 8, col+1); // raw-value 2.51 + lua_pushvalue(L, 10); // this column info 2.52 + lua_call(L, 3, 1); // converted value at position 12 2.53 } else { 2.54 - lua_rawgeti(L, 7, col+1); // raw-value at position 11 2.55 + lua_rawgeti(L, 8, col+1); // raw-value at position 12 2.56 } 2.57 - lua_pushvalue(L, 11); // 12 2.58 - lua_rawseti(L, 7, col+1); 2.59 - lua_rawset(L, 8); 2.60 - lua_settop(L, 8); 2.61 + lua_pushvalue(L, 12); // 13 2.62 + lua_rawseti(L, 8, col+1); 2.63 + lua_rawset(L, 9); 2.64 + lua_settop(L, 9); 2.65 } 2.66 - lua_settop(L, 6); 2.67 + lua_settop(L, 7); 2.68 } 2.69 } else { 2.70 - lua_getfield(L, 5, "_data"); // _data table at stack position 7 2.71 + lua_getfield(L, 6, "_data"); // _data table at stack position 8 2.72 for (col = 0; col < cols; col++) { 2.73 - lua_rawgeti(L, 6, col+1); // this column info at position 8 2.74 - lua_getfield(L, 8, "field_name"); // 9 2.75 + lua_rawgeti(L, 7, col+1); // this column info at position 9 2.76 + lua_getfield(L, 9, "field_name"); // 10 2.77 if (lua_toboolean(L, 4)) { 2.78 lua_pushvalue(L, 4); // output-converter 2.79 lua_pushvalue(L, 1); // connection 2.80 - lua_rawgeti(L, 5, col+1); // raw-value 2.81 - lua_pushvalue(L, 8); // this column info 2.82 - lua_call(L, 3, 1); // converted value at position 10 2.83 + lua_rawgeti(L, 6, col+1); // raw-value 2.84 + lua_pushvalue(L, 9); // this column info 2.85 + lua_call(L, 3, 1); // converted value at position 11 2.86 } else { 2.87 - lua_rawgeti(L, 5, col+1); // raw-value at position 10 2.88 + lua_rawgeti(L, 6, col+1); // raw-value at position 11 2.89 } 2.90 - lua_pushvalue(L, 10); // 11 2.91 - lua_rawseti(L, 5, col+1); 2.92 - lua_rawset(L, 7); 2.93 - lua_settop(L, 7); 2.94 + lua_pushvalue(L, 11); // 12 2.95 + lua_rawseti(L, 6, col+1); 2.96 + lua_rawset(L, 8); 2.97 + lua_settop(L, 8); 2.98 } 2.99 } 2.100 } 2.101 - lua_settop(L, 4); 2.102 + lua_settop(L, 5); 2.103 } 2.104 // return nil as first result value, followed by result lists/objects: 2.105 lua_settop(L, 3);