add some lua library

This commit is contained in:
云风
2012-08-09 16:48:28 +08:00
parent d246152ca5
commit 4e50079706
47 changed files with 13562 additions and 0 deletions

30
lua-protobuf/test.lua Normal file
View File

@@ -0,0 +1,30 @@
require "protobuf"
addr = io.open("addressbook.pb","rb")
buffer = addr:read "*a"
addr:close()
protobuf.register(buffer)
addressbook = {
name = "Alice",
id = 12345,
phone = {
{ number = "1301234567" },
{ number = "87654321", type = "WORK" },
}
}
code = protobuf.encode("tutorial.Person", addressbook)
decode = protobuf.decode("tutorial.Person" , code)
print(decode.name)
print(decode.id)
for _,v in ipairs(decode.phone) do
print("\t"..v.number, v.type)
end
phonebuf = protobuf.pack("tutorial.Person.PhoneNumber number","87654321")
buffer = protobuf.pack("tutorial.Person name id phone", "Alice", 123, { phonebuf })
print(protobuf.unpack("tutorial.Person name id phone", buffer))