GameState.save() 在安卓下报错

大致环境:
1.新手入门Android,lua一周
2.cocos2d-quick 3.3rc0
3.ndk-r9d
4.OS X 10.9.5
5…

测试代码:
local a = {}
a.str = “helloworld”
GameState.save(a)

结果:
用Cocos Code IDE的模拟器上运行正常
但是在安卓机上进行真机测试时出现下面的问题
11-11 00:07:22.400: D/cocos2d-x debug info(3008): LUA ERROR: :0: attempt to index upvalue ‘’ (a nil value)
11-11 00:07:22.400: D/cocos2d-x debug info(3008):
11-11 00:07:22.400: D/cocos2d-x debug info(3008): stack traceback:
11-11 00:07:22.400: D/cocos2d-x debug info(3008): : in function ‘encode’
11-11 00:07:22.400: D/cocos2d-x debug info(3008): : in function ‘’
11-11 00:07:22.400: D/cocos2d-x debug info(3008): : in function ‘save’

于是我又试下
测试代码:
local a = {}
a.str = “helloworld”
json.encode(a)

结果:
没有问题

然后翻了下GameState的源代码
function GameState.save(newValues)
local values = eventListener({
name = “save”,
values = newValues,
encode = type(secretKey) == “string”
})
if type(values) ~= “table” then
printError(“GameState.save() - listener return invalid data”)
return false
end

local filename = GameState.getGameStatePath()
local ret = false
if secretKey then
    ret = io.writefile(filename, encode_(values))
else
    local s = json.encode(values)
    if type(s) == "string" then
        ret = io.writefile(filename, s)
    end
end

printInfo("GameState.save() - update file \"%s\"", filename)
return ret

end

额…不知道怎么办,求大大们指引迷津~折腾了一个晚上了:10:

卧槽。。。好蛋疼。。。咋整

花了一天时间,终于搞掂,虽然还是不知道什么原理,可能是GameState里面调用的json对象有问题?没能再花时间研究了。用了一个应付方法:
修改源码framework/cc/utils/GameState.lua,增加下面的方法
function GameState.saveEX(m,newValues)
local values = eventListener({
name = “save”,
values = newValues,
encode = type(secretKey) == “string”
})
if type(values) ~= “table” then
printError(“GameState.save() - listener return invalid data”)
return false
end
local filename = GameState.getGameStatePath()
local ret = false
if secretKey then
local s = m.encode(values)
local hash = crypto.md5(s…secretKey)
local contents = m.encode({h = hash, s = s})
ret = io.writefile(filename, encodeSign…contents)
else
local s = m.encode(values)
if type(s) == “string” then
ret = io.writefile(filename, s)
end
end

printInfo("GameState.save() - update file \"%s\"", filename)
return ret

end

测试代码:
local a = {}
a.str = “helloworld”
GameState.saveEX(json,a)

结果:
GameState.save() - update file “/data/data/org.cocos2dx.starfun/files/data.dat”

PS:求3.3正式版快出,要是每每这么整那要是哭的节奏啊

楼主能说下这个函数是干什么用的么?

这里是有bug,本来是想用cocos的json,但有点问题。新版本已经恢复使用cjon,没问题了。
v3.3final已经打包上传到服务器,等待正式发布了。