Translating code between Lua and JS - 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: Translating code between Lua and JS (/showthread.php?tid=1577) |
Translating code between Lua and JS - buuuudzik - 06.09.2018 Hi, I am currently translate some code which I've created in NodeJS for controlling Somfy blinds into Lua to use it by LM. Could you help me with translate some functions? Code: parseInt(hexValue[i], 16) And also how can I convert hex string to hex? Code: '7FF2FAB843FA000000FFFE065D' => string.char(0x7F,0xF2,0xFA,0xB8,0x43,0xFA,0x00,0x00,0x00,0xFF,0xFE,0x06,0x5D) RE: Translating code between Lua and JS - admin - 06.09.2018 Code: number = tonumber(input, 16) Convert hex string to raw binary, make sure second argument is true otherwise zero bytes will be ignored: Code: str = lmcore.hextostr('7FF2FAB843FA000000FFFE065D', true) RE: Translating code between Lua and JS - buuuudzik - 07.09.2018 I've translated whole code and now it produces correct string frame, but I've found some ~bug/~lack in log() function which could be produced by such code: Code: S01_up = string.char(0x7F,0xF2,0xFA,0xFF,0x00,0x00,0x8E,0x5E,0xFA,0xFE,0xFE,0x07,0x4C) And this is from log(): Code: * arg: 1 So it looks that log() doesn't notice the end of first variable. RE: Translating code between Lua and JS - admin - 07.09.2018 use loghex if you want to get readable binary strings RE: Translating code between Lua and JS - buuuudzik - 07.09.2018 Nice Thanks |