记录以备忘git
由于有别的现有架构,因此只是换lua中间件,同时须要protobuf,因此使用pbc加入编译。tolua#在github上就有simpleframwork可用,我的项目能够使用。github
此时tolua#项目结构为shell
#!/bin/bash # 32 Bit Version mkdir -p window/x86 # mingw32-make = 'C:\Ruby\DevKit\mingw\bin\mingw32-make.exe' cd luajit mingw32-make clean mingw32-make BUILDMODE=static CC="gcc -m32 -O3" cp src/libluajit.a ../window/x86/libluajit.a mingw32-make clean cd .. # build protobuf fengyun ban pbc from https://github.com/cloudwu/pbc/ cd pbc mingw32-make lib BUILDMODE=static CC="gcc -m32 -O3" cp build/libpbc.a ../window/x86/libpbc.a mingw32-make clean cd .. gcc -m32 -O3 -std=gnu99 -shared \ int64.c \ uint64.c \ tolua.c \ pb.c \ lpeg.c \ struct.c \ cjson/strbuf.c \ cjson/lua_cjson.c \ cjson/fpconv.c \ luasocket/auxiliar.c \ luasocket/buffer.c \ luasocket/except.c \ luasocket/inet.c \ luasocket/io.c \ luasocket/luasocket.c \ luasocket/mime.c \ luasocket/options.c \ luasocket/select.c \ luasocket/tcp.c \ luasocket/timeout.c \ luasocket/udp.c \ luasocket/wsocket.c \ luasocket/compat.c \ pbc/binding/lua/pbc-lua.c \ -o Plugins/x86/tolua.dll \ -I./ \ -Iluajit/src \ -Ipbc \ -Ipbc/src \ -Icjson \ -Iluasocket \ -lws2_32 \ -Wl,--whole-archive window/x86/libluajit.a window/x86/libpbc.a -Wl,--no-whole-archive -static-libgcc
这是修改好的win32平台编译脚本,修改了几个内容以下:json
....
# 新加,编译pbc.a
# build protobuf fengyun ban pbc from https://github.com/cloudwu/pbc/
cd pbc
mingw32-make lib BUILDMODE=static CC="gcc -m32 -O3"
cp build/libpbc.a ../window/x86/libpbc.a
mingw32-make clean
cd .. bash
gcc -m32 -O3 -std=gnu99 -shared \
... 架构
pbc/binding/lua/pbc-lua.c \ # 新加,要编译c代码,另外一个是lua-53没用到
-o Plugins/x86/tolua.dll \
...
-Ipbc \ # 新加, 头文件目录
-Ipbc/src \# 新加,头文件目录 socket
...tcp
-Wl,--whole-archive window/x86/libluajit.a window/x86/libpbc.a -Wl,--no-whole-archive -static-libgccui
把生成的libpbc.a包含到dll中。lua
4.修改代码文件
pbc/binding/lua/pbc-lua.c 这个文件须要改一下
把 20行
#ifndef _MSC_VER
改为
#if !defined( _MSC_VER ) && !defined( __MINGW32__ ) && !defined( __MINGW64__)
由于我用的mingw + msys编译的,mingw没有_MSC_VER 这个定义,因此只好加mingw本身的
5.编译,运行mingw的msys.bat,在弹出的shell窗口cd到tolua#目录,运行./build_win32.sh生成tolua.dll在plugins/x86/目录下,拷贝到项目plugins/x86就行了。
6.使用
/*
** third party library
*/
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int luaopen_protobuf_c(IntPtr L);
3.启动lua时注册proto库,
luaState.OpenLibs(LuaDLL.luaopen_pb);
luaState.OpenLibs(LuaDLL.luaopen_struct);
luaState.OpenLibs(LuaDLL.luaopen_lpeg);
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
luaState.OpenLibs(LuaDLL.luaopen_bit);
//lua.OpenLibs(LuaDLL.luaopen_bit);
#endif
//luaState.OpenLibs(LuaDLL.luaopen_sproto_core);
luaState.OpenLibs(LuaDLL.luaopen_protobuf_c);
就和lua注册别的第三方库同样,找到而后把proto的注册调用加上,就能够写lua代码了,参考pbc自带的demo
注:
tolua#项目地址https://github.com/topameng/tolua
若是没装mingwin的话能够下载tdm-gcc,在SourceForge搜tdm mingw就有http://jaist.dl.sourceforge.net/project/tdm-gcc/TDM-GCC%20Installer/tdm64-gcc-5.1.0-2.exe
安装64位版的,由于也要编译64位dll。
安装方法:
1,运行安装文件,目录选择d:/mingw(自定义)
2,mingw安装到d:/mingw.配置bin目录到path环境变量。
3,下载msys,解压或安装(能够是执行文件和压缩包文件)到d:msys(自定义)https://sourceforge.net/projects/mingwbuilds/files/external-binary-packages/
4,修改msys目录下msys.bat,在第一行以前加入call "D:\Development\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat"(vs2015的环境变量脚本,根据安装的vs来写,或者不加)
5,修改关联文件,d:msys/etc/fstab文件,可安装fstab.sample修改,即关联mingw所在安装目录,大体内容为:
#Win32_Path Mount_Point
D:/MinGW /mingw
6,基本完成了,执行msys.bat在弹出的shell窗口能够导航到tolua#进行编译了。