Problem with utils.stringSplit

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
Sagitarius
Posts: 7
Joined: Monday 07 January 2019 14:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Problem with utils.stringSplit

Post by Sagitarius »

Hi Team,
had a first look on utils.stringSplit an copied the script below from forum, but it does not
work, I always get
2021-05-17 08:54:00.332 Status: dzVents: Error (2.4.19): ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:12: attempt to call field 'stringSplit' (a nil value)

Can one of you assist?
BTW I tested some more scripts found at this forum, get always the same error message
Many thanks.

Code: Select all

return {
    active = true,
	on = {
        timer =
        {
            'every 1 minutes'
        },
    },
	execute = function(dz)
	    
    local myString = "A-B-C-D"
   myTable = dz.utils.stringSplit(myString,"-")

    for idx, val in pairs(myTable) do
     dz.log(idx..val)
    end

end
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Problem with utils.stringSplit

Post by waaren »

Sagitarius wrote: Monday 17 May 2021 12:10 ad a first look on utils.stringSplit an copied the script below from forum, but it does not work, I always get
2021-05-17 08:54:00.332 Status: dzVents: Error (2.4.19): ...domoticz/scripts/dzVents/generated_scripts/Script #1.lua:12: attempt to call field 'stringSplit' (a nil value)
The version you are on is much too old to give proper support on.

What you could do is include the current utils.stringSplit function directly in your script; ike below example.

Code: Select all

return {
    active = true,
    on = {
        timer =
        {
            'every 1 minutes'
        },
    },
    execute = function(dz)

        local function stringSplit(text, sep, convertNumber, convertNil)
            if not(text) then return {} end
            local sep = sep or '%s'
            local include = '+'
            if convertNil then include = '*' end
            local t = {}
            for str in string.gmatch(text, "([^" ..sep.. "]" .. include .. ")" ) do
                if convertNil and str == '' then str = convertNil end
                table.insert(t, ( convertNumber and tonumber(str) ) or str)
            end
            return t
        end

       local myString = "A-B-C-D"
       local myTable = stringSplit(myString,"-")

        for idx, val in pairs(myTable) do
            dz.log(idx .. ': ' .. val)
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest