Git Product home page Git Product logo

luapbintf's Introduction

LuaPbIntf

Lua Protobuf interface.

Binding Protobuf to Lua with lua-intf, supporting lua53 and proto3.

LuaPbIntf is inspired by luapb, but has been rewritten to take advantage of lua-intf, which makes the binding easier to use and easier to understand.

LuaPbIntf will dynamic load Protocol Buffer message definition files .proto without code generation.

LuaPbIntf use lua table to present Message, encode() to encode lua message table to string, and decode() to decode string to lua message table.

Differ from luapb

  • Support proto3
  • Support service
  • Able to set the proto path
  • luapb skips some types such as: TYPE_SFIXED32. See issue.

Build

Build with conan

  1. Install conan.
  2. Add conan repositories
    • conan remote add remote_bintray_bincrafters https://api.bintray.com/conan/bincrafters/public-conan
    • conan remote add remote_bintray_jinq0123 https://api.bintray.com/conan/jinq0123/test
  3. conan create . user/channel --build missing
    • The result luapbintf.dll/luapbintf.so is in ~/.conan/data/luapbintf/0.1/user/channel/package/...
    • Add build settings like: conan create user/channel --build missing -s arch=x86

Without conan (depricated)

Init third_party dir first, see third_party/README.md. Then use premake5 to generate VS2015 sln or Makefile to build. See premake/premake5.bat

On Windows, it is recommended by google that you use static protobuf only. On Linux, you may need to recompile libprotobuf.a with -fPIC, or link libprotobuf.so.

Link error

error LNK2019: unresolved external symbol "void __cdecl lua_settop(struct lua_State *,int)" (?lua_settop@@YAXPAUlua_State@@H@Z)

Please see issue #2.

By default, it expects the Lua library to build under C++. If you really want to use Lua library compiled under C, you can define LUAINTF_LINK_LUA_COMPILED_IN_CXX to 0.

Run test

See test/README.md

Example

Encode and Decode

local pb = require("luapbintf")

pb.import_proto_file("test.proto")

local msg = { uid = 12345 }
local sz = pb.encode("test.TestMsg", msg)

local msg2 = pb.decode("test.TestMsg", sz)
assert(msg2.uid == 12345)

Rpc

    assert(pb.get_rpc_input_name("test.Test", "Foo") == "test.TestMsg")
    assert(pb.get_rpc_output_name("test.Test", "Foo") == "test.CommonMsg")

Map field

local msgs = {}
msgs["k1"] = {}
msgs["k2"] = {}
pb.encode("test.TestMsg", { msgs = msgs })

Oneof field

    local msg = { msg2 = {} }
    local s = pb.encode("test.TestMsg", msg)
    local result = pb.decode("test.TestMsg", s)
    assert(result.name == "")
    assert(result.name2 == nil)
    assert(result.msg2)

Type Convertion

Number will be converted to string if necessary.

    local msg = { name = 12345 }
    local s = pb.encode("test.TestMsg", msg)
    assert(pb.decode("test.TestMsg", s).name == "12345")

Integer will be converted from one type to another. Such as from int64 4294967296 to int32 0:

    local msg = { n32 = 4294967296 + 123 }
    assert(msg.n32 == 4294967296 + 123)
    local s = pb.encode("test.TestMsg", msg)
    local msg2 = pb.decode("test.TestMsg", s)
    assert(msg2.n32 == 123)

String can be converted to integer or float:

    local msg = { d = "12345e-67" }
    local s = pb.encode("test.TestMsg", msg)
    assert(pb.decode("test.TestMsg", s).d == 12345e-67)

Can not convert float to integer.

> msg = { n32 = 1.1 }
> pb.encode("test.TestMsg", msg)
stdin:1: bad argument #-1 to 'encode' (number has no integer representation)

Enum is integer, but input string enum will be converted to integer.

    local msg = { cmd = "CMD_TYPE_CHECK" }
    local s = pb.encode("test.TestMsg", msg)
    assert(pb.decode("test.TestMsg", s).cmd == 2)

Repeated field is a lua array table and it is read from index 1 to len, ignoring others.

    local msg = { names = {"n1", "n2", "n3", [0] = "n1", [100] = "n100"} }
    local s = pb.encode("test.TestMsg", msg)
    local msg2 = pb.decode("test.TestMsg", s)
    assert(#msg2.names == 3)

Proto2 Extension

Proto2 extension is not supported, which is replaced by Any type in proto3.

Reference

See doc/reference.md.

Known Bugs

luapbintf's People

Contributors

jinq0123 avatar vkill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

luapbintf's Issues

您好,在lua协程中调用时出错了

您好,这个代码编译好so动态库,普通测试可以,但是在lua的协程中调用时,encode和decode就不生效了,请问造成这个的原因有哪些呢,测试了好久不知道原因,希望能够解答一下。

build error with conan

Hi,

I've followed the build instruction with conan https://github.com/jinq0123/LuaPbIntf#build-with-conan

But i got following error on ubuntu 16.04

.....
/root/.conan/data/lua-cpp/5.3.4/jinq0123/testing/build/f5a6882590d137de693642227ed35e8e26da3dac/lua-5.3.4/src/lua.h:437:1: note: in expansion of macro ‘LUA_API’
 LUA_API int (lua_gethookmask) (lua_State *L);
 ^
/root/.conan/data/lua-cpp/5.3.4/jinq0123/testing/build/f5a6882590d137de693642227ed35e8e26da3dac/lua-5.3.4/src/luaconf.h:247:27: error: expected constructor, destructor, or type conversion before ‘(’ token
 #define LUA_API __declspec(dllexport)
                           ^
/root/.conan/data/lua-cpp/5.3.4/jinq0123/testing/build/f5a6882590d137de693642227ed35e8e26da3dac/lua-5.3.4/src/lua.h:438:1: note: in expansion of macro ‘LUA_API’
 LUA_API int (lua_gethookcount) (lua_State *L);
 ^
CMakeFiles/lua-cpp.dir/build.make:62: recipe for target 'CMakeFiles/lua-cpp.dir/src/lgc.cpp.o' failed
make[2]: *** [CMakeFiles/lua-cpp.dir/src/lgc.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/lua-cpp.dir/all' failed
make[1]: *** [CMakeFiles/lua-cpp.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
lua-cpp/5.3.4@jinq0123/testing: 
lua-cpp/5.3.4@jinq0123/testing: ERROR: Package 'f5a6882590d137de693642227ed35e8e26da3dac' build failed
lua-cpp/5.3.4@jinq0123/testing: WARN: Build folder /root/.conan/data/lua-cpp/5.3.4/jinq0123/testing/build/f5a6882590d137de693642227ed35e8e26da3dac
ERROR: lua-cpp/5.3.4@jinq0123/testing: Error in build() method, line 32
        cmake.build()
        ConanException: Error 512 while executing cmake --build '/root/.conan/data/lua-cpp/5.3.4/jinq0123/testing/build/f5a6882590d137de693642227ed35e8e26da3dac' '--' '-j1'

This is my installed lua packages

root@vagrant:~/pbtara/LuaPbIntf# dpkg -l | grep lua                                                                                                                                                                                   
ii  liblua5.2-0:amd64                  5.2.4-1ubuntu1                             amd64        Shared library for the Lua interpreter version 5.2
ii  liblua5.3-0:amd64                  5.3.1-1ubuntu2                             amd64        Shared library for the Lua interpreter version 5.3
ii  liblua5.3-dev:amd64                5.3.1-1ubuntu2                             amd64        Development files for the Lua language version 5.3
ii  lua5.3                             5.3.1-1ubuntu2                             amd64        Simple, extensible, embeddable programming language
rc  luarocks                           2.2.0+dfsg-2                               all          deployment and management system for Lua modules

add to luarocks

would be great if this awesome lib could be added to luarocks

can you help me build error

1>------ 已启动生成: 项目: LuaPbIntf, 配置: Debug Win32 ------
1> 正在创建库 bin\Debug\luapbintf.lib 和对象 bin\Debug\luapbintf.exp
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "void __cdecl lua_settop(struct lua_State *,int)" (?lua_settop@@YAXPAUlua_State@@h@Z),该符号在函数 "public: void __thiscall LuaIntf::LuaRef::rawset<char const *,class LuaIntf::LuaRef>(char const * const &,class LuaIntf::LuaRef const &)" (??$rawset@PBDVLuaRef@LuaIntf@@@LuaRef@LuaIntf@@QAEXABQBDABV01@@z) 中被引用
1>LuaPbIntfImpl.obj : error LNK2001: 无法解析的外部符号 "void __cdecl lua_settop(struct lua_State *,int)" (?lua_settop@@YAXPAUlua_State@@h@Z)
1>MessageSetter.obj : error LNK2001: 无法解析的外部符号 "void __cdecl lua_settop(struct lua_State *,int)" (?lua_settop@@YAXPAUlua_State@@h@Z)
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "void __cdecl lua_settop(struct lua_State *,int)" (?lua_settop@@YAXPAUlua_State@@h@Z)
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "void __cdecl lua_pushvalue(struct lua_State *,int)" (?lua_pushvalue@@YAXPAUlua_State@@h@Z),该符号在函数 "public: __thiscall LuaIntf::LuaRef::LuaRef(struct lua_State *,int)" (??0LuaRef@LuaIntf@@QAE@PAUlua_State@@h@Z) 中被引用
1>MessageSetter.obj : error LNK2001: 无法解析的外部符号 "void __cdecl lua_pushvalue(struct lua_State *,int)" (?lua_pushvalue@@YAXPAUlua_State@@h@Z)
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "void __cdecl lua_pushvalue(struct lua_State *,int)" (?lua_pushvalue@@YAXPAUlua_State@@h@Z)
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "int __cdecl lua_isuserdata(struct lua_State ,int)" (?lua_isuserdata@@YAHPAUlua_State@@h@Z),该符号在函数 "public: static int __cdecl LuaIntf::CppBindMethodBase<0,void (__cdecl)(void),1,void>::call(struct lua_State *)" (?call@?$CppBindMethodBase@$0A@P6AXXZ$00X$$V@LuaIntf@@SAHPAUlua_State@@@z) 中被引用
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "int __cdecl lua_type(struct lua_State *,int)" (?lua_type@@YAHPAUlua_State@@h@Z),该符号在函数 "public: static class LuaIntf::LuaRef __cdecl LuaIntf::LuaTypeMapping<class LuaIntf::LuaRef,void>::get(struct lua_State *,int)" (?get@?$LuaTypeMapping@VLuaRef@LuaIntf@@x@LuaIntf@@sa?AVLuaRef@2@PAUlua_State@@h@Z) 中被引用
1>MessageSetter.obj : error LNK2001: 无法解析的外部符号 "int __cdecl lua_type(struct lua_State *,int)" (?lua_type@@YAHPAUlua_State@@h@Z)
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "int __cdecl lua_type(struct lua_State *,int)" (?lua_type@@YAHPAUlua_State@@h@Z)
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "void * __cdecl lua_touserdata(struct lua_State *,int)" (?lua_touserdata@@YAPAXPAUlua_State@@h@Z),该符号在函数 "private: static int __cdecl LuaIntf::LuaRef::destructUserData<class std::function<class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class std::basic_string<char,struct std::char_traits,class std::allocator > const &)> >(struct lua_State *)" (??$destructUserData@V?$function@$$A6A?AV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@ABV12@0@Z@std@@@LuaRef@LuaIntf@@CAHPAUlua_State@@@z) 中被引用
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "void __cdecl lua_pushnil(struct lua_State *)" (?lua_pushnil@@YAXPAUlua_State@@@z),该符号在函数 "public: static void __cdecl LuaIntf::LuaTypeMapping<class LuaIntf::LuaRef,void>::push(struct lua_State *,class LuaIntf::LuaRef const &)" (?push@?$LuaTypeMapping@VLuaRef@LuaIntf@@x@LuaIntf@@SAXPAUlua_State@@ABVLuaRef@2@@z) 中被引用
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "void __cdecl lua_pushnil(struct lua_State *)" (?lua_pushnil@@YAXPAUlua_State@@@z)
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "char const * __cdecl lua_pushlstring(struct lua_State *,char const *,unsigned int)" (?lua_pushlstring@@YAPBDPAUlua_State@@pbdi@Z),该符号在函数 "public: static void __cdecl LuaIntf::LuaTypeMapping<class std::basic_string<char,struct std::char_traits,class std::allocator >,void>::push(struct lua_State *,class std::basic_string<char,struct std::char_traits,class std::allocator > const &)" (?push@?$LuaTypeMapping@V?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@x@LuaIntf@@SAXPAUlua_State@@abv?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@@z) 中被引用
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "char const * __cdecl lua_pushlstring(struct lua_State *,char const *,unsigned int)" (?lua_pushlstring@@YAPBDPAUlua_State@@pbdi@Z)
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "char const * __cdecl lua_pushstring(struct lua_State *,char const *)" (?lua_pushstring@@YAPBDPAUlua_State@@pbd@Z),该符号在函数 "public: static void __cdecl LuaIntf::LuaTypeMapping<char const *,void>::push(struct lua_State *,char const *)" (?push@?$LuaTypeMapping@PBDX@LuaIntf@@SAXPAUlua_State@@pbd@Z) 中被引用
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "char const * __cdecl lua_pushstring(struct lua_State *,char const *)" (?lua_pushstring@@YAPBDPAUlua_State@@pbd@Z)
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "void __cdecl lua_pushcclosure(struct lua_State ,int (__cdecl)(struct lua_State ),int)" (?lua_pushcclosure@@YAXPAUlua_State@@P6AH0@ZH@Z),该符号在函数 "public: static class LuaIntf::LuaRef __cdecl LuaIntf::LuaRef::createFunction<void (__cdecl)(void)>(struct lua_State ,int (__cdecl)(struct lua_State ),void (__cdeclconst &)(void))" (??$createFunction@P6AXXZ@LuaRef@LuaIntf@@sa?AV01@PAUlua_State@@P6AH0@ZABQ6AXXZ@Z) 中被引用
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "int __cdecl lua_rawgeti(struct lua_State *,int,__int64)" (?lua_rawgeti@@YAHPAUlua_State@@H_J@Z),该符号在函数 "public: __thiscall LuaIntf::LuaRef::LuaRef(class LuaIntf::LuaRef const &)" (??0LuaRef@LuaIntf@@QAE@ABV01@@z) 中被引用
1>LuaPbIntfImpl.obj : error LNK2001: 无法解析的外部符号 "int __cdecl lua_rawgeti(struct lua_State *,int,__int64)" (?lua_rawgeti@@YAHPAUlua_State@@H_J@Z)
1>MessageSetter.obj : error LNK2001: 无法解析的外部符号 "int __cdecl lua_rawgeti(struct lua_State *,int,__int64)" (?lua_rawgeti@@YAHPAUlua_State@@H_J@Z)
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "int __cdecl lua_rawgeti(struct lua_State *,int,__int64)" (?lua_rawgeti@@YAHPAUlua_State@@H_J@Z)
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "void __cdecl lua_createtable(struct lua_State *,int,int)" (?lua_createtable@@YAXPAUlua_State@@hh@Z),该符号在函数 "private: static void __cdecl LuaIntf::LuaRef::pushUserDataFrom<class std::function<class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class std::basic_string<char,struct std::char_traits,class std::allocator > const &)> >(struct lua_State *,class std::function<class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class std::basic_string<char,struct std::char_traits,class std::allocator > const &)> const &)" (??$pushUserDataFrom@V?$function@$$A6A?AV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@ABV12@0@Z@std@@@LuaRef@LuaIntf@@CAXPAUlua_State@@abv?$function@$$A6A?AV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@ABV12@0@Z@std@@@z) 中被引用
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "void __cdecl lua_createtable(struct lua_State *,int,int)" (?lua_createtable@@YAXPAUlua_State@@hh@Z)
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "void * __cdecl lua_newuserdata(struct lua_State ,unsigned int)" (?lua_newuserdata@@YAPAXPAUlua_State@@i@Z),该符号在函数 "private: static void __cdecl LuaIntf::LuaRef::pushUserDataFrom<void (__cdecl)(void)>(struct lua_State ,void (__cdeclconst &)(void))" (??$pushUserDataFrom@P6AXXZ@LuaRef@LuaIntf@@CAXPAUlua_State@@ABQ6AXXZ@Z) 中被引用
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "void __cdecl lua_setfield(struct lua_State *,int,char const *)" (?lua_setfield@@YAXPAUlua_State@@hpbD@Z),该符号在函数 "private: static void __cdecl LuaIntf::LuaRef::pushUserDataFrom<class std::function<class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class std::basic_string<char,struct std::char_traits,class std::allocator > const &)> >(struct lua_State *,class std::function<class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class std::basic_string<char,struct std::char_traits,class std::allocator > const &)> const &)" (??$pushUserDataFrom@V?$function@$$A6A?AV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@ABV12@0@Z@std@@@LuaRef@LuaIntf@@CAXPAUlua_State@@abv?$function@$$A6A?AV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@ABV12@0@Z@std@@@z) 中被引用
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "void __cdecl lua_rawset(struct lua_State *,int)" (?lua_rawset@@YAXPAUlua_State@@h@Z),该符号在函数 "public: void __thiscall LuaIntf::LuaRef::rawset<char const *,class LuaIntf::LuaRef>(char const * const &,class LuaIntf::LuaRef const &)" (??$rawset@PBDVLuaRef@LuaIntf@@@LuaRef@LuaIntf@@QAEXABQBDABV01@@z) 中被引用
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "int __cdecl lua_setmetatable(struct lua_State *,int)" (?lua_setmetatable@@YAHPAUlua_State@@h@Z),该符号在函数 "private: static void __cdecl LuaIntf::LuaRef::pushUserDataFrom<class std::function<class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class std::basic_string<char,struct std::char_traits,class std::allocator > const &)> >(struct lua_State *,class std::function<class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class std::basic_string<char,struct std::char_traits,class std::allocator > const &)> const &)" (??$pushUserDataFrom@V?$function@$$A6A?AV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@ABV12@0@Z@std@@@LuaRef@LuaIntf@@CAXPAUlua_State@@abv?$function@$$A6A?AV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@ABV12@0@Z@std@@@z) 中被引用
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "char const * __cdecl luaL_checklstring(struct lua_State *,int,unsigned int *)" (?luaL_checklstring@@YAPBDPAUlua_State@@hpai@Z),该符号在函数 "public: static class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl LuaIntf::LuaTypeMapping<class std::basic_string<char,struct std::char_traits,class std::allocator >,void>::get(struct lua_State *,int)" (?get@?$LuaTypeMapping@V?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@x@LuaIntf@@sa?AV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@PAUlua_State@@h@Z) 中被引用
1>MessageSetter.obj : error LNK2001: 无法解析的外部符号 "char const * __cdecl luaL_checklstring(struct lua_State *,int,unsigned int *)" (?luaL_checklstring@@YAPBDPAUlua_State@@hpai@Z)
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "int __cdecl luaL_error(struct lua_State *,char const *,...)" (?luaL_error@@YAHPAUlua_State@@PBDZZ),该符号在函数 __catch$??$destructUserData@V?$function@$$A6A?AV?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@ABV12@0@Z@std@@@LuaRef@LuaIntf@@CAHPAUlua_State@@@z$0 中被引用
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "int __cdecl luaL_ref(struct lua_State *,int)" (?luaL_ref@@YAHPAUlua_State@@h@Z),该符号在函数 "private: __thiscall LuaIntf::LuaRef::LuaRef(struct lua_State *)" (??0LuaRef@LuaIntf@@aae@PAUlua_State@@@z) 中被引用
1>MessageSetter.obj : error LNK2001: 无法解析的外部符号 "int __cdecl luaL_ref(struct lua_State *,int)" (?luaL_ref@@YAHPAUlua_State@@h@Z)
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "int __cdecl luaL_ref(struct lua_State *,int)" (?luaL_ref@@YAHPAUlua_State@@h@Z)
1>LuaPbIntf.obj : error LNK2019: 无法解析的外部符号 "void __cdecl luaL_unref(struct lua_State *,int,int)" (?luaL_unref@@YAXPAUlua_State@@hh@Z),该符号在函数 "public: __thiscall LuaIntf::LuaRef::~LuaRef(void)" (??1LuaRef@LuaIntf@@QAE@XZ) 中被引用
1>MessageSetter.obj : error LNK2001: 无法解析的外部符号 "void __cdecl luaL_unref(struct lua_State *,int,int)" (?luaL_unref@@YAXPAUlua_State@@hh@Z)
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "void __cdecl luaL_unref(struct lua_State *,int,int)" (?luaL_unref@@YAXPAUlua_State@@hh@Z)
1>LuaPbIntfImpl.obj : error LNK2019: 无法解析的外部符号 "void __cdecl luaL_checktype(struct lua_State *,int,int)" (?luaL_checktype@@YAXPAUlua_State@@hh@Z),该符号在函数 "public: class LuaIntf::LuaRef const & __thiscall LuaIntf::LuaRef::checkType(enum LuaIntf::LuaTypeID)const " (?checkType@LuaRef@LuaIntf@@QBEABV12@W4LuaTypeID@2@@z) 中被引用
1>MessageSetter.obj : error LNK2019: 无法解析的外部符号 "char const * __cdecl lua_typename(struct lua_State *,int)" (?lua_typename@@YAPBDPAUlua_State@@h@Z),该符号在函数 "public: char const * __thiscall LuaIntf::LuaRef::typeName(void)const " (?typeName@LuaRef@LuaIntf@@QBEPBDXZ) 中被引用
1>MessageSetter.obj : error LNK2019: 无法解析的外部符号 "int __cdecl lua_toboolean(struct lua_State *,int)" (?lua_toboolean@@YAHPAUlua_State@@h@Z),该符号在函数 "public: static bool __cdecl LuaIntf::LuaTypeMapping<bool,void>::get(struct lua_State *,int)" (?get@?$LuaTypeMapping@_NX@LuaIntf@@SA_NPAUlua_State@@h@Z) 中被引用
1>MessageSetter.obj : error LNK2019: 无法解析的外部符号 "int __cdecl lua_rawequal(struct lua_State *,int,int)" (?lua_rawequal@@YAHPAUlua_State@@hh@Z),该符号在函数 "public: bool __thiscall LuaIntf::LuaTableIterator::operator==(class LuaIntf::LuaTableIterator const &)const " (??8LuaTableIterator@LuaIntf@@QBE_NABV01@@z) 中被引用
1>MessageSetter.obj : error LNK2019: 无法解析的外部符号 "void __cdecl lua_pushinteger(struct lua_State *,__int64)" (?lua_pushinteger@@YAXPAUlua_State@@_J@Z),该符号在函数 "public: static void __cdecl LuaIntf::LuaIntegerTypeMapping::push(struct lua_State *,int)" (?push@?$LuaIntegerTypeMapping@H@LuaIntf@@SAXPAUlua_State@@h@Z) 中被引用
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "void __cdecl lua_pushinteger(struct lua_State *,__int64)" (?lua_pushinteger@@YAXPAUlua_State@@_J@Z)
1>MessageSetter.obj : error LNK2019: 无法解析的外部符号 "int __cdecl lua_gettable(struct lua_State *,int)" (?lua_gettable@@YAHPAUlua_State@@h@Z),该符号在函数 "public: class LuaIntf::LuaRef __thiscall LuaIntf::LuaTableRef::value(void)const " (??$value@VLuaRef@LuaIntf@@@LuaTableRef@LuaIntf@@qbe?AVLuaRef@1@XZ) 中被引用
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "int __cdecl lua_gettable(struct lua_State *,int)" (?lua_gettable@@YAHPAUlua_State@@h@Z)
1>MessageSetter.obj : error LNK2019: 无法解析的外部符号 "int __cdecl lua_next(struct lua_State *,int)" (?lua_next@@YAHPAUlua_State@@h@Z),该符号在函数 "private: void __thiscall LuaIntf::LuaTableIterator::next(void)" (?next@LuaTableIterator@LuaIntf@@AAEXXZ) 中被引用
1>MessageSetter.obj : error LNK2019: 无法解析的外部符号 "double __cdecl luaL_checknumber(struct lua_State *,int)" (?luaL_checknumber@@YANPAUlua_State@@h@Z),该符号在函数 "public: static float __cdecl LuaIntf::LuaNumberTypeMapping::get(struct lua_State *,int)" (?get@?$LuaNumberTypeMapping@M@LuaIntf@@SAMPAUlua_State@@h@Z) 中被引用
1>MessageSetter.obj : error LNK2019: 无法解析的外部符号 "__int64 __cdecl luaL_checkinteger(struct lua_State *,int)" (?luaL_checkinteger@@YA_JPAUlua_State@@h@Z),该符号在函数 "public: static int __cdecl LuaIntf::LuaIntegerTypeMapping::get(struct lua_State *,int)" (?get@?$LuaIntegerTypeMapping@H@LuaIntf@@SAHPAUlua_State@@h@Z) 中被引用
1>MessageSetter.obj : error LNK2019: 无法解析的外部符号 "__int64 __cdecl luaL_len(struct lua_State *,int)" (?luaL_len@@YA_JPAUlua_State@@h@Z),该符号在函数 "public: int __thiscall LuaIntf::LuaRef::len(void)const " (?len@LuaRef@LuaIntf@@QBEHXZ) 中被引用
1>MessageSetter.obj : error LNK2001: 无法解析的外部符号 "private: static enum google::protobuf::FieldDescriptor::CppType const * const google::protobuf::FieldDescriptor::kTypeToCppTypeMap" (?kTypeToCppTypeMap@FieldDescriptor@protobuf@google@@0QBW4CppType@123@B)
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "private: static enum google::protobuf::FieldDescriptor::CppType const * const google::protobuf::FieldDescriptor::kTypeToCppTypeMap" (?kTypeToCppTypeMap@FieldDescriptor@protobuf@google@@0QBW4CppType@123@B)
1>MessageSetter.obj : error LNK2001: 无法解析的外部符号 "private: static char const * const * const google::protobuf::FieldDescriptor::kCppTypeToName" (?kCppTypeToName@FieldDescriptor@protobuf@google@@0QBQBDB)
1>MsgToTbl.obj : error LNK2001: 无法解析的外部符号 "private: static char const * const * const google::protobuf::FieldDescriptor::kCppTypeToName" (?kCppTypeToName@FieldDescriptor@protobuf@google@@0QBQBDB)
1>MsgToTbl.obj : error LNK2019: 无法解析的外部符号 "void __cdecl lua_pushnumber(struct lua_State *,double)" (?lua_pushnumber@@YAXPAUlua_State@@n@Z),该符号在函数 "public: static void __cdecl LuaIntf::LuaNumberTypeMapping::push(struct lua_State *,float)" (?push@?$LuaNumberTypeMapping@M@LuaIntf@@SAXPAUlua_State@@m@Z) 中被引用
1>MsgToTbl.obj : error LNK2019: 无法解析的外部符号 "void __cdecl lua_pushboolean(struct lua_State *,int)" (?lua_pushboolean@@YAXPAUlua_State@@h@Z),该符号在函数 "public: static void __cdecl LuaIntf::LuaTypeMapping<bool,void>::push(struct lua_State *,bool)" (?push@?$LuaTypeMapping@_NX@LuaIntf@@SAXPAUlua_State@@_N@Z) 中被引用
1>MsgToTbl.obj : error LNK2019: 无法解析的外部符号 "void __cdecl lua_settable(struct lua_State *,int)" (?lua_settable@@YAXPAUlua_State@@h@Z),该符号在函数 "public: class LuaIntf::LuaTableRef & __thiscall LuaIntf::LuaTableRef::operator=(class LuaIntf::LuaRef const &)" (??$?4VLuaRef@LuaIntf@@@LuaTableRef@LuaIntf@@QAEAAV01@ABVLuaRef@1@@z) 中被引用
1>bin\Debug\luapbintf.dll : fatal error LNK1120: 34 个无法解析的外部命令
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

声明的时候报错是什么情况?

package.cpath = "../luaclib/?.so;"
local pb=require("luapbintf")
报下面的错误。是不是我还少包含了什么?
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted (core dumped)

解码的过程碰到一个奇怪的问题

协议体
syntax = "proto3";
package login;
message login {
string account = 1 ;
string password = 2 ;
int32 sdkid = 3 ;
}

发送下面这个包,客户端发完后直接解包是正常解出来的

send pbstr:0A 04 6B 69 6E 67 12 06 31 31 31 31 31 31 18 01
send:cmd(login.login) check(0) len(24) msg->{
["password"] = "111111",
["account"] = "king",
["sdkid"] = 1,
}

服务端接收到这个包的打印
recv pbstr:0A 04 6B 69 6E 67 12 06 31 31 31 31 31 31 18 01
recv:cmd(login.login) check(0) msg->"
king111111"

这个msg里面直接是个字符串了。
我看了下。
local msg = pb.decode(cmd, pbstr)
这里msg解码后得到的是一个字符串。
解码失败会直接得到tostring的结果吗?使用的协议文件是同一个。怎么会解码失败呢

build error

ERROR: protobuf/3.5.1@bincrafters/stable: 'options.static_rt' doesn't exist
Possible options are ['shared', 'with_zlib', 'fPIC', 'lite'],how to solve this issue

调用luapbintf.import_proto_file报编码问题

luapbintf.import_proto_file 调用这个接口时报下面的错误
Interpreting non ascii codepoint 155.

协议文件
显示行号是string password = 2; 这一句的错误

syntax = "proto3";
package login;
message login
{
string account = 1;
string password = 2;
string sdkid=3; //1 inner 2debug
}

在build过程中遇到麻烦

有2个问题:
1.build过程中报错:
image,需要的xxx.h文件都已经拷贝到对应的目录里了。不知道是不是环境问题,如果是环境问题,请告知改如何配置环境;
2.在thrid_party里的readme.md里有说要拷贝lib目录到该目录里,请问这个lib是从哪里来的呢?谢谢。

Can't resolve this format of proto3

message A
{
repeated uint64 img_pos =1 [packed=true];
}

message AAA
{
repeated enum_win_type enType =1 [packed=true]; //
repeated A win_pos = 2 ; //
}

I want to decode AAA message from our server send data.
I can use c++ decode it, but lubpbint can't.
Do you have any time to resolve this?

Only need to decode it, do not need encode it.

上一个问题是怀疑有冲突问题。现在确认了是在协程下的绑定有问题

上次是在skynet中测试。发现在skynet.start中无法正常解码
然后经过一段时间的观察。并且问了skynet的作者。结论是你这边在协程中的绑定lua时的问题。
测试代码如下

pb.import_proto_file("login.proto")
local pbstr = pb.encode("login.login", {account="king",password="111111"})
print("encode")
local pbmsg=pb.decode("login.login",pbstr)
print(tool.dump(pbmsg))
print("=========================")
local cor=coroutine.create(function()
local msg= pb.decode("login.login", pbstr)
print("decode")
print(tool.dump(msg))
end)
coroutine.resume(cor)

打印结果如下
encode
{
["password"] = "111111",
["sdkid"] = 0,
["account"] = "king",
}

decode
"
king111111"

无法编译 编译时遇到问题

本人在 ubuntu 和 windows10 下都遇到 无法编译
按照这个:
Build with conan
Install conan.
Add conan repositories
conan remote add remote_bintray_bincrafters https://api.bintray.com/conan/bincrafters/public-conan
conan remote add remote_bintray_jinq0123 https://api.bintray.com/conan/jinq0123/test
conan create . user/channel --build missing
The result luapbintf.dll/luapbintf.so is in ~/.conan/data/luapbintf/0.1/user/channel/package/...
Add build settings like: conan create user/channel --build missing -s arch=x86

步骤 到最后 conan create git下载的py文件 --build missing 会到一步输入到用户名和密码的地步卡到 无法进行下一步编译。
望大佬给个解决方案

luajit support

would be great if we could use this library from luajit

uint64 support broken

given the following protobuf definition:

message MyMsg {
  uint64 uint64f = 1;
  int64  int64f  = 2;
}

and the following code:

   local msg = {
      uint64f = math.pow(2,32)
      int64f = math.pow(2,32)
   }
   local x =pb.decode("MyMsg", pb.encode( "MyMsg", msg ))
   print ( msg.int64f, msg.uint64f )
   print ( x.int64f, x.uint64f )

shows the following:

4294967296	4294967296
4294967296	0

Note that the int64 field is handled correctly, but uint64 is not.
Using a value 2^32 causes the issue; 2^32-1 works as expected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.