diff mbox series

[v2,5/5] Lua: Forward image properties via table to scripts

Message ID 1516199646-5607-5-git-send-email-stefan@herbrechtsmeier.net
State Accepted
Headers show
Series [v2,1/5] dict: Rename dictionary struct and its key to distinguish it from simple lists | expand

Commit Message

Stefan Herbrechtsmeier Jan. 17, 2018, 2:34 p.m. UTC
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---

Changes in v3:
- Move declarations into the required group

Changes in v2: None

 corelib/lua_interface.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Stefano Babic Jan. 19, 2018, 9:35 a.m. UTC | #1
On 17/01/2018 15:34, stefan@herbrechtsmeier.net wrote:
> From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> 
> Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> ---
> 


Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index 6b92cf0..25d84e6 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -429,6 +429,8 @@  static int l_istream_read(lua_State* L)
 static void update_table(lua_State* L, struct img_type *img)
 {
 	if (L && img) {
+		struct dict_entry *property;
+
 		luaL_checktype(L, -1, LUA_TTABLE);
 
 		LUA_PUSH_IMG_STRING(img, "name", id.name);
@@ -453,6 +455,28 @@  static void update_table(lua_State* L, struct img_type *img)
 		LUA_PUSH_IMG_NUMBER(img, "size", size);
 		LUA_PUSH_IMG_NUMBER(img, "checksum", checksum);
 
+		lua_pushstring(L, "properties");
+		lua_newtable (L);
+		LIST_FOREACH(property, &img->properties, next) {
+			struct dict_list_elem *elem = LIST_FIRST(&property->list);
+
+			lua_pushstring(L, dict_entry_get_key(property));
+			if (LIST_NEXT(elem, next) == LIST_END(&property->list)) {
+				lua_pushstring(L, elem->value);
+			} else {
+				int i = 1;
+
+				lua_newtable (L);
+				LIST_FOREACH(elem, &property->list, next) {
+					lua_pushnumber(L, i++);
+					lua_pushstring(L, elem->value);
+					lua_settable(L, -3);
+				}
+			}
+			lua_settable(L, -3);
+		}
+		lua_settable(L, -3);
+
 #ifdef CONFIG_HANDLER_IN_LUA
 		if (is_type(L, LUA_TYPE_HANDLER)) {
 			lua_pushstring(L, "copy2file");