mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
updates
This commit is contained in:
parent
3768a6a3ca
commit
7b42a7a5ee
15
control.lua
15
control.lua
@ -78,3 +78,18 @@ Event.add(
|
||||
print(serpent.block(tbl))
|
||||
end
|
||||
)
|
||||
|
||||
local Token = require('utils.global_token')
|
||||
local data_callback = Token.register(
|
||||
function(data)
|
||||
game.print(serpent.line(data))
|
||||
end
|
||||
)
|
||||
|
||||
function get_data(data_set, key)
|
||||
Server.try_get_data(data_set, key, data_callback)
|
||||
end
|
||||
|
||||
function get_all_data(data_set, key)
|
||||
Server.try_get_all_data(data_set, data_callback)
|
||||
end
|
||||
|
11
server.lua
11
server.lua
@ -134,6 +134,9 @@ function Public.set_data(data_set, key, value)
|
||||
if vt == 'nil' then
|
||||
message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '"}'})
|
||||
elseif vt == 'string' then
|
||||
-- Excessive escaping because the data is serialized twice.
|
||||
value = value:gsub('\\', '\\\\\\\\'):gsub('"', '\\\\\\"')
|
||||
|
||||
message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"\\"', value, '\\""}'})
|
||||
elseif vt == 'number' then
|
||||
message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"', value, '"}'})
|
||||
@ -142,9 +145,13 @@ function Public.set_data(data_set, key, value)
|
||||
table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, '",value:"', tostring(value), '"}'})
|
||||
elseif vt == 'function' then
|
||||
error('value cannot be a function')
|
||||
else
|
||||
else -- table
|
||||
value = serpent.line(value)
|
||||
value = value:gsub("'", "\\'")
|
||||
|
||||
-- Less escaping than the string case as serpent provides one level of escaping.
|
||||
-- Need to escape single quotes as serpent uses double quotes for strings.
|
||||
value = value:gsub('\\', '\\\\'):gsub("'", "\\'")
|
||||
|
||||
message = table.concat({data_set_tag, '{data_set:"', data_set, '",key:"', key, "\",value:'", value, "'}"})
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user