# HG changeset patch # User jbe # Date 1455044974 -3600 # Node ID 66d7a0ac9c9dfbfa0364a9f3c2877a610dee7135 # Parent 29b1f7a049349b862738024037593897dfb5ae31 Allow :create_list(...) to create a non-empty list by passing a table as argument (needed for references) diff -r 29b1f7a04934 -r 66d7a0ac9c9d libraries/mondelefant/mondelefant_native.autodoc.lua --- a/libraries/mondelefant/mondelefant_native.autodoc.lua Fri Feb 05 01:26:00 2016 +0100 +++ b/libraries/mondelefant/mondelefant_native.autodoc.lua Tue Feb 09 20:09:34 2016 +0100 @@ -93,10 +93,12 @@ --[[-- -db_list = -- database result being an empty list -:create_list() +db_list = -- database result being an empty list (or filled list) +:create_list( + tbl -- optional table to be converted to a filled list +) -Creates an empty database result representing a list. The used meta-table is "result_metatable". The attribute "_connection" is set to the database handle, and the attribute "_type" is set to "list". The attribute "_class" is initialized to the default class prototype "class_prototype" of the module. +Creates a database result representing a list. The used meta-table is "result_metatable". The attribute "_connection" is set to the database handle, and the attribute "_type" is set to "list". The attribute "_class" is initialized to the default class prototype "class_prototype" of the module. --]]-- -- implemented in mondelefant_native.c as diff -r 29b1f7a04934 -r 66d7a0ac9c9d libraries/mondelefant/mondelefant_native.c --- a/libraries/mondelefant/mondelefant_native.c Fri Feb 05 01:26:00 2016 +0100 +++ b/libraries/mondelefant/mondelefant_native.c Tue Feb 09 20:09:34 2016 +0100 @@ -534,9 +534,14 @@ static int mondelefant_conn_create_list(lua_State *L) { // ensure that first argument is a database connection: luaL_checkudata(L, 1, MONDELEFANT_CONN_MT_REGKEY); - // create new table on stack position 2: - lua_settop(L, 1); - lua_newtable(L); // 2 + // if no second argument is given, use an empty table: + if (lua_isnoneornil(L, 2)) { + lua_settop(L, 1); + lua_newtable(L); // 2 + } else { + luaL_checktype(L, 2, LUA_TTABLE); + lua_settop(L, 2); + } // set meta-table for database result lists/objects: luaL_setmetatable(L, MONDELEFANT_RESULT_MT_REGKEY); // set "_connection" attribute to self: