I have the following super simple code.
------------------------------------
log('AAAAAAA')
sUID = 'dtCSV_UID' .. '_' .. sCurrTag .. 'x'
log('BBBBBBB: ' .. sUID)
iLastTime = tonumber(storage.get(sUID, 0))
log('CCCCCCC')
The code never gets to point 'CCCCCC'.
It produces the following output in the log:
* string: AAAAAAA
* string: BBBBBBB: dtCSV_UID_HEATING_CTRL_VARx
(and nothing more)
The tonumber function call is really not needed and is meant to be a safeguard to force the value from storage.get into a number.
If I remove the "tonumber" and just use the simpler form:
iLastTime = storage.get(sUID, 0)
Then everything works fine.
The error log shows the following:
User script:34: bad argument #2 to 'tonumber' (number expected, got string)
stack traceback: [C]: in function 'tonumber' User script:34: in main chunk
Why is this?
Isn't the whole point of tonumber to convert a number or string to a number?
From the manual (on the tonumber function):
"Tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil."
------------------------------------
log('AAAAAAA')
sUID = 'dtCSV_UID' .. '_' .. sCurrTag .. 'x'
log('BBBBBBB: ' .. sUID)
iLastTime = tonumber(storage.get(sUID, 0))
log('CCCCCCC')
The code never gets to point 'CCCCCC'.
It produces the following output in the log:
* string: AAAAAAA
* string: BBBBBBB: dtCSV_UID_HEATING_CTRL_VARx
(and nothing more)
The tonumber function call is really not needed and is meant to be a safeguard to force the value from storage.get into a number.
If I remove the "tonumber" and just use the simpler form:
iLastTime = storage.get(sUID, 0)
Then everything works fine.
The error log shows the following:
User script:34: bad argument #2 to 'tonumber' (number expected, got string)
stack traceback: [C]: in function 'tonumber' User script:34: in main chunk
Why is this?
Isn't the whole point of tonumber to convert a number or string to a number?
From the manual (on the tonumber function):
"Tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil."