the file qwcsysval will be loaded from disk thru the SAVRST operations.
the file can only be modified by an approved interface.
that is yet to be done, I will finally be working on iup.GridBox to do this.
(that endeavor, I don't wonder; will be threads among millions.
essentially it is a complement of working constants used by my programs.
I 'unroll' it from the table into standalone values.
The code works fine, and does create global variables, but has a problem.
since at present, I am declaring them individually in the require(s), my code all works
as I decide on names and values and so on, I can go into the saved table with an editor,
and fix things or add things to test. I think during normal save restores the problem that I am creating would manifest itself differently. And this is a rather artificial but not impossible happenstance.
However, trying to bulletproof it and handle errors at the earliest step, this is giving me fits:
["qwc_GPS_time_ERR"] = y8600,
it really should be just the number 8600.
however, it must resolve to null and the key does not even enter my for do
is my code not correct or is there some clever way to get this keyval pair?
(the issue here is one of program timing) that key could be used 3 or 4 require "levels" deep in my code and only under such conditions that processing is almost finished before it becomes a problem)
Ideas?
Code: Select all
--[[
require 'QSYS'
require 'QSYS_PTH'
__ipath = rtvpath()
qgdp = __ipath.global()
require 'QSYS_SAVRST'
rtvTBL()
** in QSYS:
local qcwp, qwcsysval = rtvTBL(('%s%s'):format(qgdp, 'qwcsysval.dat'))
that gets the table that is provided here as qwcsysval
]]
qwcsysval =
{
["qwc_GPS_BASE_LATI"] = 46.23997959960783,
["qwc_GPS_BASE_LONG"] = -95.95777396029047,
["qwc_GPS_time_ERR"] = y8600,
["qwc_GPS_miles_ERR"] = '',
["qwc_GPS_direction_ERR"] = '****',
["qwc_GPS_duration_ERR"] = 8686,
["qprt_spool_browser"] = 'EditPadLite8.exe',
}
--[[unroll table entries into program]]
local function reflect(_source)
local _sink = ''
local _var
for _key, _val in pairs(_source) do
_keytyp = type(_key)
_valtyp = type(_val)
if type(_val) == 'string' then _val = ("'%q'"):format(_val) end
_var = ('%s = %s\n'):format(_key, _val)
_sink = ('%s%s'):format(_sink, _var)
end
local _rc, _mat, _err = pcall(loadstring, _sink)
if _err then
error(('QSYS.reflect: sysval:\n %s\n %s\n corrupt'):format(_err, type(_mat))) end
_mat()
return
end -- fn reflect
--[[
see header comments
table provided in QSYS by file load
rtvTBL(qwcp)
]]
reflect(qwcsysval)
return