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

how to use #220

Open
ghost opened this issue Oct 5, 2022 · 1 comment
Open

how to use #220

ghost opened this issue Oct 5, 2022 · 1 comment
Labels

Comments

@ghost
Copy link

ghost commented Oct 5, 2022

I have a proto file in directory proto/:
proto/order.proto

I want to use this proto file.

how can I do this?

Could someone give me a full, working and self-contained example how to do this?

local pb = require "pb"
local pbio   = require "pb.io"
local protoc = require "protoc"

pbio.dump("abc.proto", [[
  syntax = "proto3";

package abc;

message Msg {
  int32 id = 1;
}]])

assert(protoc.new():loadfile("abc.proto"))

local data = {
  id = 0
}

local chunk, other_result = pb.encode("Msg", data)

result:

 % lua test.lua
lua: test.lua:20: bad argument #1 to 'encode' (type 'Msg' does not exists)
stack traceback:
        [C]: in function 'pb.encode'
        test.lua:20: in main chunk
        [C]: in ?

what am I doing wrong?

@ausk
Copy link

ausk commented Oct 31, 2022

try to add package prefix : pb.encode("abc.Msg", data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants