Using util.data_mapper in Lua

I’m trying to figure out how to create a package, but I keep running into my own limited understanding on how info-beamer works. I finally found out (was told) that I need to use UDP communication (See great explanation here: Analog Clock demo help)

So now I have some questions using the following files/example:

node.lua:

local var1

util.data_mapper {
  A = function(myParm)
      var1 = myParm
 end
}
print(var1)

service:

from hosted import node
node.send('/myParm:MyData')

Is this the correct way to transfer data?

  • Is ‘A’ just an empty/unused variable?
  • Should it be ‘[myParm]=’ instead of ‘A=’?
  • Or should the service file contain node.send(“A:MyData”) instead
  • Is ‘myParm’ corresponding to /myParm?

I’m trying to figure out what is what. I have never worked with sockets and TCP/UDP - as you probably can see :wink:

No. In that syntax, A isn’t a variable, but just a name (see Lua syntax, field syntax). You would get exactly the same result with:

local exports = {}
exports["A"] = function(myParam) ... end
util.data_mapper(exports)

No. See above.

You need to call:

node.send("/A:MyData")

This will result in the A callback being call with the myParam argument set to "MyData".

No. node.send(“/A:hello”) results in a UDP packet with content root/A:hello. So this will then be picked up by the data_mapper callback named A with anything after the colon in the parameter of that callback.

So in service:

node.send('/A:hello')

and in node.lua

util.data_mapper {
   ["A"] = function(parm)
      var1 = parm
   end 
}

?

Yep. That should work.

1 Like