lua的编译方式后面会介绍,今天直接说在cocos里使用lua遇到的坑......
有2种方法,一种是连带lua源码一起丢进去和cocos一起编译,另外种是用已经编译好的lua静态文件和cocos一起编译,
下面一一介绍。。。。顺便说说遇到的坑
方式1:lua源码 + cocos一起编译,主要是Android.mk的编写
Android.mk: <pre name="code" class="html">LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := luaLOCAL_SRC_FILES := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c loslib.c lparser.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c ltm.c lundump.c lvm.c lzio.cinclude $(BUILD_STATIC_LIBRARY)
<span style="color:#ff0000;">LOCAL_PATH := $(call my-dir)</span>
include $(CLEAR_VARS)LOCAL_MODULE := cocos2dcpp_sharedLOCAL_MODULE_FILENAME := libcocos2dcppLOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldScene.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../ClassesLOCAL_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += luainclude $(BUILD_SHARED_LIBRARY)$(call import-module,./prebuilt-mk)
lua源码放在jni目录
这段语法的意思是 先编译lua的源代码,模块名命名为lua,
一般以LOCAL_PATH开头....................include$() 结尾
这段代码说明有2段编译(2段LOCAL_PATH开头....................include$() 结尾)
但是注意红色部分...红色部分导致无法编译,如果网上资料查的多,都知道红色部分是正确的呢,但是必须去掉他才能通过编译!
方式2:
LOCAL_PATH:= $(call my-dir) # 需要把静态库导入 include $(CLEAR_VARS) LOCAL_MODULE := lua LOCAL_SRC_FILES := liblua.a include $(PREBUILT_STATIC_LIBRARY) <span style="color:#ff0000;">LOCAL_PATH:= $(call my-dir) </span> include $(CLEAR_VARS) LOCAL_MODULE := cocos2dcpp_shared LOCAL_MODULE_FILENAME := libcocos2dcpp LOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldScene.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += lua include $(BUILD_SHARED_LIBRARY) $(call import-module,./prebuilt-mk)
同样注意红色那一行,这部分应该删除掉......