mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
generate-wire.py: add enum->name function.
Pretty! Takes an int instead of the enum directly, because in the main daemon we call it via a function pointer, so want them all the same type. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
54cfbfeba9
commit
8ad1298f88
1 changed files with 12 additions and 0 deletions
|
@ -287,6 +287,7 @@ if options.output_header:
|
||||||
else:
|
else:
|
||||||
print('#include <{}>\n'
|
print('#include <{}>\n'
|
||||||
'#include <ccan/mem/mem.h>\n'
|
'#include <ccan/mem/mem.h>\n'
|
||||||
|
'#include <ccan/tal/str/str.h>\n'
|
||||||
''.format(args[0]))
|
''.format(args[0]))
|
||||||
|
|
||||||
# Maps message names to messages
|
# Maps message names to messages
|
||||||
|
@ -325,6 +326,17 @@ if options.output_header:
|
||||||
print('\t/*{} */'.format(c))
|
print('\t/*{} */'.format(c))
|
||||||
print('\t{} = {},'.format(m.enum.name, m.enum.value))
|
print('\t{} = {},'.format(m.enum.name, m.enum.value))
|
||||||
print('};')
|
print('};')
|
||||||
|
print('const char *{}_name(int e);'.format(args[1]))
|
||||||
|
else:
|
||||||
|
print('const char *{}_name(int e)'.format(args[1]))
|
||||||
|
print('{{\n'
|
||||||
|
'\tswitch ((enum {})e) {{'.format(args[1]));
|
||||||
|
for m in messages:
|
||||||
|
print('\tcase {0}: return "{0}";'.format(m.enum.name))
|
||||||
|
print('\t}\n'
|
||||||
|
'\treturn tal_fmt(NULL, "**INVALID** %i", e);\n'
|
||||||
|
'}\n'
|
||||||
|
'')
|
||||||
|
|
||||||
for m in messages:
|
for m in messages:
|
||||||
m.print_fromwire(options.output_header)
|
m.print_fromwire(options.output_header)
|
||||||
|
|
Loading…
Add table
Reference in a new issue