首页 > 代码库 > cocos2dx 3.3 C++工程添加lua支持

cocos2dx 3.3 C++工程添加lua支持

准备工作:

1. 拷贝cocos2d-x-3.3rc0\external\lua整个文件夹到项目中(如myProject\cocos2d\external\lua)

2. 拷贝cocos2d-x-3.3rc0\cocos\scripting整个文件夹到项目中(如myProject\cocos2d\cocos\scripting)

 

VS工程配置:

1. 解决方案中添加刚拷贝过来的libluacocos2d项目(添加现有项目: myProject\cocos2d\cocos\scripting\lua-bindings\proj.win32\libluacocos2d.vcxproj)

2. myProject工程添加项目依赖(右键项目属性->添加->引用->添加新引用->勾选libluacocos2d)

3. 附加包含目录添加(参考lua-tests工程):

$(EngineRoot)cocos\scripting\lua-bindings\auto
$(EngineRoot)cocos\scripting\lua-bindings\manual
$(EngineRoot)external\lua\luajit\include
$(EngineRoot)external\lua\tolua
$(EngineRoot)external\lua

4. 连接器->输入添加:

lua51.lib

 

Android.mk配置:

只需添加:

LOCAL_STATIC_LIBRARIES += cocos2d_lua_static

$(call import-module,scripting/lua-bindings/proj.android)

如:

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)LOCAL_MODULE := cocos2dcpp_sharedLOCAL_MODULE_FILENAME := libcocos2dcpp#====== Auto include all cpp files in Classes directory ======# define walk function to recursive travel directorydefine walk    $(wildcard $(1)) $(foreach e, $(wildcard $(1)/*), $(call walk, $(e)))endef# travel Classes directoryALLFILES = $(call walk, $(LOCAL_PATH)/../../Classes)FILE_LIST := hellocpp/main.cppFILE_LIST += $(filter %.cpp, $(ALLFILES))LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)#=============================================================LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes                     $(LOCAL_PATH)/../../Classes/CCGame/includeLOCAL_STATIC_LIBRARIES := cocos2dx_staticLOCAL_STATIC_LIBRARIES += cocos2d_lua_staticinclude $(BUILD_SHARED_LIBRARY)$(call import-module,scripting/lua-bindings/proj.android)$(call import-module,.)

 

cocos2dx 3.3 C++工程添加lua支持