I just did my own tests and the string functions don't count unicode characters as others have suggested.
I tested it with the string "これは日本語の文字列です" with string.len, the # operator,
two methods proposed on the lua-users wiki and the utf8len function in
this gist.
Lua Code:
local input = "これは日本語の文字列です"
local count1 = input:len()
local count2 = #input
local _, count3 = string.gsub(input, "[^\128-\193]","")
local count4 = 0
for uchar in string.gmatch(input, "([%z\1-\127\194-\244][\128-\191]*)") do
count4 = count4 + 1
end
local count5 = utf8len(input)
d(count1, count2, count3, count4, count5)
The output is 36, 36, 36, 0, 12, meaning that the string functions use byte count, gsub and gmatch do something unexpected and the only way right now is to use some library to count how many characters you have left.
As for your original problem, you can always use a function that manages saving and reading the saved string and split it up dynamically. Here is an example that I just slapped together:
Lua Code:
local MAX_SAVE_DATA_LENGTH = 2000 -- buffer length used by ZOS
local function WriteLongString(obj, key, value)
local output = value
local byteLength = #value
if(byteLength > MAX_SAVE_DATA_LENGTH) then
output = {}
local startPos = 1
local endPos = startPos + MAX_SAVE_DATA_LENGTH - 1
while startPos <= byteLength do
output[#output + 1] = string.sub(value, startPos, endPos)
startPos = endPos + 1
endPos = startPos + MAX_SAVE_DATA_LENGTH - 1
end
end
obj[key] = output
end
local function ReadLongString(obj, key)
local value = obj[key]
if(type(value) == "table") then
return table.concat(value, "")
end
return value
end