You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
在tolua.c中,试图根据宏LUAJIT_VERSION对代码进行区分,
然而实际情况是,并未按预期走入我们所期望的分支。
在文件tolua_runtime\tolua.c中,代码如下:
(In tolua.c, there is an attempt to differentiate the code based on the LUAJIT_VERSION macro.
However, in reality, it does not follow the expected path.
The code snippet in the file tolua_runtime\tolua.c is as follows:)
以当前的Windows版本为例,代码的初衷是要走LuaJIT的逻辑分支。
然而,由于既未在tolua.c中引用定义LUAJIT_VERSION的头文件luajit.h,也未在编译指令中加入宏LUAJIT_VERSION,
因此实际上执行了else分支的代码。
(Taking the current Windows version as an example, the code was intended to handle the LuaJIT logical branch.
However, due to the lack of inclusion of the luajit.h header file, which defines LUAJIT_VERSION, in the tolua.c file, and the absence of the LUAJIT_VERSION macro in the compilation instructions,
the code actually executes the else branch.)
解决(Solution)
考虑到macnojit也会使用该tolua.c文件,直接包含"luajit.h"的方式并不十分友好,需要进行其他的改动。
建议在编译指令中加入LUAJIT_VERSION。
(Since the tolua.c file is also used for macnojit, directly including "luajit.h" is not very friendly and requires other modifications.
Here, it is suggested to add LUAJIT_VERSION in the compilation instructions.)
Windows
以Windows为例,示例如下:
(Here is an example for Windows::)
#tolua_runtime\build_win64.sh
gcc -m64 -O2 -std=gnu99 -shared \
-DLUAJIT_VERSION="\"LuaJIT 2.1.0-beta3\"" \ #add this line
tolua.c \
如上述代码所示,我在第二行中增加了对LUAJIT_VERSION的定义。
(As shown in the code above, a definition for LUAJIT_VERSION has been added in the second line.)
Android
#tolua_runtime\android\jni\Android.mk
LOCAL_CFLAGS := -O2 -std=gnu99
LOCAL_CFLAGS += "-DLUAJIT_VERSION=\"LuaJIT 2.1.0-beta3\"" #add this line
LOCAL_SRC_FILES := ../../tolua.c \
iOS
Xcode ---> select "target" ---> "Build Settings" ---> Search “Preprocessor Macros” ---> add LUAJIT_VERSION="LuaJIT 2.1.0-beta3":
After adding it, the changes to the corresponding serialized file tolua_runtime\iOS\tolua.xcodeproj\project.pbxproj are as follows:
The text was updated successfully, but these errors were encountered:
而宏LUAJIT_VERSION生效后,我们可以基于它优雅地写兼容性代码。
(Once the LUAJIT_VERSION macro is working, we can elegantly write compatibility code based on it. )
现状(Current Status)
以cjson为例子,需要根据是否为luajit注释与反注释第一、二行。
(Take cjson as an example, we need to comment and uncomment the first and second lines depending on whether it's luajit.)
当前代码如下:
(The current code is as follows:)
tolua_runtime\cjson\lua_cjson.c
问题(Issue)
在tolua.c中,试图根据宏LUAJIT_VERSION对代码进行区分,
然而实际情况是,并未按预期走入我们所期望的分支。
在文件tolua_runtime\tolua.c中,代码如下:
(In tolua.c, there is an attempt to differentiate the code based on the LUAJIT_VERSION macro.
However, in reality, it does not follow the expected path.
The code snippet in the file tolua_runtime\tolua.c is as follows:)
分析(Analysis)
以当前的Windows版本为例,代码的初衷是要走LuaJIT的逻辑分支。
然而,由于既未在tolua.c中引用定义LUAJIT_VERSION的头文件luajit.h,也未在编译指令中加入宏LUAJIT_VERSION,
因此实际上执行了else分支的代码。
(Taking the current Windows version as an example, the code was intended to handle the LuaJIT logical branch.
However, due to the lack of inclusion of the luajit.h header file, which defines LUAJIT_VERSION, in the tolua.c file, and the absence of the LUAJIT_VERSION macro in the compilation instructions,
the code actually executes the else branch.)
解决(Solution)
考虑到macnojit也会使用该tolua.c文件,直接包含"luajit.h"的方式并不十分友好,需要进行其他的改动。
建议在编译指令中加入LUAJIT_VERSION。
(Since the tolua.c file is also used for macnojit, directly including "luajit.h" is not very friendly and requires other modifications.
Here, it is suggested to add LUAJIT_VERSION in the compilation instructions.)
Windows
以Windows为例,示例如下:
(Here is an example for Windows::)
如上述代码所示,我在第二行中增加了对LUAJIT_VERSION的定义。
(As shown in the code above, a definition for LUAJIT_VERSION has been added in the second line.)
Android
iOS
Xcode ---> select "target" ---> "Build Settings" ---> Search “Preprocessor Macros” ---> add LUAJIT_VERSION="LuaJIT 2.1.0-beta3":
After adding it, the changes to the corresponding serialized file tolua_runtime\iOS\tolua.xcodeproj\project.pbxproj are as follows:
The text was updated successfully, but these errors were encountered: