@@ -66,16 +66,33 @@ epicsShareFunc std::string luaMacrosFromTable(lua_State* state, int index);
6666 *
6767 * The native field_type values from dbFldTypes.h conflict with the
6868 * DBF_* macros from db_access.h (included by cadef.h) -- they use
69- * different numeric values for the same names. These constants and
70- * the dbf_to_lua_type mapping resolve this by using the known numeric
71- * values from dbFldTypes.h directly.
69+ * different numeric values for the same names. These DB_DBR_*
70+ * constants use the dbFldTypes.h numbering for dbGetField/dbPutField.
71+ *
72+ * Base 7.0 inserted INT64/UINT64 at positions 7-8, shifting
73+ * FLOAT/DOUBLE/ENUM by 2 relative to 3.15.
74+ *
75+ * dbFldTypes.h enum (3.15):
76+ * 0=STRING, 1=CHAR, 2=UCHAR, 3=SHORT, 4=USHORT,
77+ * 5=LONG, 6=ULONG, 7=FLOAT, 8=DOUBLE, 9=ENUM,
78+ * 10=MENU, 11=DEVICE
79+ *
80+ * dbFldTypes.h enum (7.0+):
81+ * 0=STRING, 1=CHAR, 2=UCHAR, 3=SHORT, 4=USHORT,
82+ * 5=LONG, 6=ULONG, 7=INT64, 8=UINT64, 9=FLOAT,
83+ * 10=DOUBLE, 11=ENUM, 12=MENU, 13=DEVICE
7284 */
7385
74- /* Database-side DBR request type values from dbFldTypes.h */
86+ /* Database-side request type values from dbFldTypes.h */
7587#define DB_DBR_STRING 0
7688#define DB_DBR_CHAR 1
7789#define DB_DBR_LONG 5
90+
91+ #if EPICS_VERSION_INT >= VERSION_INT(7, 0, 0, 0)
7892#define DB_DBR_DOUBLE 10
93+ #else
94+ #define DB_DBR_DOUBLE 8
95+ #endif
7996
8097enum db_lua_type {
8198 DB_LUA_STRING ,
@@ -88,25 +105,27 @@ enum db_lua_type {
88105
89106/*
90107 * Map the native database field_type (dbFldTypes.h enum values)
91- * to a Lua type category.
92- *
93- * dbFldTypes.h enum:
94- * 0=STRING, 1=CHAR, 2=UCHAR, 3=SHORT, 4=USHORT,
95- * 5=LONG, 6=ULONG, 7=INT64, 8=UINT64, 9=FLOAT,
96- * 10=DOUBLE, 11=ENUM, 12=MENU, 13=DEVICE
108+ * to a Lua type category. Version-guarded for the INT64/UINT64
109+ * shift between base 3.15 and 7.0.
97110 */
98111static inline enum db_lua_type dbf_to_lua_type (short field_type)
99112{
100113 switch (field_type)
101114 {
102- case 0 : return DB_LUA_STRING ;
103- case 1 : case 2 : return DB_LUA_CHAR ;
104- case 3 : case 4 : return DB_LUA_INTEGER ;
105- case 5 : case 6 : return DB_LUA_INTEGER ;
106- case 7 : case 8 : return DB_LUA_DOUBLE ;
107- case 9 : case 10 : return DB_LUA_DOUBLE ;
115+ case 0 : return DB_LUA_STRING ; /* STRING */
116+ case 1 : case 2 : return DB_LUA_CHAR ; /* CHAR, UCHAR */
117+ case 3 : case 4 : return DB_LUA_INTEGER ; /* SHORT, USHORT */
118+ case 5 : case 6 : return DB_LUA_INTEGER ; /* LONG, ULONG */
119+ #if EPICS_VERSION_INT >= VERSION_INT(7, 0, 0, 0)
120+ case 7 : case 8 : return DB_LUA_DOUBLE ; /* INT64, UINT64 */
121+ case 9 : case 10 : return DB_LUA_DOUBLE ; /* FLOAT, DOUBLE */
108122 case 11 : case 12 :
109- case 13 : return DB_LUA_ENUM ;
123+ case 13 : return DB_LUA_ENUM ; /* ENUM, MENU, DEVICE */
124+ #else
125+ case 7 : case 8 : return DB_LUA_DOUBLE ; /* FLOAT, DOUBLE */
126+ case 9 : case 10 :
127+ case 11 : return DB_LUA_ENUM ; /* ENUM, MENU, DEVICE */
128+ #endif
110129 default : return DB_LUA_UNKNOWN ;
111130 }
112131}
0 commit comments