diff mbox series

[OpenWrt-Devel,1/1] ubus/lua: add support for BLOBMSG_TYPE_DOUBLE

Message ID 20180821104306.29364-2-marcus.comstedt@qamcom.se
State Accepted
Delegated to: John Crispin
Headers show
Series ubus/lua: add support for BLOBMSG_TYPE_DOUBLE | expand

Commit Message

marcus.comstedt@qamcom.se Aug. 21, 2018, 10:43 a.m. UTC
From: Marcus Comstedt <marcus@mc.pp.se>

Signed-off-by: Marcus Comstedt <marcus@mc.pp.se>
---
 lua/ubus.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/lua/ubus.c b/lua/ubus.c
index 00d9e00..4da3c80 100644
--- a/lua/ubus.c
+++ b/lua/ubus.c
@@ -111,6 +111,17 @@  ubus_lua_parse_blob(lua_State *L, struct blob_attr *attr, bool table)
 		lua_pushnumber(L, (double) be64_to_cpu(*(uint64_t *)data));
 		break;
 
+	case BLOBMSG_TYPE_DOUBLE:
+		{
+			union {
+				double d;
+				uint64_t u64;
+			} v;
+			v.u64 = be64_to_cpu(*(uint64_t *)data);
+			lua_pushnumber(L, v.d);
+		}
+		break;
+
 	case BLOBMSG_TYPE_STRING:
 		lua_pushstring(L, data);
 		break;
@@ -982,6 +993,8 @@  luaopen_ubus(lua_State *L)
 	lua_setfield(L, -2, "INT16");
 	lua_pushinteger(L, BLOBMSG_TYPE_INT8);
 	lua_setfield(L, -2, "INT8");
+	lua_pushinteger(L, BLOBMSG_TYPE_DOUBLE);
+	lua_setfield(L, -2, "DOUBLE");
 	lua_pushinteger(L, BLOBMSG_TYPE_BOOL);
 	lua_setfield(L, -2, "BOOLEAN");