Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
error:
code that produces it:
--[[
I use iup.matrix instead which can be found in the IUP Controls under Additional + iupControls + iupMatrix
In its documentation under Utility Functions it mentions these Lua functions:
ih:setcell(lin, col: number, value: string)
ih:getcell(lin, col: number) -> (cell: string)
if type(_usrdfn) ~= 'table' then
error('definition not a table')
end
if type(_tbl) ~= 'table' then
error('display not a table')
end
numdiv = #_usrdfn['fld'] + 2
local numbuf = #_usrdfn['buf'] + 2
if numdiv ~= numbuf then
error('mismatch in user defined fields and buffers')
end
for k, v in ipairs(_usrdfn['buf']) do
local _ub = _usrdfn['buf'][k]
local inbuf
for , _y in pairs({'o', 'io', 'var',}) do
if _ub == _y then
_inbuf = true
break
end
end
if not _inbuf then
error('buffer value is not valid')
end
end
for _k ,_v in ipairs(_usrdfn['fld']) do
_hdr_col = ('%s%s '):format(_hdr_col, _v)
-- check for is %q etc
end
-- if not indexed index
for k, v in pairs(_tbl) do
sflsiz = sflsiz + 1
if type(v) == 'table' then
if type(k) == 'string' then
istree = true
end
end
end
hdlix = string.len(sflsiz)
hdlfmt = ('%s%i%s'):format('%0', hdlix, 'i')
return
end
local function _get_io()
if _OBJ._buf == 'io' then
_OBJ._io = 'io'
_OBJ.readonly = 'NO'
return
end
if _OBJ._buf == 'var' then
-- send key of file and fld decide if it should be 'io' or 'o'
-- 'u' for planned expansion
local _buf = cb_io('u', _OBJ._key, _OBJ._fld)
if _buf == 'io' then
_OBJ.readonly = 'NO'
return
end
if _buf == 'o' then
_OBJ.readonly = 'YES'
return
end
error("cb_io returned value that is not 'o' or 'io'.")
end
end -- fn _get_io
function _set_ptr(row, key, hdl, _OBJ)
-- data pointer subfile
-- bld value handles
if not (__ptr[row][key]) then
__ptr[row][key] = ''
end -- exists
iup.SetHandle(hdl, _OBJ)
ptr[row][key] = hdl
-- return ptr -- upvalue must return it
end -- fn _set_ptr
--[[
_sfl._ptr = __ptr
return _sfl
end
]]
function _get_ptr(row, key)
-- get handle return value
return iup.GetHandle(__ptr[row][key])
end -- fields in the row
function set_io_IO(options)
local IOfld = iup.text
{
multiline = options.multiline or 'NO',
readonly = options.readonly or 'NO'
}
if options.value then
IOfld.value = options.value
else
IOfld.value = iup.NULL
end
if options.visiblecolumns then
IOfld.visiblecolumns = options.visiblecolumns
end
if options.font then
IOfld.font = options.font
end
if options.filter then
IOfld.filter = options.filter
end
if options.mask then
IOfld.mask = options.mask
end
return IOfld
end
function set_io_O(options)
local Ofld = iup.label
{
title = options.value or iup.NULL,
value = options.value or iup.NULL,
}
if options.font then
Ofld.font = options.font
end
if options.size then
Ofld.size = options.size
end
-- for KEY, _ in pairs(tbl) do -- = ARRAY
for k, v in pairs(_tbl) do
row = row + 1
local opt = set_io_IO
{
name = opt,
value = '',
visiblecolumns = 1,
filter = 'NUMBER',
mask = IUP_MASK_INT,
font = 'Courier New, 10',
readonly = 'NO',
}
_set_ptr(row, 'opt', ('%s%s'):format('opt_', hdlfmt:format(row)), opt)
_sfl:append(opt)
local _key = set_io_O
{
name = ('%s%s'):format('key_', hdlfmt:format(row)),
value = k,
font = 'Courier New, 10',
}
_sfl:append(_key)
_set_ptr(row, 'key', key.name, key.value)
for ix, ufld in ipairs(_usrdfn['fld']) do
local _ufld = set_io_O
{
name = _usrdfn.fld[ix], -- FIELD NAME
value = _tbl[k][ufld], -- FIELD VALUE from _tbl
readonly = 'YES', -- YES, NO > crt_IO('var' > cb_io)
multiline = 'NO', -- for now, one line.
font = 'Courier New, 10',
}
_sfl:append(_ufld)
end
end
return _sfl
end
function _sfl_CTL(_WS)
local hdrcol =
iup.label
{
title = _hdr_col,
font = 'Courier New, 10',
gaplin = '0',
gapcol = '0',
expand = 'NO',
alignmentcol = 'ALEFT',
alignmentlin = 'ATOP',
multiline = 'NO',
}
local hdr_col = iup.hbox{hdrcol}
local sfl = iup.vbox{iup.scrollbox{_WS}}
local btn_ok = iup.button
{
name = 'ENTER',
title = 'ENTER',
action = function(self)
_sfl_READC()
rtx.rc = WS_ENTER
rtx.TAG = TAG
return iup.CLOSE
end
}
local btn_cancel = iup.button
{
name = 'CANCEL',
title = 'CANCEL',
action = function(self)
rtx.rc = WS_CANCEL
rtx.TAG = ''
return iup.CLOSE
end
}
local fn_keys = iup.hbox{btn_ok, btn_cancel}
local _ws_dsp = iup.dialog
{
font = 'Courier New, 10',
title = '(y = mx + b)',
--*add
iup.vbox{iup.hbox{hdr_col}, sfl, iup.hbox{fn_keys}},
}
iup.Map(_ws_dsp)
local _cz = _ws_dsp.charsize -- '8x16'
local _sz = _WS.size -- get size of the table
local _w, _h = _sz:match('(%d+)X-x')
_ws_dsp.size = ('%sx%s'):format(_w * 1.5, 200) -- table width x 1.5 and fixed height
return _ws_dsp
end -- fn _sfl_CTL
function _sfl_READC()
--[[
iup.GetChild
iup.GetNextChild
iup.GetBrother
iup.GetParent
Another option is to use the NAME attribute.
You set it on the element you want then use
IupGetDialogChild to retrieve the element given the NAME value.
]]
for row = 1, _WS.numlin do
-- format handle using hdlix
opt = ('%s%s'):format('opt', hdlfmt:format(row))
key = ('%s%s'):format('key', hdlfmt:format(row))
ptropt = _get_ptr(row, _opt)
ptrkey = _get_ptr(row, _key)
local ent = iup.GetChild(_WS, (row - 1) * _WS.numdiv)
local opt = iup.GetBrother(ent) -- opt.value how?
local key = iup.GetBrother(_opt) -- key.value how?
if opt > '' then
rtx[rtx + 1] = {opt = opt, key = key}
end
end
end
-- EXEC()
if not _WS then
vfy_parms(_usrdfn, _tbl)
_WS = _sfl_WRITE(_tbl)
_ws_dsp = _sfl_CTL(_WS)
end
error:
code that produces it:
--[[
I use iup.matrix instead which can be found in the IUP Controls under Additional + iupControls + iupMatrix
In its documentation under Utility Functions it mentions these Lua functions:
ih:setcell(lin, col: number, value: string)
ih:getcell(lin, col: number) -> (cell: string)
I use those to set and get cell values in iup.matrix and maybe the same work for iup.gridbox. e.g. gbox:setcell( 1, 2, 3 ) x = gbox:getcell( 1, 2 ) http://webserver2.tecgraf.puc-rio.br/iup/en/ctrl/iupmatrix.html http://webserver2.tecgraf.puc-rio.br/iup/en/elem/iuptree.html ]]
require 'iuplua' iup.SetGlobal('CUSTOMQUITMESSAGE', 'YES') iup.SetGlobal('UTF8MODE','YES') iup.SetGlobal('UTF8MODE_FILE', 'NO')
WS_Abort = 'Abort' WS_CANCEL = false WS_Cancel = 'Cancel' WS_ENTER = true WS_Ignore = 'Ignore' WS_OK = 'OK' WS_Retry = 'Retry'
WS_ERR = 2 WS_YES = 'Yes' WS_NO = 'No'
-- local _ptr = {} -- local row = 0
local __ptr = {} local rtx = {} -- return changed records via callback local numdiv = 0 local sflsiz = 0 local _hdr_col = 'Opt KEY ' local istree
local hdlfmt local hdlix = 0 local owid = 0 local row = 0
_tbl = { ["adr"] = {["M"] = 0,["X"] = 4,["B"] = 1,}, ["age"] = {["M"] = 0,["X"] = 6,["B"] = 0,}, ["ahn"] = {["M"] = 0,["X"] = 6,["B"] = 0,}, ["ara"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["arm"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["bin"] = {["M"] = 0,["X"] = 4,["B"] = 4,}, ["cem"] = {["M"] = 0,["X"] = 4,["B"] = 4,}, ["dir"] = {["M"] = 0,["X"] = 4,["B"] = 2,}, ["dob"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["dod"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["dst"] = {["M"] = 0,["X"] = 4,["B"] = 4,}, ["dup"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["era"] = {["M"] = 0,["X"] = 1,["B"] = 0,}, ["err"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["erx"] = {["M"] = 0,["X"] = 1,["B"] = 0,}, ["fct"] = {["M"] = 0,["X"] = 8,["B"] = 0,}, ["fid"] = {["M"] = 0,["X"] = 6,["B"] = 0,}, ["gen"] = {["M"] = 0,["X"] = 6,["B"] = 0,}, ["gli"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["gpi"] = {["M"] = 0,["X"] = 4,["B"] = 4,}, ["gps"] = {["M"] = 0,["X"] = 1,["B"] = 4,}, ["iid"] = {["M"] = 0,["X"] = 6,["B"] = 0,}, ["lbl"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["loc"] = {["M"] = 0,["X"] = 4,["B"] = 4,}, ["mdt"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["mml"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["nam"] = {["M"] = 0,["X"] = 4,["B"] = 1,}, ["nct"] = {["M"] = 0,["X"] = 8,["B"] = 0,}, ["ord"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["oth"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["plc"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["ptg"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["ptr"] = {["M"] = 0,["X"] = 1,["B"] = 0,}, ["rgn"] = {["M"] = 0,["X"] = 4,["B"] = 4,}, ["rlt"] = {["M"] = 0,["X"] = 4,["B"] = 4,}, ["rmn"] = {["M"] = 0,["X"] = 6,["B"] = 0,}, ["rnk"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["rte"] = {["M"] = 0,["X"] = 4,["B"] = 2,}, ["sdf"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["sep"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["set"] = {["M"] = 0,["X"] = 6,["B"] = 0,}, ["sex"] = {["M"] = 0,["X"] = 1,["B"] = 0,}, ["src"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["svc"] = {["M"] = 0,["X"] = 4,["B"] = 2,}, ["tim"] = {["M"] = 0,["X"] = 3,["B"] = 0,}, ["trk"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["war"] = {["M"] = 0,["X"] = 4,["B"] = 0,}, ["web"] = {["M"] = 0,["X"] = 4,["B"] = 4,}, ["yr"] = {["M"] = 0,["X"] = 1,["B"] = 0,}, }
_usrdfn = { -- optsiz = (1 or 2 ' '), ['fld'] = {[1] = 'M', [2] = 'X', [3] = 'B',}, ['buf'] = {[1] = 'var', [2] = 'o', [3] = 'o',}, }
function vfy_parms(_usrdfn, _tbl)
if type(_usrdfn) ~= 'table' then error('definition not a table') end if type(_tbl) ~= 'table' then error('display not a table') end
numdiv = #_usrdfn['fld'] + 2 local numbuf = #_usrdfn['buf'] + 2 if numdiv ~= numbuf then error('mismatch in user defined fields and buffers') end
for k, v in ipairs(_usrdfn['buf']) do local _ub = _usrdfn['buf'][k] local inbuf for , _y in pairs({'o', 'io', 'var',}) do if _ub == _y then _inbuf = true break end end if not _inbuf then error('buffer value is not valid') end end
for _k ,_v in ipairs(_usrdfn['fld']) do _hdr_col = ('%s%s '):format(_hdr_col, _v) -- check for is %q etc end
-- if not indexed index for k, v in pairs(_tbl) do sflsiz = sflsiz + 1 if type(v) == 'table' then if type(k) == 'string' then istree = true end end end hdlix = string.len(sflsiz) hdlfmt = ('%s%i%s'):format('%0', hdlix, 'i') return end
local function _get_io()
if _OBJ._buf == 'io' then _OBJ._io = 'io' _OBJ.readonly = 'NO' return end
if _OBJ._buf == 'var' then -- send key of file and fld decide if it should be 'io' or 'o' -- 'u' for planned expansion local _buf = cb_io('u', _OBJ._key, _OBJ._fld)
end end -- fn _get_io
function _set_ptr(row, key, hdl, _OBJ) -- data pointer subfile -- bld value handles if not (__ptr[row][key]) then
__ptr[row][key] = '' end -- exists
iup.SetHandle(hdl, _OBJ) ptr[row][key] = hdl -- return ptr -- upvalue must return it end -- fn _set_ptr
--[[ _sfl._ptr = __ptr return _sfl end ]]
function _get_ptr(row, key) -- get handle return value return iup.GetHandle(__ptr[row][key]) end -- fields in the row
function set_io_IO(options)
local IOfld = iup.text { multiline = options.multiline or 'NO', readonly = options.readonly or 'NO' }
if options.value then IOfld.value = options.value else IOfld.value = iup.NULL end if options.visiblecolumns then IOfld.visiblecolumns = options.visiblecolumns end if options.font then IOfld.font = options.font end if options.filter then IOfld.filter = options.filter end if options.mask then IOfld.mask = options.mask end
return IOfld end
function set_io_O(options) local Ofld = iup.label { title = options.value or iup.NULL, value = options.value or iup.NULL, } if options.font then Ofld.font = options.font end if options.size then Ofld.size = options.size end
return Ofld end
function _sfl_WRITE(_tbl)
local _sfl = iup.gridbox { numdiv = numdiv, dropdown = 'NO', expandchildren = 'NO', gaplin = '1', gapcol = '16', margin = '4x4', alignmentcol = 'ALEFT', alignmentlin = 'ABOTTOM', orientation = 'HORIZONTAL', }
-- for KEY, _ in pairs(tbl) do -- = ARRAY for k, v in pairs(_tbl) do row = row + 1
end return _sfl end
function _sfl_CTL(_WS)
local hdrcol = iup.label { title = _hdr_col, font = 'Courier New, 10', gaplin = '0', gapcol = '0', expand = 'NO', alignmentcol = 'ALEFT', alignmentlin = 'ATOP', multiline = 'NO', } local hdr_col = iup.hbox{hdrcol}
local sfl = iup.vbox{iup.scrollbox{_WS}}
local btn_ok = iup.button { name = 'ENTER', title = 'ENTER', action = function(self) _sfl_READC() rtx.rc = WS_ENTER rtx.TAG = TAG return iup.CLOSE end }
local btn_cancel = iup.button { name = 'CANCEL', title = 'CANCEL', action = function(self) rtx.rc = WS_CANCEL rtx.TAG = '' return iup.CLOSE end } local fn_keys = iup.hbox{btn_ok, btn_cancel}
local _ws_dsp = iup.dialog { font = 'Courier New, 10', title = '(y = mx + b)', --*add iup.vbox{iup.hbox{hdr_col}, sfl, iup.hbox{fn_keys}}, }
iup.Map(_ws_dsp) local _cz = _ws_dsp.charsize -- '8x16' local _sz = _WS.size -- get size of the table local _w, _h = _sz:match('(%d+)X-x') _ws_dsp.size = ('%sx%s'):format(_w * 1.5, 200) -- table width x 1.5 and fixed height
return _ws_dsp end -- fn _sfl_CTL
function _sfl_READC() --[[ iup.GetChild iup.GetNextChild iup.GetBrother iup.GetParent
Another option is to use the NAME attribute. You set it on the element you want then use IupGetDialogChild to retrieve the element given the NAME value. ]]
for row = 1, _WS.numlin do -- format handle using hdlix opt = ('%s%s'):format('opt', hdlfmt:format(row)) key = ('%s%s'):format('key', hdlfmt:format(row)) ptropt = _get_ptr(row, _opt) ptrkey = _get_ptr(row, _key) local ent = iup.GetChild(_WS, (row - 1) * _WS.numdiv) local opt = iup.GetBrother(ent) -- opt.value how? local key = iup.GetBrother(_opt) -- key.value how? if opt > '' then rtx[rtx + 1] = {opt = opt, key = key} end end end
-- EXEC() if not _WS then vfy_parms(_usrdfn, _tbl) _WS = _sfl_WRITE(_tbl) _ws_dsp = _sfl_CTL(_WS) end
_ws_dsp:show(iup.CENTER, iup.CENTER) iup.MainLoop() _ws_dsp:destroy()
return