cocos2dx lua让print 在andriod 输出log的方法

前端之家收集整理的这篇文章主要介绍了cocos2dx lua让print 在andriod 输出log的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.在cpp工程中搜索print( 定位到 int lua_print(lua_State * luastate),这个地方就是 lua中print函数的api

2.修改函数



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 \

原文链接:https://www.f2er.com/cocos2dx/341113.html

猜你在找的Cocos2d-x相关文章