cocos2d-x 3.5后使用luasocket:local SOCKET = require "socket";
结果运行就报错:[LUA-print] USE " cc.exports.socket = value " INSTEAD OF SET GLOBAL VARIABLE
lua禁用全局变量
解决办法:在require "cocos.init"之前引入require "socket"; 即可,
代码:
cc.FileUtils:getInstance():setPopupNotify(false)
cc.FileUtils:getInstance():addSearchPath("src/")
cc.FileUtils:getInstance():addSearchPath("res/") --这样引入luasocket
require "socket" require "config"
require "cocos.init" local function main() local SOCKET = socket; print("============xxxxxx===========", SOCKET); require("app.MyApp"):create():run()
end local status, msg = xpcall(main, __G__TRACKBACK__)
if not status then
print(msg)
end
参考:http://blog.csdn.net/qq446569365/article/details/44977397