webmcp

changeset 382:810c020b0da4

Reverted changes to mondelefant_result_index and mondelefant_result_newindex C-functions (proxying of JSON document)
author jbe
date Mon Nov 16 18:31:49 2015 +0100 (2015-11-16)
parents 46ff54bbd10e
children f0ac171edf62
files libraries/mondelefant/mondelefant_native.c
line diff
     1.1 --- a/libraries/mondelefant/mondelefant_native.c	Mon Nov 16 16:55:49 2015 +0100
     1.2 +++ b/libraries/mondelefant/mondelefant_native.c	Mon Nov 16 18:31:49 2015 +0100
     1.3 @@ -1494,87 +1494,80 @@
     1.4    // different lookup for lists and objects:
     1.5    if (result_type && !strcmp(result_type, "object")) {  // object
     1.6      lua_settop(L, 3);
     1.7 -    lua_pushnil(L);
     1.8 -    lua_insert(L, 3);  // optional document column name on stack position 3
     1.9 -    // try inherited attributes, methods or getter functions
    1.10 -    // (and determine optional document column, if existent):
    1.11 -    while (lua_toboolean(L, 4)) {  // class on stack position 4 (due to insert)
    1.12 -      lua_getfield(L, 4, "object");  // 5
    1.13 -      lua_pushvalue(L, 2);  // 6
    1.14 -      lua_gettable(L, 5);  // 6
    1.15 -      if (!lua_isnil(L, 6)) return 1;
    1.16 -      lua_settop(L, 4);
    1.17 -      lua_getfield(L, 4, "object_get");  // 5
    1.18 -      lua_pushvalue(L, 2);  // 6
    1.19 -      lua_gettable(L, 5);  // 6
    1.20 -      if (lua_toboolean(L, 6)) {
    1.21 -        lua_pushvalue(L, 1);  // 7
    1.22 -        lua_call(L, 1, 1);  // 6
    1.23 +    // try inherited attributes, methods or getter functions:
    1.24 +    while (lua_toboolean(L, 3)) {
    1.25 +      lua_getfield(L, 3, "object");  // 4
    1.26 +      lua_pushvalue(L, 2);  // 5
    1.27 +      lua_gettable(L, 4);  // 5
    1.28 +      if (!lua_isnil(L, 5)) return 1;
    1.29 +      lua_settop(L, 3);
    1.30 +      lua_getfield(L, 3, "object_get");  // 4
    1.31 +      lua_pushvalue(L, 2);  // 5
    1.32 +      lua_gettable(L, 4);  // 5
    1.33 +      if (lua_toboolean(L, 5)) {
    1.34 +        lua_pushvalue(L, 1);  // 6
    1.35 +        lua_call(L, 1, 1);  // 5
    1.36          return 1;
    1.37        }
    1.38 -      lua_settop(L, 4);
    1.39 -      if (lua_isnil(L, 3)) {
    1.40 -        lua_getfield(L, 4, "document_column");  // 5
    1.41 -        lua_replace(L, 3);
    1.42 -      }
    1.43 -      lua_pushliteral(L, "prototype");  // 5
    1.44 -      lua_rawget(L, 4);  // 5
    1.45 -      lua_replace(L, 4);
    1.46 +      lua_settop(L, 3);
    1.47 +      lua_pushliteral(L, "prototype");  // 4
    1.48 +      lua_rawget(L, 3);  // 4
    1.49 +      lua_replace(L, 3);
    1.50      }
    1.51 -    lua_settop(L, 3);
    1.52 +    lua_settop(L, 2);
    1.53      // try primary keys of referenced objects:
    1.54      lua_pushcfunction(L,
    1.55        mondelefant_class_get_foreign_key_reference_name
    1.56 -    );  // 4
    1.57 -    lua_getfield(L, 1, "_class");  // 5
    1.58 -    lua_pushvalue(L, 2);  // 6
    1.59 -    lua_call(L, 2, 1);  // 4
    1.60 -    if (!lua_isnil(L, 4)) {
    1.61 -      // reference name at stack position 4
    1.62 -      lua_pushcfunction(L, mondelefant_class_get_reference);  // 5
    1.63 -      lua_getfield(L, 1, "_class");  // 6
    1.64 -      lua_pushvalue(L, 4);  // 7
    1.65 -      lua_call(L, 2, 1);  // reference info at stack position 5
    1.66 -      lua_getfield(L, 1, "_ref");  // 6
    1.67 -      lua_getfield(L, 4, "ref");  // 7
    1.68 -      lua_gettable(L, 6);  // 7
    1.69 -      if (!lua_isnil(L, 7)) {
    1.70 -        if (lua_toboolean(L, 7)) {
    1.71 -          lua_getfield(L, 5, "that_key");  // 8
    1.72 -          if (lua_isnil(L, 8)) {
    1.73 +    );  // 3
    1.74 +    lua_getfield(L, 1, "_class");  // 4
    1.75 +    lua_pushvalue(L, 2);  // 5
    1.76 +    lua_call(L, 2, 1);  // 3
    1.77 +    if (!lua_isnil(L, 3)) {
    1.78 +      // reference name at stack position 3
    1.79 +      lua_pushcfunction(L, mondelefant_class_get_reference);  // 4
    1.80 +      lua_getfield(L, 1, "_class");  // 5
    1.81 +      lua_pushvalue(L, 3);  // 6
    1.82 +      lua_call(L, 2, 1);  // reference info at stack position 4
    1.83 +      lua_getfield(L, 1, "_ref");  // 5
    1.84 +      lua_getfield(L, 4, "ref");  // 6
    1.85 +      lua_gettable(L, 5);  // 6
    1.86 +      if (!lua_isnil(L, 6)) {
    1.87 +        if (lua_toboolean(L, 6)) {
    1.88 +          lua_getfield(L, 4, "that_key");  // 7
    1.89 +          if (lua_isnil(L, 7)) {
    1.90              return luaL_error(L, "Missing 'that_key' entry in model reference.");
    1.91            }
    1.92 -          lua_gettable(L, 7);  // 8
    1.93 +          lua_gettable(L, 6);  // 7
    1.94          } else {
    1.95            lua_pushnil(L);
    1.96          }
    1.97          return 1;
    1.98        }
    1.99      }
   1.100 -    lua_settop(L, 3);
   1.101 +    lua_settop(L, 2);
   1.102      // try normal data field info:
   1.103 -    lua_getfield(L, 1, "_data");  // _data table on stack position 4
   1.104 -    lua_pushvalue(L, 2);  // 5
   1.105 -    lua_gettable(L, 4);  // 5
   1.106 -    if (!lua_isnil(L, 5)) return 1;
   1.107 -    lua_settop(L, 4);  // _data table kept on stack position 4 for later use
   1.108 +    lua_getfield(L, 1, "_data");  // 3
   1.109 +    lua_pushvalue(L, 2);  // 4
   1.110 +    lua_gettable(L, 3);  // 4
   1.111 +    if (!lua_isnil(L, 4)) return 1;
   1.112 +    lua_settop(L, 2);
   1.113      // try cached referenced object (or cached NULL reference):
   1.114 -    lua_getfield(L, 1, "_ref");  // 5
   1.115 -    lua_pushvalue(L, 2);  // 6
   1.116 -    lua_gettable(L, 5);  // 6
   1.117 -    if (lua_isboolean(L, 6) && !lua_toboolean(L, 6)) {
   1.118 +    lua_getfield(L, 1, "_ref");  // 3
   1.119 +    lua_pushvalue(L, 2);  // 4
   1.120 +    lua_gettable(L, 3);  // 4
   1.121 +    if (lua_isboolean(L, 4) && !lua_toboolean(L, 4)) {
   1.122        lua_pushnil(L);
   1.123        return 1;
   1.124 -    } else if (!lua_isnil(L, 6)) {
   1.125 +    } else if (!lua_isnil(L, 4)) {
   1.126        return 1;
   1.127      }
   1.128 -    lua_settop(L, 4);
   1.129 +    lua_settop(L, 2);
   1.130      // try to load a referenced object:
   1.131 -    lua_pushcfunction(L, mondelefant_class_get_reference);  // 5
   1.132 -    lua_getfield(L, 1, "_class");  // 6
   1.133 -    lua_pushvalue(L, 2);  // 7
   1.134 -    lua_call(L, 2, 1);  // 5
   1.135 -    if (!lua_isnil(L, 5)) {
   1.136 +    lua_pushcfunction(L, mondelefant_class_get_reference);  // 3
   1.137 +    lua_getfield(L, 1, "_class");  // 4
   1.138 +    lua_pushvalue(L, 2);  // 5
   1.139 +    lua_call(L, 2, 1);  // 3
   1.140 +    if (!lua_isnil(L, 3)) {
   1.141        lua_settop(L, 2);
   1.142        lua_getfield(L, 1, "load");  // 3
   1.143        lua_pushvalue(L, 1);  // 4 (self)
   1.144 @@ -1587,19 +1580,6 @@
   1.145        if (lua_isboolean(L, 4) && !lua_toboolean(L, 4)) lua_pushnil(L);  // TODO: use special object instead of false
   1.146        return 1;
   1.147      }
   1.148 -    lua_settop(L, 4);
   1.149 -    // try proxy access to document in special column:
   1.150 -    if (lua_toboolean(L, 3)) {
   1.151 -      lua_insert(L, 3);  // switch stack values on position 3 and 4
   1.152 -      // _data table is on stack position 3
   1.153 -      // document column name is on stack position 4
   1.154 -      lua_gettable(L, 3);  // 4
   1.155 -      if (!lua_isnil(L, 4)) {
   1.156 -        lua_pushvalue(L, 2);  // 5
   1.157 -        lua_gettable(L, 4);  // 5
   1.158 -        if (!lua_isnil(L, 5)) return 1;
   1.159 -      }
   1.160 -    }
   1.161      return 0;
   1.162    } else if (result_type && !strcmp(result_type, "list")) {  // list
   1.163      lua_settop(L, 3);
   1.164 @@ -1643,81 +1623,58 @@
   1.165    // distinguish between lists and objects:
   1.166    if (result_type && !strcmp(result_type, "object")) {  // objects
   1.167      lua_settop(L, 4);
   1.168 -    lua_pushnil(L);
   1.169 -    lua_insert(L, 4);  // optional document column name on stack position 4
   1.170      // try object setter functions:
   1.171 -    // (and determine optional document column, if existent):
   1.172 -    while (lua_toboolean(L, 5)) {  // class on stack position 5 (due to insert)
   1.173 -      lua_getfield(L, 5, "object_set");  // 6
   1.174 -      lua_pushvalue(L, 2);  // 7
   1.175 -      lua_gettable(L, 6);  // 7
   1.176 -      if (lua_toboolean(L, 7)) {
   1.177 -        lua_pushvalue(L, 1);  // 8
   1.178 -        lua_pushvalue(L, 3);  // 9
   1.179 +    while (lua_toboolean(L, 4)) {
   1.180 +      lua_getfield(L, 4, "object_set");  // 5
   1.181 +      lua_pushvalue(L, 2);  // 6
   1.182 +      lua_gettable(L, 5);  // 6
   1.183 +      if (lua_toboolean(L, 6)) {
   1.184 +        lua_pushvalue(L, 1);  // 7
   1.185 +        lua_pushvalue(L, 3);  // 8
   1.186          lua_call(L, 2, 0);
   1.187          return 0;
   1.188        }
   1.189 -      lua_settop(L, 5);
   1.190 -      lua_pushliteral(L, "prototype");  // 6
   1.191 -      lua_rawget(L, 5);  // 6
   1.192 -      lua_replace(L, 5);
   1.193 +      lua_settop(L, 4);
   1.194 +      lua_pushliteral(L, "prototype");  // 5
   1.195 +      lua_rawget(L, 4);  // 5
   1.196 +      lua_replace(L, 4);
   1.197      }
   1.198 -    lua_settop(L, 4);
   1.199 -    lua_getfield(L, 1, "_data");  // _data table on stack position 5
   1.200 +    lua_settop(L, 3);
   1.201      // check, if a object reference is changed:
   1.202 -    lua_pushcfunction(L, mondelefant_class_get_reference);  // 6
   1.203 -    lua_getfield(L, 1, "_class");  // 7
   1.204 -    lua_pushvalue(L, 2);  // 8
   1.205 -    lua_call(L, 2, 1);  // 6
   1.206 -    if (!lua_isnil(L, 6)) {
   1.207 +    lua_pushcfunction(L, mondelefant_class_get_reference);  // 4
   1.208 +    lua_getfield(L, 1, "_class");  // 5
   1.209 +    lua_pushvalue(L, 2);  // 6
   1.210 +    lua_call(L, 2, 1);  // 4
   1.211 +    if (!lua_isnil(L, 4)) {
   1.212        // store object in _ref table (use false for nil):  // TODO: use special object instead of false
   1.213 -      lua_getfield(L, 1, "_ref");  // 7
   1.214 -      lua_pushvalue(L, 2);  // 8
   1.215 -      if (lua_isnil(L, 3)) lua_pushboolean(L, 0);  // 9
   1.216 -      else lua_pushvalue(L, 3);  // 9
   1.217 -      lua_settable(L, 7);
   1.218 -      lua_settop(L, 6);
   1.219 +      lua_getfield(L, 1, "_ref");  // 5
   1.220 +      lua_pushvalue(L, 2);  // 6
   1.221 +      if (lua_isnil(L, 3)) lua_pushboolean(L, 0);  // 7
   1.222 +      else lua_pushvalue(L, 3);  // 7
   1.223 +      lua_settable(L, 5);
   1.224 +      lua_settop(L, 4);
   1.225        // delete referencing key from _data table:
   1.226 -      lua_getfield(L, 6, "this_key");  // 7
   1.227 -      if (lua_isnil(L, 7)) {
   1.228 +      lua_getfield(L, 4, "this_key");  // 5
   1.229 +      if (lua_isnil(L, 5)) {
   1.230          return luaL_error(L, "Missing 'this_key' entry in model reference.");
   1.231        }
   1.232 -      //lua_getfield(L, 1, "_data");  // 6
   1.233 -      lua_pushvalue(L, 7);  // 8
   1.234 -      lua_pushnil(L);  // 9
   1.235 -      lua_settable(L, 5);
   1.236 -      lua_settop(L, 7);
   1.237 -      lua_getfield(L, 1, "_dirty");  // 8
   1.238 -      lua_pushvalue(L, 7);  // 9
   1.239 -      lua_pushboolean(L, 1);  // 10
   1.240 -      lua_settable(L, 5);
   1.241 +      lua_getfield(L, 1, "_data");  // 6
   1.242 +      lua_pushvalue(L, 5);  // 7
   1.243 +      lua_pushnil(L);  // 8
   1.244 +      lua_settable(L, 6);
   1.245 +      lua_settop(L, 5);
   1.246 +      lua_getfield(L, 1, "_dirty");  // 6
   1.247 +      lua_pushvalue(L, 5);  // 7
   1.248 +      lua_pushboolean(L, 1);  // 8
   1.249 +      lua_settable(L, 6);
   1.250        return 0;
   1.251      }
   1.252 -    lua_settop(L, 5);
   1.253 -    // check proxy access to document in special column:
   1.254 -    if (lua_toboolean(L, 4)) {
   1.255 -      lua_getfield(L, 1, "_column_info");  // 6
   1.256 -      lua_pushvalue(L, 2);  // 7
   1.257 -      lua_gettable(L, 6);  // 7
   1.258 -      if (lua_toboolean(L, 7)) {
   1.259 -        lua_settop(L, 5);
   1.260 -        lua_pushvalue(L, 4);  // 6
   1.261 -        // _data table is on stack position 5
   1.262 -        // document column name is on stack position 4 and 6
   1.263 -        lua_gettable(L, 5);  // 6
   1.264 -        if (!lua_isnil(L, 6)) {
   1.265 -          lua_pushvalue(L, 2);  // 7
   1.266 -          lua_pushvalue(L, 3);  // 8
   1.267 -          lua_settable(L, 6);
   1.268 -          return 0;
   1.269 -        }
   1.270 -      }
   1.271 -      lua_settop(L, 5);
   1.272 -    }
   1.273 +    lua_settop(L, 3);
   1.274      // store value in data field info:
   1.275 -    lua_pushvalue(L, 2);  // 6
   1.276 -    lua_pushvalue(L, 3);  // 7
   1.277 -    lua_settable(L, 5);
   1.278 +    lua_getfield(L, 1, "_data");  // 4
   1.279 +    lua_pushvalue(L, 2);  // 5
   1.280 +    lua_pushvalue(L, 3);  // 6
   1.281 +    lua_settable(L, 4);
   1.282      lua_settop(L, 3);
   1.283      // mark field as dirty (needs to be UPDATEd on save):
   1.284      lua_getfield(L, 1, "_dirty");  // 4

Impressum / About Us