Lua: Add image properties to table

Message ID 1515408301-31416-1-git-send-email-stefan@herbrechtsmeier.net
State Changes Requested
Headers show
Series
  • Lua: Add image properties to table
Related show

Commit Message

Stefan Herbrechtsmeier Jan. 8, 2018, 10:45 a.m.
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---
 corelib/lua_interface.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index f873aac..3ed3d4d 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -420,6 +420,8 @@  static int l_istream_read(lua_State* L)
 
 static void update_table(lua_State* L, struct img_type *img)
 {
+	struct dict_entry *property;
+
 	if (L && img) {
 		luaL_checktype(L, -1, LUA_TTABLE);
 
@@ -445,6 +447,15 @@  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) {
+			lua_pushstring(L, property->varname);
+			lua_pushstring(L, property->value);
+			lua_settable(L, -3);
+		}
+		lua_settable(L, -3);
+
 #ifdef CONFIG_HANDLER_IN_LUA
 		if (is_type(L, LUA_TYPE_HANDLER)) {
 			lua_pushstring(L, "copy2file");