1.在cpp工程中搜索print( 定位到 int lua_print(lua_State * luastate),这个地方就是 lua中print函数的api
int lua_print(lua_State * luastate)
{
int nargs = lua_gettop(luastate);
std::string t;
for (int i=1; i <= nargs; i++)
{
if (lua_istable(luastate,i))
t += "table";
else if (lua_isnone(luastate,i))
t += "none";
else if (lua_isnil(luastate,i))
t += "nil";
else if (lua_isboolean(luastate,i))
{
if (lua_toboolean(luastate,i) != 0)
t += "true";
else
t += "false";
}
else if (lua_isfunction(luastate,i))
t += "function";
else if (lua_islightuserdata(luastate,i))
t += "lightuserdata";
else if (lua_isthread(luastate,i))
t += "thread";
else
{
const char * str = lua_tostring(luastate,i);
if (str)
t += lua_tostring(luastate,i);
else
t += lua_typename(luastate,lua_type(luastate,i));
}
if (i!=nargs)
t += "\t";
}
#ifdef ANDROID
__android_log_print(ANDROID_LOG_DEBUG,"cocos2d-x debug info","%s",t.c_str());
#else
CCLOG("[LUA-print] %s",t.c_str());
#endif
return 0;
}
3.修改frameworks\cocos2d-x\cocos目录下的 Android.mk
添加一句LOCAL_CFLAGS :=-DCOCOS2D_DEBUG=1 -DANDROID 这样就定义了cpp中的 ANDROID 宏,相当于#define ANDROID
LOCAL_CFLAGS :=-DCOCOS2D_DEBUG=1 -DANDROID LOCAL_SRC_FILES := \ cocos2d.cpp \ 2d/CCAction.cpp \ 2d/CCActionCamera.cpp \ 2d/CCActionCatmullRom.cpp \ 2d/CCActionEase.cpp \ 2d/CCActionGrid.cpp \