OpenWrt‎ > ‎LuCI‎ > ‎

lububus-lua

I have done a bit of work with the luci lua interface to ubus and I have found the following issues
The libubus-lua library does the following with the ubus types
NOTE: Usually the only digit type in Lua is "number" which is represented as a double float, some lua versions do support integers

 Ubus method Ubus Object Type Lua Type Comments
 blobmesg_add_u8() BLOBMSG_TYPE_INT8 Booleanfalse if 0, otherwise true 
 blobmesg_add_u16() BLOBMSG_TYPE_INT16 Integeror number if integer is not supported 
 blobmesg_add_u32() BLOBMSG_TYPE_INT32 Integer or number if integer is not supported 
 blobmesg_add_u64() BLOBMSG_TYPE_INT64 Number The IN64 type is treated as if it was a double
 blobmesg_add_string() BLOBMSG_TYPE_STRING String 
 blobmesg_add_double() BLOBMSG_TYPE_DOUBLE nil Surprisingly this is not supported
    

When converting back Lua values are mapped as shown below:
NOTE: there is no double returned.
In my view it would have been better to return numbers as doubles

 Lua Type Ubus Object type Comments
 Number BLOBMSG_TYPE_INT32 Although most number are stored a double floats in Lua they are returned as as in integer in BLOBMSG_TYPE_INT32.  This means that they are rounded in an unpredictable manner
 String BLOBMSG_TYPE_STRING 
 Boolean BLOBMSG_TYPE_INT8 true => 1, false => 0
   

Since the library only allows me to pass floats via INT64, and I can't return them, and I can't modify the library without breaking other utilities that rely on its "broken" and missing functionality
I have decided to pass all numbers and  strings,  as strings and then do the conversion to numbers in the receiving system.  This is convenient and reasonably straight forward in C with the ati and atof functions


Comments