starwing / lua-protobuf

A Lua module to work with Google protobuf
MIT License
1.74k stars 387 forks source link

Name resolution is failing #268

Closed git-torrent closed 5 months ago

git-torrent commented 5 months ago

I have three files (in attachment) proto.zip

The example is for Windows (my workstation), but the same happens on Linux. Running the test.lua causes error:

Exception has occurred: ../Program Files (x86)/Lua/5.1/lua/protoc.lua:82: c:\proto\a\x.proto:13:3: unknown type 'b.Z

The same with protoc --cpp_out=. -I c:\proto c:\proto\a\x.proto does everything without any complaint.

According to https://protobuf.dev/programming-guides/proto3/#name-resolution the names should be resolved inside out. This seem to fail in protoc-lua. If I change the attribute to use definition fully qualified name, it works.

message X {
  Y y = 1; // local import
  something.else.b.Z z = 2; // import from other package
}

We do not use fully qualified names because of zero added value (visual noise) if the common part is enough for google tooling.

In lua protoc, is this a bug or a feature? Can it be fixed to behave according to spec?

Thank you

starwing commented 5 months ago

Have you tried the latest lua-protobuf? it works for me:

local protoc = require "protoc" -- protocol buffer compiler, similar to `pb` standing for `protocol buffers`

local p = protoc.new();

-- p.include_imports = true;
p:addpath( "" );
p:loadfile( "a/x.proto" );

print ( "loaded" );

produces:

$ lua  -- test.lua
loaded
git-torrent commented 5 months ago

Thank you, lua-protobuf-0.5.1-1 works perfectly