Skip to content

tolua.c中的LUAJIT_VERSION不生效(The LUAJIT_VERSION is not working in tolua.c) #37

@zhangjiequan

Description

@zhangjiequan

问题(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:)

#ifdef LUAJIT_VERSION            
        luaL_traceback(L, L1, msg, level);
#else        
        lua_getref(L, LUA_RIDX_TRACEBACK);
        lua_pushthread(L1);
        lua_pushvalue(L, arg + 1);
        lua_pushnumber(L, level + 1);
        lua_call(L, 3, 1);
#endif

分析(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::)

#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":
image
After adding it, the changes to the corresponding serialized file tolua_runtime\iOS\tolua.xcodeproj\project.pbxproj are as follows:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions