# HG changeset patch # User jbe # Date 1447695109 -3600 # Node ID 810c020b0da4153d67a912e3c4784b27ebe34ddd # Parent 46ff54bbd10ed387f4baf54f7ade0d9fc42eac27 Reverted changes to mondelefant_result_index and mondelefant_result_newindex C-functions (proxying of JSON document) diff -r 46ff54bbd10e -r 810c020b0da4 libraries/mondelefant/mondelefant_native.c --- a/libraries/mondelefant/mondelefant_native.c Mon Nov 16 16:55:49 2015 +0100 +++ b/libraries/mondelefant/mondelefant_native.c Mon Nov 16 18:31:49 2015 +0100 @@ -1494,87 +1494,80 @@ // different lookup for lists and objects: if (result_type && !strcmp(result_type, "object")) { // object 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_call(L, 1, 1); // 6 + // try inherited attributes, methods or getter functions: + while (lua_toboolean(L, 3)) { + lua_getfield(L, 3, "object"); // 4 + lua_pushvalue(L, 2); // 5 + lua_gettable(L, 4); // 5 + if (!lua_isnil(L, 5)) return 1; + lua_settop(L, 3); + lua_getfield(L, 3, "object_get"); // 4 + lua_pushvalue(L, 2); // 5 + lua_gettable(L, 4); // 5 + if (lua_toboolean(L, 5)) { + lua_pushvalue(L, 1); // 6 + lua_call(L, 1, 1); // 5 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); + lua_pushliteral(L, "prototype"); // 4 + lua_rawget(L, 3); // 4 + lua_replace(L, 3); } - lua_settop(L, 3); + lua_settop(L, 2); // try primary keys of referenced objects: lua_pushcfunction(L, mondelefant_class_get_foreign_key_reference_name - ); // 4 - lua_getfield(L, 1, "_class"); // 5 - lua_pushvalue(L, 2); // 6 - lua_call(L, 2, 1); // 4 - if (!lua_isnil(L, 4)) { - // reference name at stack position 4 - lua_pushcfunction(L, mondelefant_class_get_reference); // 5 - lua_getfield(L, 1, "_class"); // 6 - lua_pushvalue(L, 4); // 7 - lua_call(L, 2, 1); // reference info at stack position 5 - lua_getfield(L, 1, "_ref"); // 6 - lua_getfield(L, 4, "ref"); // 7 - lua_gettable(L, 6); // 7 - if (!lua_isnil(L, 7)) { - if (lua_toboolean(L, 7)) { - lua_getfield(L, 5, "that_key"); // 8 - if (lua_isnil(L, 8)) { + ); // 3 + lua_getfield(L, 1, "_class"); // 4 + lua_pushvalue(L, 2); // 5 + lua_call(L, 2, 1); // 3 + if (!lua_isnil(L, 3)) { + // reference name at stack position 3 + lua_pushcfunction(L, mondelefant_class_get_reference); // 4 + lua_getfield(L, 1, "_class"); // 5 + lua_pushvalue(L, 3); // 6 + lua_call(L, 2, 1); // reference info at stack position 4 + lua_getfield(L, 1, "_ref"); // 5 + lua_getfield(L, 4, "ref"); // 6 + lua_gettable(L, 5); // 6 + if (!lua_isnil(L, 6)) { + if (lua_toboolean(L, 6)) { + lua_getfield(L, 4, "that_key"); // 7 + if (lua_isnil(L, 7)) { return luaL_error(L, "Missing 'that_key' entry in model reference."); } - lua_gettable(L, 7); // 8 + lua_gettable(L, 6); // 7 } else { lua_pushnil(L); } return 1; } } - lua_settop(L, 3); + lua_settop(L, 2); // try normal data field info: - lua_getfield(L, 1, "_data"); // _data table on stack position 4 - lua_pushvalue(L, 2); // 5 - lua_gettable(L, 4); // 5 - if (!lua_isnil(L, 5)) return 1; - lua_settop(L, 4); // _data table kept on stack position 4 for later use + lua_getfield(L, 1, "_data"); // 3 + lua_pushvalue(L, 2); // 4 + lua_gettable(L, 3); // 4 + if (!lua_isnil(L, 4)) return 1; + lua_settop(L, 2); // try cached referenced object (or cached NULL reference): - lua_getfield(L, 1, "_ref"); // 5 - lua_pushvalue(L, 2); // 6 - lua_gettable(L, 5); // 6 - if (lua_isboolean(L, 6) && !lua_toboolean(L, 6)) { + lua_getfield(L, 1, "_ref"); // 3 + lua_pushvalue(L, 2); // 4 + lua_gettable(L, 3); // 4 + if (lua_isboolean(L, 4) && !lua_toboolean(L, 4)) { lua_pushnil(L); return 1; - } else if (!lua_isnil(L, 6)) { + } else if (!lua_isnil(L, 4)) { return 1; } - lua_settop(L, 4); + lua_settop(L, 2); // try to load a referenced object: - lua_pushcfunction(L, mondelefant_class_get_reference); // 5 - lua_getfield(L, 1, "_class"); // 6 - lua_pushvalue(L, 2); // 7 - lua_call(L, 2, 1); // 5 - if (!lua_isnil(L, 5)) { + lua_pushcfunction(L, mondelefant_class_get_reference); // 3 + lua_getfield(L, 1, "_class"); // 4 + lua_pushvalue(L, 2); // 5 + lua_call(L, 2, 1); // 3 + if (!lua_isnil(L, 3)) { lua_settop(L, 2); lua_getfield(L, 1, "load"); // 3 lua_pushvalue(L, 1); // 4 (self) @@ -1587,19 +1580,6 @@ if (lua_isboolean(L, 4) && !lua_toboolean(L, 4)) lua_pushnil(L); // TODO: use special object instead of false return 1; } - lua_settop(L, 4); - // try proxy access to document in special column: - if (lua_toboolean(L, 3)) { - lua_insert(L, 3); // switch stack values on position 3 and 4 - // _data table is on stack position 3 - // document column name is on stack position 4 - lua_gettable(L, 3); // 4 - if (!lua_isnil(L, 4)) { - lua_pushvalue(L, 2); // 5 - lua_gettable(L, 4); // 5 - if (!lua_isnil(L, 5)) return 1; - } - } return 0; } else if (result_type && !strcmp(result_type, "list")) { // list lua_settop(L, 3); @@ -1643,81 +1623,58 @@ // 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 + while (lua_toboolean(L, 4)) { + lua_getfield(L, 4, "object_set"); // 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_settop(L, 5); - lua_pushliteral(L, "prototype"); // 6 - lua_rawget(L, 5); // 6 - lua_replace(L, 5); + lua_settop(L, 4); + lua_pushliteral(L, "prototype"); // 5 + lua_rawget(L, 4); // 5 + lua_replace(L, 4); } - lua_settop(L, 4); - lua_getfield(L, 1, "_data"); // _data table on stack position 5 + lua_settop(L, 3); // check, if a object reference is changed: - 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)) { + 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)) { // store object in _ref table (use false for nil): // TODO: use special object instead of false - 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); + 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); // delete referencing key from _data table: - lua_getfield(L, 6, "this_key"); // 7 - if (lua_isnil(L, 7)) { + lua_getfield(L, 4, "this_key"); // 5 + if (lua_isnil(L, 5)) { return luaL_error(L, "Missing 'this_key' entry in model reference."); } - //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); + 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); return 0; } - lua_settop(L, 5); - // check proxy access to document in special column: - if (lua_toboolean(L, 4)) { - lua_getfield(L, 1, "_column_info"); // 6 - lua_pushvalue(L, 2); // 7 - lua_gettable(L, 6); // 7 - if (lua_toboolean(L, 7)) { - lua_settop(L, 5); - lua_pushvalue(L, 4); // 6 - // _data table is on stack position 5 - // document column name is on stack position 4 and 6 - lua_gettable(L, 5); // 6 - if (!lua_isnil(L, 6)) { - lua_pushvalue(L, 2); // 7 - lua_pushvalue(L, 3); // 8 - lua_settable(L, 6); - return 0; - } - } - lua_settop(L, 5); - } + lua_settop(L, 3); // store value in data field info: - lua_pushvalue(L, 2); // 6 - lua_pushvalue(L, 3); // 7 - lua_settable(L, 5); + lua_getfield(L, 1, "_data"); // 4 + lua_pushvalue(L, 2); // 5 + lua_pushvalue(L, 3); // 6 + lua_settable(L, 4); lua_settop(L, 3); // mark field as dirty (needs to be UPDATEd on save): lua_getfield(L, 1, "_dirty"); // 4