From patchwork Wed Jan 17 14:34:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Herbrechtsmeier X-Patchwork-Id: 862293 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::238; helo=mail-wr0-x238.google.com; envelope-from=swupdate+bncbdn7dbh5yqibbwv67xjakgqe57maesy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="LeNf9pfE"; dkim-atps=neutral Received: from mail-wr0-x238.google.com (mail-wr0-x238.google.com [IPv6:2a00:1450:400c:c0c::238]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zM8lx1V9Jz9s71 for ; Thu, 18 Jan 2018 01:36:12 +1100 (AEDT) Received: by mail-wr0-x238.google.com with SMTP id h38sf6721051wrh.11 for ; Wed, 17 Jan 2018 06:36:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1516199770; cv=pass; d=google.com; s=arc-20160816; b=d036MKbmNm2lvpl24fnxuuU5DTv42FRDvCrDtNwYNdxgWW8R4L7AZ4aDauNAQzdS45 RMqd31boUZSWNPoupXhyF4JBWL2FqCsbvvcJMwYOezjI5QYlm21VDg/1iFhAal07sU7R MCAvuSvcTiFHggzWa9N4oGT63+aV4jhsJWXxWKnjn1G9x5Fe3Q0MB6mQKgO5AG6Ie8lV DX1QftE2xTPre6GbyOsQwWbEppw/VTXVJi70oqXke1Effe8sgQk0Xc2SoxCabuRVAX8H 1Q5wNhZaTOd2tEApxkNF7R13Rc3UcQpOZbyC9JgpdZpLdH1PenAFmWe/GyhpjFShBPIR 8ZTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=FLYSDCWXwnv7MBvU9SOBytJXsj9egOascOCu9xKIv6s=; b=wwaY7R840NTBLMsmsxEW0qTBmmQhMHk2DQhLj98L4mV9PNxTjfkNAcCx7H+7cK6vqA QLzLVhe9rJfHqmBsr5UAcqTVbeTv29zKd9yOM48OllkwzbVWogI8kViWPk4ZUHqEu8km BTdHYs8ieLuT78IbVOOAwoDA4ORJLrGsLmK4AH7Qe/GGuWFs2lx1fIdu/oyKCdEchJiN I255Urqz5Lwm4V1cribM/5kmGq65rj3paGMQfwE9tSHVxcndq+yFmMr1Xp7ut+Kl5eaK OkZBS0Scf6Ob387kfU4U5dos4J66tt9uDQJIJXm0KS2lvGoxs+PgFGXvaRgBfMI2+FEl uKpQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=FLYSDCWXwnv7MBvU9SOBytJXsj9egOascOCu9xKIv6s=; b=LeNf9pfEcgZjSgv4/f9khSvkkPSv5GFwZk2XwEjr/6a6Be1iyY3Xp+GsXH7+3ycAdW dfswO3NNE4vlXIlMc0Kc4nEMQRAZk3kB3fCElL3cjjyhHXM4dHhWJ4ha4LPe5rDh61F2 jsifL1FvC/QIUudkwiVohFchewsj4593oId/oiUCC10ynsFP51QBJm+FeM9NXjbykMIZ mi/XNpjJtSBUz4Frfyuqn0Jr+BPst+lu6nCGMYJYLLpvs1fd+lf+q6KWfrovn6qKMIcP m9+5V1rPwnmJHAC+Wah3SMd8LmFn007Arqio7GeTbfYiYIxexufe+eeppCKzMjiQzJgE DZ0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=FLYSDCWXwnv7MBvU9SOBytJXsj9egOascOCu9xKIv6s=; b=G+0jyjCszZXVCfNSjO64Y1CXXgyf8/7Qu8i/kHygx+Dxgglf+C4gX0bjY6v8Fsebj1 86hbdKrokxiygF5IA4s6fNu/w9sLq8aAqLCCpN/b1IYACj+OfIJcwAP+gUOl9aDa5k2J 1uP/N2g8IpGIqXhmgkGFaIgYTMu/OU/CtzsKfAO9ZuJ/0/ZG7OBNTgl20y5JKJX6wkbq vc1nuPK6VDJdu065peFjpNvbrS5x8asuDKrWk2+oMZvHgHrFUNc8hNWU+HBFaGWIKRcM i3/0o/knftVO53279zL7aFcogl5SjmcDwYEgwnI4qt9EYcBJIHGHHA9/hhyGEkneZUdG IPNQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxytfwVtGgEs7aRgpb540YM+tCj0bXlIbiAjp8Eu4WSZ0ywYkAud3+ vO/AhyfpwCb7sadPKqCbzfg= X-Google-Smtp-Source: ACJfBosDbnH+efx4YhUie8Qmr30qh9n2p2zFPULcxz+vzE8LDhP2oqdEvOndM5MMxanL/YnhnVRffA== X-Received: by 10.28.197.195 with SMTP id v186mr35066wmf.6.1516199770311; Wed, 17 Jan 2018 06:36:10 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.223.146.66 with SMTP id 60ls1699700wrj.9.gmail; Wed, 17 Jan 2018 06:36:09 -0800 (PST) X-Received: by 10.28.101.86 with SMTP id z83mr290886wmb.31.1516199769721; Wed, 17 Jan 2018 06:36:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516199769; cv=none; d=google.com; s=arc-20160816; b=JG89jhpauu7kKwhExkYhDMjJneDm3ZUQ+oLSCtOUSyzDiYQODNR1/zbbC/GY/SSICF xiV4PUJoRZZo0v36gZBZ6EKrjd0KpLpajX1l1893Z7TnfvwpQwguAQJdLizUHno+kWmP Xc1yYGR9gszrBf9GpeyDbWN8/5Z1TZlC0N9Eu6dp/jFw2xEtukzlWuQonlGa3xJn5SCv lKqB1KY9yjP5pIE84JY7gUewtqSuN+ewygApzPPgWY3+l7mHCut6Ayhp3DH21gIClf+u 49scnhIrRdiIHhCa5LBEpWiWmwQd9jJm0hRLoD7evE2fJOSNWG9xdGbkuYL4aoNZOjs8 4UmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jXAhyAWJEaVGAI0yyJ8gPyMidGVYyTgXNv8v065crVo=; b=NcPlGP8KeAJqTEsS3x6TBG+mYidhQo/6LFvd/qhh5qyyyjt70fpiQ7dp+znO+FWFDO h4T8qahaDU3G7gHWc4QfYwsB2tEeXqsIZg9ZJXNl9DJDMsQWOZ4532SVtmuR/+m0/hax NmIkO8SdDRSV8YDUJG1Zdks5mM2gN+qT5Qe/xfW4U6T/UI7YqrknMz37T6jIaxPHGlRY eT0Wmr/0wWflF5x5zvorawhT8L4QwVKO+FEoH7uxGWaBbSKlSnIzVV+bGQEyMXNO7pLm 1QvWJ8xdwQTbOPdJWZb2OoMOXrkvgIpKqik20uTvZ2JKsfJQg4etsV2cMN2mBNK2oyQK znVw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net Received: from dd41138.kasserver.com (dd41138.kasserver.com. [85.13.157.12]) by gmr-mx.google.com with ESMTPS id v10si647190wrv.5.2018.01.17.06.36.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 06:36:09 -0800 (PST) Received-SPF: neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) client-ip=85.13.157.12; Received: from WS08941.weidmueller.com (unknown [217.244.7.16]) by dd41138.kasserver.com (Postfix) with ESMTPSA id 53C2311A0698; Wed, 17 Jan 2018 15:36:09 +0100 (CET) From: stefan@herbrechtsmeier.net To: swupdate@googlegroups.com Cc: Stefan Herbrechtsmeier Subject: [swupdate] [PATCH v2 4/5] Lua: Dump tables in Lua stack recursive Date: Wed, 17 Jan 2018 15:34:05 +0100 Message-Id: <1516199646-5607-4-git-send-email-stefan@herbrechtsmeier.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516199646-5607-1-git-send-email-stefan@herbrechtsmeier.net> References: <1516199646-5607-1-git-send-email-stefan@herbrechtsmeier.net> X-Original-Sender: stefan@herbrechtsmeier.net X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , From: Stefan Herbrechtsmeier Signed-off-by: Stefan Herbrechtsmeier --- Changes in v3: - Replace -1 by ENOMEM_ASPRINTF define - Move declarations into the required blocks Changes in v2: None corelib/lua_interface.c | 89 +++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 36 deletions(-) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index b617f61..6b92cf0 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -61,6 +61,52 @@ static bool is_type(lua_State *L, uintptr_t type) } #endif +static void lua_dump_table(lua_State *L, char *str) +{ + /* Stack: table, ... */ + lua_pushnil(L); + /* Stack: nil, table, ... */ + while (lua_next(L, -2)) { + /* Stack: value, key, table, ... */ + lua_pushvalue(L, -2); + /* Stack: key, value, key, table, ... */ + switch(lua_type(L, -2)) { + case LUA_TSTRING: + case LUA_TNUMBER: + TRACE("%s %s = %s", str, + lua_tostring(L, -1), + lua_tostring(L, -2)); + break; + case LUA_TFUNCTION: + TRACE("%s %s()", str, + lua_tostring(L, -1)); + break; + case LUA_TTABLE: { + char *s; + + if (asprintf(&s, "%s %s:", str, lua_tostring(L, -1)) != ENOMEM_ASPRINTF) { + lua_pushvalue(L, -2); + lua_dump_table(L, s); + lua_pop(L, 1); + free(s); + } + break; + } + case LUA_TBOOLEAN: + TRACE("%s %s = %s", str, + lua_tostring(L, -1), + (lua_toboolean(L, -2) ? "true" : "false")); + break; + default: + TRACE("%s %s = ", str, + lua_tostring(L, -1)); + } + lua_pop(L, 2); + /* Stack: key, table, ... */ + } + /* Stack: table, ... */ +} + void LUAstackDump(lua_State *L) { int top = lua_gettop(L); @@ -84,43 +130,14 @@ void LUAstackDump(lua_State *L) break; } case LUA_TTABLE: { - lua_pushvalue(L, -1); - lua_pushnil(L); - /* Stack: nil, table */ - while (lua_next(L, -2)) { - /* Stack: value, key, table */ - lua_pushvalue(L, -2); - /* Stack: key, value, key, table */ - switch(lua_type(L, -2)) { - case LUA_TSTRING: - case LUA_TNUMBER: - TRACE("(%d) [table ] %s = %s", i, - lua_tostring(L, -1), - lua_tostring(L, -2)); - break; - case LUA_TFUNCTION: - TRACE("(%d) [table ] %s()", i, - lua_tostring(L, -1)); - break; - case LUA_TTABLE: - TRACE("(%d) [table ] %s ", i, - lua_tostring(L, -1)); - break; - case LUA_TBOOLEAN: - TRACE("(%d) [table ] %s = %s", i, - lua_tostring(L, -1), - (lua_toboolean(L, -2) ? "true" : "false")); - break; - default: - TRACE("(%d) [table ] %s = ", i, - lua_tostring(L, -1)); - } - lua_pop(L, 2); - /* Stack: key, table */ + char *s; + + if (asprintf(&s, "(%d) [table ]", i) != ENOMEM_ASPRINTF) { + lua_pushvalue(L, -1); + lua_dump_table(L, s); + lua_pop(L, 1); + free(s); } - /* Stack: table */ - lua_pop(L, 1); - /* Stack: */ break; } default: {