This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Check if 'address' is a valid IPv4 address. | |
| local function check_ip_address(address) | |
| local a, b, c, d = (address or ""):match("^(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)$") | |
| a, b, c, d = tonumber(a), tonumber(b), tonumber(c), tonumber(d) | |
| return | |
| not not (a and b and c and d) | |
| and (a >= 0 and a <= 255) | |
| and (b >= 0 and b <= 255) | |
| and (c >= 0 and c <= 255) | |
| and (d >= 0 and d <= 255) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local items = { | |
| "Bacon", | |
| "Lettuce", | |
| "Tomato" | |
| } | |
| Controls.list.Choices = items | |
| Controls.list.EventHandler = function(ctl) | |
| print(ctl.String .. " has been selected!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| json = require("rapidjson") -- Load the rapidjson library to parse the responses. | |
| queryTimer = Timer.New() | |
| -- Setup your server details here: | |
| Server = { | |
| Address = "127.0.0.1", -- The address of the server | |
| --Port = 80, -- Optional, the port to connect on. Defaults to 80. | |
| Timeout = 5, -- Time to wait for a responce before throwing an error. | |
| QueryInterval = 10 -- How often to poll the endpoint. This should probably be longer than the timeout. | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| thisCoreSNMP = SNMPSession.New(SNMP.SessionType.V2c) | |
| thisCoreSNMP:setHostName(Network.Interfaces()[1].Address) | |
| thisCoreSNMP:setCommunity("public") | |
| thisCoreSNMP:startSession() | |
| function mySNMPCallback(response) | |
| if response.Error then | |
| error(("There was an SNMP error: %s"):format(d.Error)) | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data = "\x00\x00\x02\x02\x00" | |
| local function modulo( data ) | |
| local checksum = 0 | |
| for _, byte in ipairs( table.pack( data:byte( 1, #data ) ) ) do | |
| checksum = ( checksum + byte ) % 256 | |
| end | |
| return string.char( checksum ) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| json = require("rapidjson") | |
| myData = { | |
| valuea = "This is value a", | |
| valueb = "This is value b", | |
| valuec = "This is value c", | |
| } | |
| -- | |
| -- We can create/overwrite a file like this: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Generic Radio Group Constructor. | |
| local function radio(controls, allowOff) | |
| local handlers = {} | |
| -- Radio logic function. | |
| local function doRadio(control) | |
| local currentIdx = 0 | |
| for i, v in ipairs(controls) do | |
| local initialValue = v.Boolean | |
| v.Boolean = v == control and (not allowOff and true or control.Boolean) |