# Using util.data\_mapper in Lua

**URL:** <https://community.info-beamer.com/t/using-util-data-mapper-in-lua/877>\
**Category:** How-to and Tutorials\
**Created:** [May 1, 2020, 12:51pm UTC](https://community.info-beamer.com/t/using-util-data-mapper-in-lua/877 "2020-05-01T12:51:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [May 1, 2020, 12:51pm UTC](https://community.info-beamer.com/t/using-util-data-mapper-in-lua/877/1 "2020-05-01T12:51:03Z")

</div>

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](https://community.info-beamer.com/t/analog-clock-demo-help/869/23))

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

**node.lua:**

```lua
local var1

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

```

**service:**

```python
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 😉

---

<div class="post-metadata">

**Author:** ![infobeamer-fw](https://community.info-beamer.com/user_avatar/community.info-beamer.com/infobeamer-fw/32/3_2.png) [@infobeamer-fw](https://community.info-beamer.com/u/infobeamer-fw)\
**Post date:** [May 1, 2020, 1:02pm UTC](https://community.info-beamer.com/t/using-util-data-mapper-in-lua/877/2 "2020-05-01T13:02:00Z")

</div>

> [@Wassini](#):
>
> Is ‘A’ just an empty/unused variable?

No. In that syntax, A isn’t a variable, but just a name (see [Lua syntax](https://www.lua.org/manual/5.1/manual.html#8), `field` syntax). You would get exactly the same result with:

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

```

> [@](#):
>
> Should it be ‘[myParm]=’ instead of ‘A=’?

No. See above.

> [@](#):
>
> Or should the service file contain _node.send(“A:MyData”)_ instead

You need to call:

```python
node.send("/A:MyData")

```

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

> [@](#):
>
> Is ‘myParm’ corresponding to /myParm?

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.

---

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [May 1, 2020, 1:14pm UTC](https://community.info-beamer.com/t/using-util-data-mapper-in-lua/877/3 "2020-05-01T13:14:52Z")

</div>

So in service:

```lua
node.send('/A:hello')

```

and in node.lua

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

```

?

---

<div class="post-metadata">

**Author:** ![infobeamer-fw](https://community.info-beamer.com/user_avatar/community.info-beamer.com/infobeamer-fw/32/3_2.png) [@infobeamer-fw](https://community.info-beamer.com/u/infobeamer-fw)\
**Post date:** [May 1, 2020, 1:15pm UTC](https://community.info-beamer.com/t/using-util-data-mapper-in-lua/877/4 "2020-05-01T13:15:42Z")

</div>

Yep. That should work.
