Skip to content

Commit 9a57776

Browse files
author
Dimitri Nikitopoulos
committed
fix: push constants
1 parent 1db8ad6 commit 9a57776

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

rostsd_gen/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,21 @@ function saveMsgConstructorAsTSD(rosMsgInterface, fd) {
303303
const type = rosMsgInterface.type();
304304
const msgName = type.interfaceName;
305305

306+
fs.writeSync(fd, ` export interface ${msgName}Constants {\n`);
307+
for (const constant of rosMsgInterface.ROSMessageDef.constants) {
308+
if(primitiveType2JSName(constant.type) === "string"){
309+
fs.writeSync(fd, ` ${constant.name} = "${constant.value}";\n`);
310+
} else {
311+
fs.writeSync(fd, ` ${constant.name} = ${constant.value};\n`);
312+
}
313+
}
314+
fs.writeSync(fd, ' }\n');
315+
316+
306317
fs.writeSync(fd, ` export interface ${msgName}Constructor {\n`);
307318

308319
for (const constant of rosMsgInterface.ROSMessageDef.constants) {
309-
const constantType = primitiveType2JSName(constant.type);
310-
fs.writeSync(fd, ` readonly ${constant.name}: ${constantType};\n`);
320+
s.writeSync(fd, ` readonly ${constant.name}: ${msgName}Constants.${constant.name};\n`);
311321
}
312322

313323
fs.writeSync(fd, ` new(other?: ${msgName}): ${msgName};\n`);

0 commit comments

Comments
 (0)