tolua#各个平台添加自定义扩展并编译tolua库

先放上tolua#的几个github地址
tolua#
https://github.com/topameng/tolua
Debugger
https://github.com/topameng/Debugger
tolua_runtime
https://github.com/topameng/tolua_runtime

Windows环境配置
NDK 版本:android-ndk-r10e 默认安装到 D:/android-ndk-r10ehttps://dl.google.com/android/repository/android-ndk-r10e-windows-x86_64.zip
Msys2配置说明https://github.com/topameng/tolua_runtime/wiki
配置好的Msys2下载https://pan.baidu.com/s/1c2JzvDQ

OSX环境配置
需要Xcode命令行工具

tolua_runtime build
pc: build_win32.sh build_win64.h (mingw + luajit2.1.0-beat3)
android: build_arm.sh build_x86.sh (mingw + luajit2.1.0-beat3)
mac: build_osx.sh (xcode + luac5.1.5 luajit can't run in unity5)
ios: build_ios.sh (xcode + luajit2.1.0-beat3)

添加自定义扩展库(以添加云风的Snapshot.c库 为例)
需要将snapshot.c文件稍微修改一下,符合tolua语法

/*
int
luaopen_snapshot(lua_State *L) {
    luaL_checkversion(L);
    lua_pushcfunction(L, snapshot);
    return 1;
} */

static const struct luaL_Reg snapshot_funcs[] = {
    { "snapshot", snapshot },
    { NULL, NULL }
};

LUALIB_API int luaopen_snapshot(lua_State *L) {
    luaL_checkversion(L);
    #if LUA_VERSION_NUM < 502
        luaL_register(L, "snapshot", snapshot_funcs);
    #else
        luaL_newlib(L, snapshot_funcs);
    #endif
    return 1;
}

将Snapshot.c放到tolua_runtime-master/目录下
pc:分别在build_win32.sh和build_win64.h中将 snapshot.c \添加到 luasocket/wsocket.c \下一行
android:tolua_runtime-master/android/jni/Android.mk中将 ../../snapshot.c \添加到../../luasocket/usocket.c \下一行
mac:将tolua_runtime-master/macnojit/中的xcode工程文件打开,将snapshot.c加入到工程中
mac:将tolua_runtime-master/iOS/中的xcode工程文件打开,将snapshot.c加入到工程中

修改完成后根据各个平台执行编译脚本。

在tolua中的LuaDLL.cs中 添加
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
public static extern int luaopen_snapshot(IntPtr L);
然后通过下面代码开启snapshot库

LuaState lua = new LuaState();
lua.Start();
lua.OpenLibs(LuaDLL.luaopen_snapshot);

然后再lua中再使用

require("snapshot")
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,498评论 25 709
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,784评论 2 45
  • 看着街道上的人来人往,心,从未有过的孤独,什么时候我的身边才会有那么一个人,一起牵手逛街,一起吃饭,一起分享喜怒哀...
    6c6d01a33995阅读 1,342评论 0 0
  • 中元的夜里,人也醒着,鬼也醒着。 ——题记 清明节、中元节和寒衣节被称为中国古代的三大鬼节,其中又以中元节最为深入...
    春秋一语阅读 2,372评论 0 1

友情链接更多精彩内容