c++导出全局变量给lua使用

来源:互联网 发布:宝贝关键词怎么优化 编辑:程序博客网 时间:2024/06/03 08:41

在cocos中注册

bool AppDelegate::applicationDidFinishLaunching(){// set default FPSDirector::getInstance()->setAnimationInterval(1.0 / 60.0f);Image::setPVRImagesHavePremultipliedAlpha(true);// register lua moduleauto engine = LuaEngine::getInstance();ScriptEngineManager::getInstance()->setScriptEngine(engine);#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)    CrashReport::initCrashReport("365835e6ed", false);    BuglyLuaAgent::registerLuaExceptionHandler(engine);  //在这注册

静态的注册函数registerLuaExceptionHandler注册BuglyLuaAgent中的静态函数reportLuaException

void BuglyLuaAgent::registerLuaExceptionHandler(cocos2d::LuaEngine * engine) {lua_State *L = engine->getLuaStack()->getLuaState();lua_register(L, "buglyReportLuaException", BuglyLuaAgent::reportLuaException);  //这个是导出的全局变量lua_register(L, "buglySetUserId", BuglyLuaAgent::setUserId);lua_register(L, "buglySetTag", BuglyLuaAgent::setTag);lua_register(L, "buglyAddUserValue", BuglyLuaAgent::addUserValue);lua_register(L, "buglyRemoveUserValue", BuglyLuaAgent::removeUserValue);lua_register(L, "buglyLog", BuglyLuaAgent::printLog);}


使用全局变量:buglyReportLuaException

function __G__TRACKBACK__( msg )--崩溃收集if buglyReportLuaException thenbuglyReportLuaException(tostring(msg), debug.traceback())end--调试模式显示异常if gt.isDebugPackage thenlocal logInfo = io.readfile(logfile)local logTab = string.split(logInfo, "\n")local ret = table.concat(logTab, "\n", #logTab > 100 and (#logTab - 100 ) or 1)        require("app/views/ErrorTips"):create(ret .. "\n" .. "LUA ERROR: " .. tostring(msg) .. "\n" .. debug.traceback(), true)    end    gt.log("LUA ERROR: " .. tostring(msg) .. "\n")    gt.log(debug.traceback()) end

原创粉丝点击