Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add constants #997

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions rostsd_gen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,21 @@ function saveMsgConstructorAsTSD(rosMsgInterface, fd) {
const type = rosMsgInterface.type();
const msgName = type.interfaceName;

fs.writeSync(fd, ` export interface ${msgName}Constants {\n`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be enum here?

for (const constant of rosMsgInterface.ROSMessageDef.constants) {
if(primitiveType2JSName(constant.type) === "string"){
fs.writeSync(fd, ` ${constant.name} = "${constant.value}",\n`);
} else {
fs.writeSync(fd, ` ${constant.name} = ${constant.value},\n`);
}
}
fs.writeSync(fd, ' }\n');


fs.writeSync(fd, ` export interface ${msgName}Constructor {\n`);

for (const constant of rosMsgInterface.ROSMessageDef.constants) {
const constantType = primitiveType2JSName(constant.type);
fs.writeSync(fd, ` readonly ${constant.name}: ${constantType};\n`);
s.writeSync(fd, ` readonly ${constant.name}: ${msgName}Constants.${constant.name};\n`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=>fs.writeSync

}

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