加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 16:37:54 所属栏目:百科 来源:网络整理
导读: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 (lu

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.修改frameworkscocos2d-xcocos目录下的 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读