webmcp
changeset 378:1625fd905168
Preparatory work for proxy write access to "document_column"
author | jbe |
---|---|
date | Mon Nov 16 00:19:53 2015 +0100 (2015-11-16) |
parents | ecafddf7ac93 |
children | 4b1d88f77ab8 |
files | libraries/mondelefant/mondelefant_native.c |
line diff
1.1 --- a/libraries/mondelefant/mondelefant_native.c Sun Nov 15 22:00:12 2015 +0100 1.2 +++ b/libraries/mondelefant/mondelefant_native.c Mon Nov 16 00:19:53 2015 +0100 1.3 @@ -1636,61 +1636,96 @@ 1.4 // get value of "_type" attribute: 1.5 lua_getfield(L, 1, "_type"); // 5 1.6 result_type = lua_tostring(L, 5); 1.7 - // distinguish between lists and objects: 1.8 - if (result_type && !strcmp(result_type, "object")) { // objects 1.9 - lua_settop(L, 4); 1.10 - // try object setter functions: 1.11 - while (lua_toboolean(L, 4)) { 1.12 - lua_getfield(L, 4, "object_set"); // 5 1.13 + 1.14 + 1.15 + lua_settop(L, 3); 1.16 + lua_pushnil(L); 1.17 + lua_insert(L, 3); // optional document column name on stack position 3 1.18 + // try inherited attributes, methods or getter functions 1.19 + // (and determine optional document column, if existent): 1.20 + while (lua_toboolean(L, 4)) { // class on stack position 4 (due to insert) 1.21 + lua_getfield(L, 4, "object"); // 5 1.22 + lua_pushvalue(L, 2); // 6 1.23 + lua_gettable(L, 5); // 6 1.24 + if (!lua_isnil(L, 6)) return 1; 1.25 + lua_settop(L, 4); 1.26 + lua_getfield(L, 4, "object_get"); // 5 1.27 lua_pushvalue(L, 2); // 6 1.28 lua_gettable(L, 5); // 6 1.29 if (lua_toboolean(L, 6)) { 1.30 lua_pushvalue(L, 1); // 7 1.31 - lua_pushvalue(L, 3); // 8 1.32 - lua_call(L, 2, 0); 1.33 - return 0; 1.34 + lua_call(L, 1, 1); // 6 1.35 + return 1; 1.36 } 1.37 lua_settop(L, 4); 1.38 + if (lua_isnil(L, 3)) { 1.39 + lua_getfield(L, 4, "document_column"); // 5 1.40 + lua_replace(L, 3); 1.41 + } 1.42 lua_pushliteral(L, "prototype"); // 5 1.43 lua_rawget(L, 4); // 5 1.44 lua_replace(L, 4); 1.45 } 1.46 lua_settop(L, 3); 1.47 + 1.48 + // distinguish between lists and objects: 1.49 + if (result_type && !strcmp(result_type, "object")) { // objects 1.50 + lua_settop(L, 4); 1.51 + lua_pushnil(L); 1.52 + lua_insert(L, 4); // optional document column name on stack position 4 1.53 + // try object setter functions: 1.54 + // (and determine optional document column, if existent): 1.55 + while (lua_toboolean(L, 5)) { // class on stack position 5 (due to insert) 1.56 + lua_getfield(L, 5, "object_set"); // 6 1.57 + lua_pushvalue(L, 2); // 7 1.58 + lua_gettable(L, 6); // 7 1.59 + if (lua_toboolean(L, 7)) { 1.60 + lua_pushvalue(L, 1); // 8 1.61 + lua_pushvalue(L, 3); // 9 1.62 + lua_call(L, 2, 0); 1.63 + return 0; 1.64 + } 1.65 + lua_settop(L, 5); 1.66 + lua_pushliteral(L, "prototype"); // 6 1.67 + lua_rawget(L, 5); // 6 1.68 + lua_replace(L, 5); 1.69 + } 1.70 + lua_settop(L, 4); 1.71 + lua_getfield(L, 1, "_data"); // _data table on stack position 5 1.72 // check, if a object reference is changed: 1.73 - lua_pushcfunction(L, mondelefant_class_get_reference); // 4 1.74 - lua_getfield(L, 1, "_class"); // 5 1.75 - lua_pushvalue(L, 2); // 6 1.76 - lua_call(L, 2, 1); // 4 1.77 - if (!lua_isnil(L, 4)) { 1.78 + lua_pushcfunction(L, mondelefant_class_get_reference); // 6 1.79 + lua_getfield(L, 1, "_class"); // 7 1.80 + lua_pushvalue(L, 2); // 8 1.81 + lua_call(L, 2, 1); // 6 1.82 + if (!lua_isnil(L, 6)) { 1.83 // store object in _ref table (use false for nil): // TODO: use special object instead of false 1.84 - lua_getfield(L, 1, "_ref"); // 5 1.85 - lua_pushvalue(L, 2); // 6 1.86 - if (lua_isnil(L, 3)) lua_pushboolean(L, 0); // 7 1.87 - else lua_pushvalue(L, 3); // 7 1.88 - lua_settable(L, 5); 1.89 - lua_settop(L, 4); 1.90 + lua_getfield(L, 1, "_ref"); // 7 1.91 + lua_pushvalue(L, 2); // 8 1.92 + if (lua_isnil(L, 3)) lua_pushboolean(L, 0); // 9 1.93 + else lua_pushvalue(L, 3); // 9 1.94 + lua_settable(L, 7); 1.95 + lua_settop(L, 6); 1.96 // delete referencing key from _data table: 1.97 - lua_getfield(L, 4, "this_key"); // 5 1.98 - if (lua_isnil(L, 5)) { 1.99 + lua_getfield(L, 6, "this_key"); // 7 1.100 + if (lua_isnil(L, 7)) { 1.101 return luaL_error(L, "Missing 'this_key' entry in model reference."); 1.102 } 1.103 - lua_getfield(L, 1, "_data"); // 6 1.104 - lua_pushvalue(L, 5); // 7 1.105 - lua_pushnil(L); // 8 1.106 - lua_settable(L, 6); 1.107 - lua_settop(L, 5); 1.108 - lua_getfield(L, 1, "_dirty"); // 6 1.109 - lua_pushvalue(L, 5); // 7 1.110 - lua_pushboolean(L, 1); // 8 1.111 - lua_settable(L, 6); 1.112 + //lua_getfield(L, 1, "_data"); // 6 1.113 + lua_pushvalue(L, 7); // 8 1.114 + lua_pushnil(L); // 9 1.115 + lua_settable(L, 5); 1.116 + lua_settop(L, 7); 1.117 + lua_getfield(L, 1, "_dirty"); // 8 1.118 + lua_pushvalue(L, 7); // 9 1.119 + lua_pushboolean(L, 1); // 10 1.120 + lua_settable(L, 5); 1.121 return 0; 1.122 } 1.123 - lua_settop(L, 3); 1.124 + lua_settop(L, 5); 1.125 // store value in data field info: 1.126 - lua_getfield(L, 1, "_data"); // 4 1.127 - lua_pushvalue(L, 2); // 5 1.128 - lua_pushvalue(L, 3); // 6 1.129 - lua_settable(L, 4); 1.130 + lua_pushvalue(L, 2); // 6 1.131 + lua_pushvalue(L, 3); // 7 1.132 + lua_settable(L, 5); 1.133 lua_settop(L, 3); 1.134 // mark field as dirty (needs to be UPDATEd on save): 1.135 lua_getfield(L, 1, "_dirty"); // 4