I am building a table, a typical example of what it should look like is:
__ptr[1] =
{
_cp = { '_cp_01', (user data) }, -- rcd lookup handle, rcd handle(pointer)
_dp[3] =
{
[3] = {'_dp_03', (user data)}, -- fld dta lookup handle, field handle(pointer)
[7] = {'_dp_07', (user data)}, -- fld dta lookup handle, field handle(pointer)
},
__ptr[2] =
{
_cp = {'cp_02', (user data) }, -- rcd lookup handle, rcd handle(pointer)
_dp[5] =
{
[3] = {'_dp_03', (user data)}, -- fld dta lookup handle, field handle(pointer)
[7] = {'_dp_07', (user data)}, -- fld dta lookup handle, field handle(pointer)
},
__ptr[3] =
{
_cp = { '_cp_03', (user data) }, -- rcd lookup handle, rcd handle(pointer)
},
-- __ptr defined in _sfl_WRITE as:
-- local __ptr = {} -- record handles, fld dta handles
-- which calls the function:
function _set_sfl_ptr(matobj, row, col, __ptr, _OBJ)
local _hdl
local _hnam
-- space pointer subfile record number key pointers
--[[debug values are:
matobj = "_cp"
row = 1
col = 1
__ptr => (table .0)
_OBJ = (iup user data)
_hnam = "_cp_1"
_hdl = (user data)
]]
if matobj == '_cp' then
_hnam = string.format('%s_%s', matobj, row)
iup.SetHandle(_hnam, _OBJ)
_hdl = iup.GetHandle(_hnam)
--[[
__ptr[row][matobj] = {_hnam = _hnam, _hdl = _hdl}
__ptr[row].matobj = {_hnam = _hnam, _hdl = _hdl}
__ptr[row]._cp = {_hnam = _hnam, _hdl = _hdl}
__ptr[row]._cp._hnam = _hnam
__ptr[row]._cp._hdl = _hdl
******** any of these variations results in:
******** attempt to index field '?' (a nil value)
]]
return __ptr
end
>>>> I have fought with this for 5 days, there must be some simple glaring coding error that I am not seeing.
-- [[ you can ignore this, it is for the _dp array, and I am sure it suffers the same malady as the _cp table.
-- data pointer subfile record number field and offset pointers
if matobj == '_dp' then
_hnam = string.format('%s_%s_%s', matobj, row, col)
iup.SetHandle(_hnam, _OBJ)
_hdl = iup.GetHandle(_hnam)
__ptr[row]._dp[col] = {_hnam = _hnam, _hdl = _hdl}
__ptr[row].matobj[col] = {_hnam = _hnam, _hdl = _hdl}
return __ptr
end
]]
end
* coding adding entries to a table subtable
coding adding entries to a table subtable
FH V.6.2.7 Win 10 64 bit
- tatewise
- Megastar
- Posts: 27085
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: coding adding entries to a table subtable
Ron, I have seen you successfully code this scenario before.
The table __ptr is initially empty so __ptr[row] does not exist and raises the error message.
You need:
if not __ptr[row] then __ptr[row] = {} end
Then your first option will work:
__ptr[row][matobj] = {_hnam = _hnam, _hdl = _hdl}
The table __ptr is initially empty so __ptr[row] does not exist and raises the error message.
You need:
if not __ptr[row] then __ptr[row] = {} end
Then your first option will work:
__ptr[row][matobj] = {_hnam = _hnam, _hdl = _hdl}
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry