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

fix import other proto bug, without changing the xxx_pb variable #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lifelongchaser
Copy link

an error occurs when you want to use other message type from another proto file,

[string "protobuf.lua"]:363: attempt to index upvalue 'message_type' (a nil value)

e.g.
mail.proto:

    import "reward.proto";
    package mail;

    message Mail
    {
        optional uint32 id = 1;  
        optional reward.Reward reward = 2;
    }

reward.proto:

    package reward; 
    message Reward
    {
        optional uint32 money = 1;
    }

test.lua:

    -- sending --
    local sendMail = mail_pb.Mail()
    sendMail.id = 12
    local reward = sendMail.reward
    reward.money = 30
    printf(sendMail)

    -- receiving--
    local recvMail = mail_pb.Mail()
    recvMail:ParseFromString(sendMail:SerializeToString())
    printf(recvMail)

The same thing happens when using repeated instead of optional.

[string "containers.lua"]:27: attempt to call field '_concrete_class' (a nil value)

The reason is that mail_pb.lua generated by protoc-gen-lua doesn't consider the situation of other proto msg type. The message_type is nil.

some guy has fixed this bug by putting the REWARD table to XXX_pb variable. But I offer another method without changing XXX_pb.

you can choose whether is more fit considering your program structure.

Thank you for reading.

@kudoran
Copy link

kudoran commented May 24, 2017

This soluation leads to another bug. If there are a lot of messages or enums in proto file, it will create lots of local variables . More than 200 local variables in a chunk lead to lua error.

@mazexiang
Copy link

local player = player_pb.Player()
player.email="123456"
player.user.username = "mazexiang"
player.user.password="1004"

local msgdata = player:SerializeToString()
local msgplayer = player_pb.Player()
msgplayer:ParseFromString(msgdata)
print(msgplayer.user.username)

this is a example,and it work success

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.

None yet

4 participants