Js variables & Lua variables - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Js variables & Lua variables (/showthread.php?tid=683) |
Js variables & Lua variables - Jonathan - 17.03.2017 Hello ! I am actually able to put a lua value into a js variable using a piece of code that i found on this forum : var js_variable = '<? write(lua_variable) ?>' If someone could explain to me what is this write function ... and why don't we need the ';' here ? Also, i would like to do the opposite but when i try something like : '<? lua_variable ?>' = js_variable; That does not work... Thx for help ! RE: Js variables & Lua variables - Erwin van der Zwart - 17.03.2017 Hi, This is a sample how to write var into JS as client side LUA and yes you need ; if you have more lines. You can't write back like this as the data is just a result from the server with option to have additional LUA data in it. The data is static so if you want new data you have to request it from the server again. Sending back JS to LUA must be done by http post with arguments or json form data to the .lp file and handle the posted data in LUA on server also from .lp file. You can include your user libs to the .lp and have full bidirectional communication by get/post data between server and client. You can use all LUA functions inside the .lp including sockets and ports and that allows you to do http/udp/tcp/bacnet/modbus/enocean requests from your clients javascript engine. Offcourse your .lp file must handle all the requests and translate it to LUA requests or JSON posts back to the client. There is also a option to use the websocket connection by adding the localbus.js and that allows you to read and write to the knx engine. This way you can have live events without polling or posting all the time. BR, Erwin RE: Js variables & Lua variables - buuuudzik - 20.03.2017 (17.03.2017, 16:12)Jonathan Wrote: var js_variable = '<? write(lua_variable) ?>' Which lua variable did you connect with your js script? Is this lua variable from .lp which you created before or is this a current value of some global variable which is available from every script like storage? RE: Js variables & Lua variables - Jonathan - 21.03.2017 Thx for your response Erwin buuuudzik, it's a variable from a .lua (17.03.2017, 17:19)Erwin van der Zwart Wrote: There is also a option to use the websocket connection by adding the localbus.js and that allows you to read and write to the knx engine. This way you can have live events without polling or posting all the time. I haven't found any documentation on this, could you explain me which functions can be used with localbus ? RE: Js variables & Lua variables - Erwin van der Zwart - 21.03.2017 Hi, You can use the localbus like this: 1) First you need to include the JS lib Code: <head> 2) You need to start (init) the localbus Code: <script> 3) Now you can listen to all or a single KNX events like this Code: <script> 4) Or update / write to a object like this Code: <script> 5) You can also listen to storage change events like this Code: <script> Don't know if we can also simply write to the storage by using this, maybe admin can say something about that Code: <script> Edit: Tested yesterday evening the above option to write to storage and is not possible as far as i can tell... BR, Erwin RE: Js variables & Lua variables - Jonathan - 22.03.2017 Tyvm Erwin, this will be helpful ! I don't want to ask you too many things, but could you also explain me how do you do in Lua for retrieving a POST variable ? I can manage to post with $.post but i don't know how to get them back in lua... RE: Js variables & Lua variables - admin - 23.03.2017 Have a look at apps docs here (LP scripts section): http://forum.logicmachine.net/showthread.php?tid=85 RE: Js variables & Lua variables - Jonathan - 28.03.2017 It's all good, tyvm |