webmcp
changeset 383:f0ac171edf62
New implementation of (proxy) read access to fields of JSON object in a special column
author | jbe |
---|---|
date | Mon Nov 16 21:18:56 2015 +0100 (2015-11-16) |
parents | 810c020b0da4 |
children | 3fffd1ae5a68 |
files | libraries/mondelefant/mondelefant_native.c |
line diff
1.1 --- a/libraries/mondelefant/mondelefant_native.c Mon Nov 16 18:31:49 2015 +0100 1.2 +++ b/libraries/mondelefant/mondelefant_native.c Mon Nov 16 21:18:56 2015 +0100 1.3 @@ -1478,7 +1478,7 @@ 1.4 if (lua_type(L, 2) != LUA_TSTRING || lua_tostring(L, 2)[0] == '_') { 1.5 return 0; 1.6 } 1.7 - // get value of "_class" attribute, or default class, when unset: 1.8 + // value of "_class" attribute or default class:on stack position 3: 1.9 lua_settop(L, 2); 1.10 lua_getfield(L, 1, "_class"); // 3 1.11 if (!lua_toboolean(L, 3)) { 1.12 @@ -1494,80 +1494,81 @@ 1.13 // different lookup for lists and objects: 1.14 if (result_type && !strcmp(result_type, "object")) { // object 1.15 lua_settop(L, 3); 1.16 + lua_pushvalue(L, 3); // 4 1.17 // try inherited attributes, methods or getter functions: 1.18 - while (lua_toboolean(L, 3)) { 1.19 - lua_getfield(L, 3, "object"); // 4 1.20 - lua_pushvalue(L, 2); // 5 1.21 - lua_gettable(L, 4); // 5 1.22 - if (!lua_isnil(L, 5)) return 1; 1.23 - lua_settop(L, 3); 1.24 - lua_getfield(L, 3, "object_get"); // 4 1.25 - lua_pushvalue(L, 2); // 5 1.26 - lua_gettable(L, 4); // 5 1.27 - if (lua_toboolean(L, 5)) { 1.28 - lua_pushvalue(L, 1); // 6 1.29 - lua_call(L, 1, 1); // 5 1.30 + while (lua_toboolean(L, 4)) { 1.31 + lua_getfield(L, 4, "object"); // 5 1.32 + lua_pushvalue(L, 2); // 6 1.33 + lua_gettable(L, 5); // 6 1.34 + if (!lua_isnil(L, 6)) return 1; 1.35 + lua_settop(L, 4); 1.36 + lua_getfield(L, 4, "object_get"); // 5 1.37 + lua_pushvalue(L, 2); // 6 1.38 + lua_gettable(L, 5); // 6 1.39 + if (lua_toboolean(L, 6)) { 1.40 + lua_pushvalue(L, 1); // 7 1.41 + lua_call(L, 1, 1); // 6 1.42 return 1; 1.43 } 1.44 - lua_settop(L, 3); 1.45 - lua_pushliteral(L, "prototype"); // 4 1.46 - lua_rawget(L, 3); // 4 1.47 - lua_replace(L, 3); 1.48 + lua_settop(L, 4); 1.49 + lua_pushliteral(L, "prototype"); // 5 1.50 + lua_rawget(L, 4); // 5 1.51 + lua_replace(L, 4); 1.52 } 1.53 - lua_settop(L, 2); 1.54 + lua_settop(L, 3); 1.55 // try primary keys of referenced objects: 1.56 lua_pushcfunction(L, 1.57 mondelefant_class_get_foreign_key_reference_name 1.58 - ); // 3 1.59 - lua_getfield(L, 1, "_class"); // 4 1.60 - lua_pushvalue(L, 2); // 5 1.61 - lua_call(L, 2, 1); // 3 1.62 - if (!lua_isnil(L, 3)) { 1.63 - // reference name at stack position 3 1.64 - lua_pushcfunction(L, mondelefant_class_get_reference); // 4 1.65 - lua_getfield(L, 1, "_class"); // 5 1.66 + ); // 4 1.67 + lua_pushvalue(L, 3); // 5 1.68 + lua_pushvalue(L, 2); // 6 1.69 + lua_call(L, 2, 1); // 4 1.70 + if (!lua_isnil(L, 4)) { 1.71 + // reference name at stack position 4 1.72 + lua_pushcfunction(L, mondelefant_class_get_reference); // 5 1.73 lua_pushvalue(L, 3); // 6 1.74 - lua_call(L, 2, 1); // reference info at stack position 4 1.75 - lua_getfield(L, 1, "_ref"); // 5 1.76 - lua_getfield(L, 4, "ref"); // 6 1.77 - lua_gettable(L, 5); // 6 1.78 - if (!lua_isnil(L, 6)) { 1.79 - if (lua_toboolean(L, 6)) { 1.80 - lua_getfield(L, 4, "that_key"); // 7 1.81 - if (lua_isnil(L, 7)) { 1.82 + lua_pushvalue(L, 4); // 7 1.83 + lua_call(L, 2, 1); // reference info at stack position 5 1.84 + lua_getfield(L, 1, "_ref"); // 6 1.85 + lua_getfield(L, 5, "ref"); // 7 1.86 + lua_gettable(L, 6); // 7 1.87 + if (!lua_isnil(L, 7)) { 1.88 + if (lua_toboolean(L, 7)) { 1.89 + lua_getfield(L, 5, "that_key"); // 8 1.90 + if (lua_isnil(L, 8)) { 1.91 return luaL_error(L, "Missing 'that_key' entry in model reference."); 1.92 } 1.93 - lua_gettable(L, 6); // 7 1.94 + lua_gettable(L, 7); // 8 1.95 } else { 1.96 lua_pushnil(L); 1.97 } 1.98 return 1; 1.99 } 1.100 } 1.101 - lua_settop(L, 2); 1.102 + lua_settop(L, 3); 1.103 + lua_getfield(L, 1, "_data"); // _data table on stack position 4 1.104 // try normal data field info: 1.105 - lua_getfield(L, 1, "_data"); // 3 1.106 - lua_pushvalue(L, 2); // 4 1.107 - lua_gettable(L, 3); // 4 1.108 - if (!lua_isnil(L, 4)) return 1; 1.109 - lua_settop(L, 2); 1.110 + lua_pushvalue(L, 2); // 5 1.111 + lua_gettable(L, 4); // 5 1.112 + if (!lua_isnil(L, 5)) return 1; 1.113 + lua_settop(L, 4); // keep _data table on stack 1.114 // try cached referenced object (or cached NULL reference): 1.115 - lua_getfield(L, 1, "_ref"); // 3 1.116 - lua_pushvalue(L, 2); // 4 1.117 - lua_gettable(L, 3); // 4 1.118 - if (lua_isboolean(L, 4) && !lua_toboolean(L, 4)) { 1.119 + lua_getfield(L, 1, "_ref"); // 5 1.120 + lua_pushvalue(L, 2); // 6 1.121 + lua_gettable(L, 5); // 6 1.122 + if (lua_isboolean(L, 6) && !lua_toboolean(L, 6)) { 1.123 lua_pushnil(L); 1.124 return 1; 1.125 - } else if (!lua_isnil(L, 4)) { 1.126 + } else if (!lua_isnil(L, 6)) { 1.127 return 1; 1.128 } 1.129 - lua_settop(L, 2); 1.130 + lua_settop(L, 4); 1.131 // try to load a referenced object: 1.132 - lua_pushcfunction(L, mondelefant_class_get_reference); // 3 1.133 - lua_getfield(L, 1, "_class"); // 4 1.134 - lua_pushvalue(L, 2); // 5 1.135 - lua_call(L, 2, 1); // 3 1.136 - if (!lua_isnil(L, 3)) { 1.137 + lua_pushcfunction(L, mondelefant_class_get_reference); // 5 1.138 + lua_pushvalue(L, 3); // 6 1.139 + lua_pushvalue(L, 2); // 7 1.140 + lua_call(L, 2, 1); // 5 1.141 + if (!lua_isnil(L, 5)) { 1.142 lua_settop(L, 2); 1.143 lua_getfield(L, 1, "load"); // 3 1.144 lua_pushvalue(L, 1); // 4 (self) 1.145 @@ -1580,6 +1581,17 @@ 1.146 if (lua_isboolean(L, 4) && !lua_toboolean(L, 4)) lua_pushnil(L); // TODO: use special object instead of false 1.147 return 1; 1.148 } 1.149 + lua_settop(L, 4); 1.150 + // try proxy access to document in special column: 1.151 + lua_getfield(L, 3, "document_column"); // 5 1.152 + if (lua_toboolean(L, 5)) { 1.153 + lua_gettable(L, 4); // 5 1.154 + if (!lua_isnil(L, 5)) { 1.155 + lua_pushvalue(L, 2); // 6 1.156 + lua_gettable(L, 5); // 6 1.157 + if (!lua_isnil(L, 6)) return 1; 1.158 + } 1.159 + } 1.160 return 0; 1.161 } else if (result_type && !strcmp(result_type, "list")) { // list 1.162 lua_settop(L, 3);