# HG changeset patch # User jbe # Date 1447629593 -3600 # Node ID 1625fd9051687679606e703972b2baadd3963dc8 # Parent ecafddf7ac936a37f34d7a1878adc779116be030 Preparatory work for proxy write access to "document_column" diff -r ecafddf7ac93 -r 1625fd905168 libraries/mondelefant/mondelefant_native.c --- a/libraries/mondelefant/mondelefant_native.c Sun Nov 15 22:00:12 2015 +0100 +++ b/libraries/mondelefant/mondelefant_native.c Mon Nov 16 00:19:53 2015 +0100 @@ -1636,61 +1636,96 @@ // get value of "_type" attribute: lua_getfield(L, 1, "_type"); // 5 result_type = lua_tostring(L, 5); - // distinguish between lists and objects: - if (result_type && !strcmp(result_type, "object")) { // objects - lua_settop(L, 4); - // try object setter functions: - while (lua_toboolean(L, 4)) { - lua_getfield(L, 4, "object_set"); // 5 + + + lua_settop(L, 3); + lua_pushnil(L); + lua_insert(L, 3); // optional document column name on stack position 3 + // try inherited attributes, methods or getter functions + // (and determine optional document column, if existent): + while (lua_toboolean(L, 4)) { // class on stack position 4 (due to insert) + lua_getfield(L, 4, "object"); // 5 + lua_pushvalue(L, 2); // 6 + lua_gettable(L, 5); // 6 + if (!lua_isnil(L, 6)) return 1; + lua_settop(L, 4); + lua_getfield(L, 4, "object_get"); // 5 lua_pushvalue(L, 2); // 6 lua_gettable(L, 5); // 6 if (lua_toboolean(L, 6)) { lua_pushvalue(L, 1); // 7 - lua_pushvalue(L, 3); // 8 - lua_call(L, 2, 0); - return 0; + lua_call(L, 1, 1); // 6 + return 1; } lua_settop(L, 4); + if (lua_isnil(L, 3)) { + lua_getfield(L, 4, "document_column"); // 5 + lua_replace(L, 3); + } lua_pushliteral(L, "prototype"); // 5 lua_rawget(L, 4); // 5 lua_replace(L, 4); } lua_settop(L, 3); + + // distinguish between lists and objects: + if (result_type && !strcmp(result_type, "object")) { // objects + lua_settop(L, 4); + lua_pushnil(L); + lua_insert(L, 4); // optional document column name on stack position 4 + // try object setter functions: + // (and determine optional document column, if existent): + while (lua_toboolean(L, 5)) { // class on stack position 5 (due to insert) + lua_getfield(L, 5, "object_set"); // 6 + lua_pushvalue(L, 2); // 7 + lua_gettable(L, 6); // 7 + if (lua_toboolean(L, 7)) { + lua_pushvalue(L, 1); // 8 + lua_pushvalue(L, 3); // 9 + lua_call(L, 2, 0); + return 0; + } + lua_settop(L, 5); + lua_pushliteral(L, "prototype"); // 6 + lua_rawget(L, 5); // 6 + lua_replace(L, 5); + } + lua_settop(L, 4); + lua_getfield(L, 1, "_data"); // _data table on stack position 5 // check, if a object reference is changed: - lua_pushcfunction(L, mondelefant_class_get_reference); // 4 - lua_getfield(L, 1, "_class"); // 5 - lua_pushvalue(L, 2); // 6 - lua_call(L, 2, 1); // 4 - if (!lua_isnil(L, 4)) { + lua_pushcfunction(L, mondelefant_class_get_reference); // 6 + lua_getfield(L, 1, "_class"); // 7 + lua_pushvalue(L, 2); // 8 + lua_call(L, 2, 1); // 6 + if (!lua_isnil(L, 6)) { // store object in _ref table (use false for nil): // TODO: use special object instead of false - lua_getfield(L, 1, "_ref"); // 5 - lua_pushvalue(L, 2); // 6 - if (lua_isnil(L, 3)) lua_pushboolean(L, 0); // 7 - else lua_pushvalue(L, 3); // 7 - lua_settable(L, 5); - lua_settop(L, 4); + lua_getfield(L, 1, "_ref"); // 7 + lua_pushvalue(L, 2); // 8 + if (lua_isnil(L, 3)) lua_pushboolean(L, 0); // 9 + else lua_pushvalue(L, 3); // 9 + lua_settable(L, 7); + lua_settop(L, 6); // delete referencing key from _data table: - lua_getfield(L, 4, "this_key"); // 5 - if (lua_isnil(L, 5)) { + lua_getfield(L, 6, "this_key"); // 7 + if (lua_isnil(L, 7)) { return luaL_error(L, "Missing 'this_key' entry in model reference."); } - lua_getfield(L, 1, "_data"); // 6 - lua_pushvalue(L, 5); // 7 - lua_pushnil(L); // 8 - lua_settable(L, 6); - lua_settop(L, 5); - lua_getfield(L, 1, "_dirty"); // 6 - lua_pushvalue(L, 5); // 7 - lua_pushboolean(L, 1); // 8 - lua_settable(L, 6); + //lua_getfield(L, 1, "_data"); // 6 + lua_pushvalue(L, 7); // 8 + lua_pushnil(L); // 9 + lua_settable(L, 5); + lua_settop(L, 7); + lua_getfield(L, 1, "_dirty"); // 8 + lua_pushvalue(L, 7); // 9 + lua_pushboolean(L, 1); // 10 + lua_settable(L, 5); return 0; } - lua_settop(L, 3); + lua_settop(L, 5); // store value in data field info: - lua_getfield(L, 1, "_data"); // 4 - lua_pushvalue(L, 2); // 5 - lua_pushvalue(L, 3); // 6 - lua_settable(L, 4); + lua_pushvalue(L, 2); // 6 + lua_pushvalue(L, 3); // 7 + lua_settable(L, 5); lua_settop(L, 3); // mark field as dirty (needs to be UPDATEd on save): lua_getfield(L, 1, "_dirty"); // 4