-
Notifications
You must be signed in to change notification settings - Fork 28
Support nested definitions and fields with capitals #5
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution.
I haven't touched lua-protobuf in years, so it is an effort for me to remember how this all works. And when I say "this all" I literally mean both Lua and Protocol Buffers, as I haven't used either in years.
I found some style issues with your PR but haven't really fully digested the content changes yet because I need to find time to page this back into my brain. So consider this a partial review.
If anyone else is watching and wants to help with the meat of the review, I'd appreciate the help! Be warned: if you sound too competent I may ask you to become a project maintainer ;)
@@ -183,10 +186,10 @@ def package_function_prefix(package): | |||
def message_function_prefix(package, message): | |||
return '%s%s_' % (package_function_prefix(package), message) | |||
|
|||
def message_open_function_name(package, message): | |||
def message_open_function_name(package, message, namespace=[]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using []
as a default value is one of the most common Python gotchas. See http://docs.python-guide.org/en/latest/writing/gotchas/#mutable-default-arguments for more.
The correct way to write this is:
def func(namespace=None):
namespace = namespace or []
or
def func(namespace=None):
if namespace is None:
namespace = []
lines.append('string s = m->%s();' % name) | ||
lines.append('m->has_%s() ? lua_pushlstring(L, s.c_str(), s.size()) : lua_pushnil(L);' % name) | ||
lines.append('string s = m->%s();' % name.lower()) | ||
lines.append('if (m->has_%s()) lua_pushlstring(L, s.c_str(), s.size()); else lua_pushnil(L);' % name.lower()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Please don't make unrelated changed to code structure in the same commit as a substantive change, as this makes it more difficult to perform code review and to bisect failures later. Please revert back to the ternary operator or move this to its own commit.
Also, is if (expr) statement; else statement;
valid syntax?! I don't think I've ever seen that. I don't like blocks without { ... }
because of things like the infamous "goto fail" bug. So if you are going to change this, please use common syntax.
@@ -718,14 +721,14 @@ def message_function_array(package, message): | |||
'};\n', | |||
] | |||
|
|||
def message_method_array(package, descriptor): | |||
def message_method_array(package, descriptor, namespace=[]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another instance of a mutable default argument.
@@ -785,10 +788,10 @@ def message_open_function(package, descriptor): | |||
|
|||
return lines | |||
|
|||
def message_header(package, message_descriptor): | |||
def message_header(package, message_descriptor, namespace=[]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And another. (This will be the last time I mention it.)
@@ -999,7 +1012,7 @@ def file_header(file_descriptor): | |||
lines.extend(c_header_header(filename, package)) | |||
|
|||
for descriptor in file_descriptor.message_type: | |||
lines.extend(message_header(package, descriptor)) | |||
lines += message_header_recursive(package, descriptor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this back to lines.extend()
, as I have a personal bias against the +=
operator because it often doesn't do what you intended and can mask bugs.
|
||
nested_namespace = namespace + [descriptor.name] | ||
for nested in descriptor.nested_type: | ||
lines += enum_source_recursive(nested, nested_namespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use lines.extend()
.
This PR expands lua-protobuf to support: