From patchwork Thu May 10 08:52:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 911314 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:4010:c07::23a; helo=mail-lf0-x23a.google.com; envelope-from=swupdate+bncbcxploxj6ikrbruq2dlqkgqeaxuk3xq@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="psOfXZF6"; dkim-atps=neutral Received: from mail-lf0-x23a.google.com (mail-lf0-x23a.google.com [IPv6:2a00:1450:4010:c07::23a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40hRn623VVz9s3Z for ; Thu, 10 May 2018 18:52:26 +1000 (AEST) Received: by mail-lf0-x23a.google.com with SMTP id b5-v6sf556383lff.3 for ; Thu, 10 May 2018 01:52:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1525942343; cv=pass; d=google.com; s=arc-20160816; b=TqR6+2I2LQ9c7Wp1QNyNrAtgqeNa/KS3IvyExGiuzDMgB7+tTR4iC4uagxbSHKiUZ7 BUb+N286eZDAbTghdYPk2WBIEBw6ciGImo1mO/0sx0/qMeiAvxLHV/CUoMrFin5/hU8l 52IN5Y3qe7kRehV+lLch/M9Pw7vaS/Q0eAtiXLD4f1YQDRVkLR7Os1/u83uBfzwN1r3M EKWAJZzMlU5MpU/1c4OdY9DCVm1CM9COSFBsOCSMacDYrRApb8hK1/+STk+qezM+Ph1j yNfN0Ce9KydyOuEpA0lFqSQmNDzlalJ0VFToZboMiXKiyv4qLoiGdqlFp0Zbfj3COW7R ecFw== 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:message-id:date:subject:cc:to:from :arc-authentication-results:arc-message-signature:mime-version :sender:dkim-signature:arc-authentication-results; bh=2sttYZCu9fctB8+aaopoirHEo+Iq3yANiCOSrwScp5A=; b=pbGuA5DTj+OSTDssvSDSRm7BSYmK4kIXfHq1a2Jb2h8akP9RZjvXZs6F1uuiGn8psJ Jgp0D7gax5CyHi4UMGjuq/2PikHRrSJoA4OT4iUWpgkgzxD/k/W+SDob4t2w8bxMuzQI GLCc/5Qu9SOBd04bg+ZsQ9VIWv6oN0uXxPW18Lpe55Yy1G0VtyGoKaa2ie2BSl+D/l7Z JBmgFAefcOirfaJR1e23Co0RQFtUPMWDSSIL9LDXdCUB6bnm82kyeqN53htVY8TO3XHI aJP4S6F0CxZJ5vAMe9wAt3PUP1t9oLDjvxSLX2ytTDJtBLhMWJsgXvTCu2pQ9pE0lS0/ 5mhA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de 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 :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=2sttYZCu9fctB8+aaopoirHEo+Iq3yANiCOSrwScp5A=; b=psOfXZF6Ya79tJ98vIvpTJSOe+Xu/F/VvTBSm7uH2X/1j1LMmkFo2M0NENUM7qsp0d mvQYuie3sC7cGruU2nXEMvCjzsqeJmRAYnMocH7X2+EF85vtWF6Lg0dLqg3PFFhj8yFz AXVrzEO7I/dSoae6w/Afwtq3R5nJZxNcvQB2tOXc35X3z3InCZwxKrLEOPznbT7UH7YM eu6SLyQb/fgBN5WOpjoJBAQoXB+ahipn/9+vgSVq7RpC40mz/rcMqVU5qBC54T1WC130 JCBLVcaVg6pXrk3xvkhjgQToUEgLZVfpQbriZHAHIh7KSNvnB8UxwlL7ePJi5C4IGGfi fPIQ== 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: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=2sttYZCu9fctB8+aaopoirHEo+Iq3yANiCOSrwScp5A=; b=tXbdDkptqgICt4aLL0rubN1y2vOKyTBhr3EKhegyKl+uygLmvvDx5Jpkf5WafCDohf eBijqDrvYFbKvKUqsswGKsudBxEC+rLQm9YDKPRIAJiaUSzW//ZAAGj0vhYXdTslwvRT JG7cYHRMLOEbTxeBDX2PaV8eZa1ttSVZtv7npGphBrPjFPLQ8dfNqtkhsbZcmiU/MVLb Mtnt/OW61nmTUwBxW6NZhdmqCQTeB8TcsdoWF2OFaczDZS9jjFB2rWUIMN6tmTLS8NQn DvR98IoiYZb9HrpnzkWi2bp5ksnL9J17si3CMebXs1eRkyTp+8OHjIymFdj8foVNYpsZ XhVQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: ALKqPwdHtbUhoJxIbYv27eym8oyL0VD0hftmU0HvuReTKfS2pC8N9mSS muXHkkVc3IaEpEUUAN5NkqQ= X-Google-Smtp-Source: AB8JxZp2g/E1j5cgt/BKuHhs300PYaVj09N7z9QwsitWWG6aNVxesYIC5SQfSmbdQ66J8PUtM3kKLQ== X-Received: by 2002:a19:a643:: with SMTP id p64-v6mr1857lfe.13.1525942342957; Thu, 10 May 2018 01:52:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a2e:868c:: with SMTP id l12-v6ls754976lji.4.gmail; Thu, 10 May 2018 01:52:22 -0700 (PDT) X-Received: by 2002:a2e:980a:: with SMTP id a10-v6mr29088ljj.26.1525942342303; Thu, 10 May 2018 01:52:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525942342; cv=none; d=google.com; s=arc-20160816; b=PT3Wv6lQXEHqI7t+GTlINJK3IfZNg7Ez+Xj+OXG2/RCtbp2QzPHYUTVttbnRok5Ap/ 6H3PJpqrJPAXyy29XL2/DhALpLTdfkOTNlyUOTv6XVoQyvRgSzSkt5bQcHifkjV+gnqT 3j5bNXUFf1Usuvc7caz0fKu7hX0DD0Ex59qXBVJf3LKhHARanBUyOzn2RF1bZ+UkVhZ2 b00xvxYUuEzAEYIrfZtm2I/lzeSrYHIIyrMAX2cFABdQskQP1aHpXVQ94z52UAWH32ae xEK5+iVk6QSJSNZo9jR7PzzQzRRNT5leNIIm8FmGUW+AMNsO+wssfxEaT9sn1pbzU8CB ED9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=INLWTeKEiSeZTxYhy4JJ+rkVzlx4qOKKQ5lljUKyeQQ=; b=WZbi9UxKjl5/MS9EEvG5UywdWWJ0Y1Q4M1NYuL2PO1xUYCjrltt8I8GPr7v6JXC0Y6 H2qVLTF36MaGB3F0m68gIiXY4XwhxSeIXKbkUaghBaVCyQQ2IJfZPajKz/kqZgh6g3U6 tvSvD4mvTutCYbqfT9zjNYWla9vpzrayPH4dMuDuOLvJWlloBpZS/+pbdZxja0XVfItd 7vFu+J63VjKxSdydrDjgw8TxKbfx6v3SZopo/ik4UPKbgUl+Il/eycmfOmeFpn+I6mk6 MRcHo+0C+0I9ST1vItNwO7kcAbIGf9dHCog2UWDPN7Jy09n3lVmdpHUbXLkhTaJCEMBq KRBQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id v13-v6si14341lji.0.2018.05.10.01.52.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 May 2018 01:52:22 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 40hRn14jc3z1qwCZ; Thu, 10 May 2018 10:52:21 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 40hRn14cM8z1qrg4; Thu, 10 May 2018 10:52:21 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id SzKPhT0bZSoT; Thu, 10 May 2018 10:52:20 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Thu, 10 May 2018 10:52:20 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 603654540325; Thu, 10 May 2018 10:52:20 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5hYUetQ9CpYg; Thu, 10 May 2018 10:52:17 +0200 (CEST) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id C658F4540060; Thu, 10 May 2018 10:52:17 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH] lua: allow scripts to change image's properties Date: Thu, 10 May 2018 10:52:16 +0200 Message-Id: <1525942336-17370-1-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de 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: , The properties list is already passed to Lua, but it is not retrieved when the script returns. Parsed the properties table after a script returns and allows that a script can add new properties as well. Signed-off-by: Stefano Babic --- corelib/lua_interface.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index c4d29c6..6104e06 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -64,7 +64,7 @@ static bool is_type(lua_State *L, uintptr_t type) } #endif -static void lua_dump_table(lua_State *L, char *str) +static void lua_dump_table(lua_State *L, char *str, struct img_type *img, const char *key) { /* Stack: table, ... */ lua_pushnil(L); @@ -79,6 +79,14 @@ static void lua_dump_table(lua_State *L, char *str) TRACE("%s %s = %s", str, lua_tostring(L, -1), lua_tostring(L, -2)); + if (img) { + TRACE("Inserting property %s[%s] = %s\n", + key, + lua_tostring(L, -1), + lua_tostring(L, -2)); + dict_insert_value(&img->properties, key, + lua_tostring(L, -2)); + } break; case LUA_TFUNCTION: TRACE("%s %s()", str, @@ -86,19 +94,29 @@ static void lua_dump_table(lua_State *L, char *str) break; case LUA_TTABLE: { char *s; + char *propkey; - if (asprintf(&s, "%s %s:", str, lua_tostring(L, -1)) != ENOMEM_ASPRINTF) { + if (asprintf(&propkey, "%s", lua_tostring(L, -1)) == ENOMEM_ASPRINTF) { + TRACE("Out of memory, dump stopped"); + break; + } + + if (asprintf(&s, "%s %s:", str, propkey) != ENOMEM_ASPRINTF) { lua_pushvalue(L, -2); - lua_dump_table(L, s); + lua_dump_table(L, s, img, propkey); lua_pop(L, 1); free(s); } + free(propkey); break; } case LUA_TBOOLEAN: TRACE("%s %s = %s", str, lua_tostring(L, -1), (lua_toboolean(L, -2) ? "true" : "false")); + if (img) + dict_insert_value(&img->properties, str, + (lua_toboolean(L, -2) ? "true" : "false")); break; default: TRACE("%s %s = ", str, @@ -137,7 +155,7 @@ void LUAstackDump(lua_State *L) if (asprintf(&s, "(%d) [table ]", i) != ENOMEM_ASPRINTF) { lua_pushvalue(L, -1); - lua_dump_table(L, s); + lua_dump_table(L, s, NULL, NULL); lua_pop(L, 1); free(s); } @@ -577,6 +595,14 @@ static void table2image(lua_State* L, struct img_type *img) { case LUA_TNUMBER: /* numbers */ lua_number_to_img(img, lua_tostring(L, -2), lua_tonumber(L, -1)); break; + case LUA_TTABLE: + if (!strcmp (lua_tostring(L, -2), "properties")) { + dict_drop_db(&img->properties); + lua_pushvalue(L, -1); + lua_dump_table(L, (char*)"properties", img, NULL); + lua_pop(L, 1); + } + break; } lua_pop(L, 1); }