|
记录环境
Unity 2021.3.4f1xLua-2.1.16_with_silicon_supportLua 5.3.3 => Lua 5.3.5
各平台需要的软件
1、Windows
cmake-3.24.0-rc1-windows-x86_64Lua 5.3.3 (bin)
2、Centos(用来编译Android)
cmake-3.20.0-linux-x86_64.shandroid-ndk-r15c-linux-x86_64.zip
<hr>源码修改
我们项目需要cjson跟pbc,所以要添加拓展。
1、CMakeLists.txt
...#begin ======================== lua-cjson ========================set ( CJSON_SRC lua-cjson-2.1.0/strbuf.c lua-cjson-2.1.0/lua_cjson.c lua-cjson-2.1.0/fpconv.c)#add_definitions(-DUSE_INTERNAL_FPCONV)if(WIN32) # Windows sprintf()/strtod() handle NaN/inf differently. Not supported. add_definitions(-DDISABLE_INVALID_NUMBERS)endif()set_property( SOURCE ${CJSON_SRC} APPEND PROPERTY COMPILE_DEFINITIONS LUA_LIB)list(APPEND THIRDPART_INC lua-cjson-2.1.0)set (THIRDPART_SRC ${THIRDPART_SRC} ${CJSON_SRC})#end ======================== lua-cjson ========================#begin ======================== pbc ========================set ( PBC_SRC pbc/binding/lua/pbc-lua.c pbc/src/alloc.c pbc/src/array.c pbc/src/bootstrap.c pbc/src/context.c pbc/src/decode.c pbc/src/map.c pbc/src/pattern.c pbc/src/proto.c pbc/src/register.c pbc/src/rmessage.c pbc/src/stringpool.c pbc/src/varint.c pbc/src/wmessage.c)set_property( SOURCE ${PBC_SRC} APPEND PROPERTY COMPILE_DEFINITIONS LUA_LIB)list(APPEND THIRDPART_INC pbc)list(APPEND THIRDPART_INC pbc/src)set (THIRDPART_SRC ${THIRDPART_SRC} ${PBC_SRC})#end ======================== pbc ========================#begin ======================== 宏定义 ========================# 兼容5.1的APIadd_definitions(-DLUA_COMPAT_5_1)#end ======================== 宏定义 ========================if (NOT LUA_VERSION) # 这里设置Lua版本 set(LUA_VERSION "5.3.3")endif()...2、xlua - lua-5.3.3源码修改
删除 loadlib.c、wmain.c 两个文件在编译iOS时,修改loslib.c
将int stat = system(cmd);改为int stat = nftw(cmd, unlink_cb, 64, FTW_DEPTH | FTW_PHYS);
同时添加修改:
#include <ftw.h>...static int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf){ int rv = remove(fpath); if (rv) perror(fpath); return rv;}3、pbc源码修改
...#ifdef __cplusplusextern "C" {#endif/******************** 修改添加 Begin ********************/#ifndef bool#define bool char#endif#ifndef true#define true 1#endif#ifndef false#define false 0#endif/******************** 修改添加 End ********************/...intluaopen_protobuf_c(lua_State *L) {改为LUALIB_API intluaopen_protobuf_c(lua_State *L) {4、cjson源码修改
// 添加别名定义#ifdef _MSC_VER#define strcasecmp stricmp#define strncasecmp strnicmp #endif// lua导出注册int luaopen_cjson(lua_State *l)改为LUALIB_API int luaopen_cjson(lua_State *l)<hr>编译
<hr>问题记录
1、Android运行报错
LuaException: error loading module Main.Main_C from CustomLoader, Main/Main_C: size_t size mismatch in precompiled chunk
Lua 5.3.5之前的版本没有支持通用字节码,这个折腾了两天时间Orz。所以不能使用Lua 5.3.3版本。
参考文章
UWA开源库:uLua Project
lua cjson 数字问题 |
|