Skip to content

Conversation

@gdb
Copy link

@gdb gdb commented Feb 24, 2017

This PR expands lua-protobuf to support:

  • Nested messages and enums
  • Fields with capital letters (the C++ protobuf library downcases them)

Copy link
Owner

@indygreg indygreg left a 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 ;)

return '%s%s_' % (package_function_prefix(package), message)

def message_open_function_name(package, message):
def message_open_function_name(package, message, namespace=[]):
Copy link
Owner

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())
Copy link
Owner

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.

]

def message_method_array(package, descriptor):
def message_method_array(package, descriptor, namespace=[]):
Copy link
Owner

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.

return lines

def message_header(package, message_descriptor):
def message_header(package, message_descriptor, namespace=[]):
Copy link
Owner

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.)


for descriptor in file_descriptor.message_type:
lines.extend(message_header(package, descriptor))
lines += message_header_recursive(package, descriptor)
Copy link
Owner

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)
Copy link
Owner

Choose a reason for hiding this comment

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

Please use lines.extend().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants