Hello,
I use sys.serialize() to send data via tcp to another host and there, use sys.deserialize() to turn the payload back into Lua objects. Very straight forward.
When I have a msg.url() in the payload, however, the deserialize() function throws errors which seem to be dependent on the composition of the url. I cannot see a pattern, though.
For example, deserializing msg.url( “main”, “hello”, “frag” ) will throw an error every time.
On the other hand, deserializing msg.url( “foo”, “bar”, “baz” ) works just fine.
To illustrate the problem, here is some simple example code:
local tcp_client = require( "defnet.tcp_client" )
local tcp_server = require( "defnet.tcp_server" )
function init(self)
msg.post(".", "acquire_input_focus")
msg.post("@render:", "use_fixed_fit_projection", { near = -1, far = 1 })
local onData = function( data, cip, cport, client )
local cmd = sys.deserialize( data )
pprint( cmd )
end
local nop = function() end
self.server = tcp_server.create( 8888, onData, nop, nop )
self.server.start()
self.client = tcp_client.create( "127.0.0.1", 8888, nop, nop )
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
local payload = {}
-- FAILS: --------------------------------
payload.url = msg.url( "main", "hello", "frag" )
-- ERROR:SCRIPT: defnet/tcp_server.lua:181: main/main.script:11: Table contains invalid type (nil) at element #0:
-- stack traceback: [C]:-1: ?
-- defnet/tcp_server.lua:181: in function update
-- main/main.script:47: in function <main/main.script:45>
-- INSTEAD WORKS: ----------------------
payload.url = msg.url( "foo", "bar", "baz" )
self.client.send( sys.serialize( payload ) .. "\n" )
end
end
function update( self, dt )
if self.client then self.client.update() end
if self.server then self.server.update() end
end
Am I doing something wrong or is this a bug in the serializer/deserializer functions? I use Defold version 1.9.1 on MacOSX.
Thanks in advance!
Cheers,
Lutz