-- This file: -- https://anggtwu.net/LUA/DiagStacks1.lua.html -- https://anggtwu.net/LUA/DiagStacks1.lua -- (find-angg "LUA/DiagStacks1.lua") -- Author: Eduardo Ochs -- -- This file implements the stacks used by: -- (find-dn6 "diagforth.lua" "diagram") -- (find-dn6 "diagforth.lua" "enddiagram") -- -- The main stack, `ds', is based on the Forth data stack - see: -- (find-miniforthgempage 3 "DS={ 5 }") -- -- The items in `ds' are usually nodes and arrows, -- that are also kept in the tables `nodes' and `arrows', -- and are reset every time that we run "diagram" and "enddiagram". -- -- There is also a "metastack" called `depths', used by "((" and "))": -- (find-dednatslides2018page 10) -- (find-dednatslides2018text 10) -- -- Based on: (find-dn6 "diagstacks.lua") -- Used by: (find-angg "LUA/DiagForth1.lua") -- «.nodes» (to "nodes") -- «.nodes-test» (to "nodes-test") -- «.arrows-test» (to "arrows-test") require "Stack1" -- (find-angg "LUA/Stack1.lua") ds = Stack.new() depths = Stack {ds=ds} -- (find-angg "LUA/Stack1.lua" "Stack" "metastacks") -- _ -- _ __ ___ __| | ___ ___ -- | '_ \ / _ \ / _` |/ _ \/ __| -- | | | | (_) | (_| | __/\__ \ -- |_| |_|\___/ \__,_|\___||___/ -- -- «nodes» (to ".nodes") -- See: (find-angg "LUA/DiagForth1.lua" "DiagForth" "ds:push(nodes[word])") -- (find-angg "LUA/DiagForth1.lua" "2D-and-2Dx" "storenode") -- nodes = VTable {} -- has numeric and string indices storenode = function (node) table.insert(nodes, node) node.noden = #nodes -- ".noden" acts as a numeric id. if node.tag then -- ".tag" acts as a string id. nodes[node.tag] = node -- "midpoint" creates nodes without ".tag"s. end return node end -- «nodes-test» (to ".nodes-test") --[[  (eepitch-lua51)  (eepitch-kill)  (eepitch-lua51) dofile "DiagStacks1.lua" ds:push(storenode {x=4, y=5, tag="A"}) ds:push(storenode {x=6, y=7, tag="B"}) ds:push(storenode {x=8, y=9}) = nodes --]] -- «arrows» (to ".arrows") -- See: (find-angg "LUA/DiagForth1.lua" "arrows" "storearrow") -- (find-angg "LUA/DiagForth1.lua" "enddiagram") -- (find-angg "LUA/DiagTeX1.lua" "diagxy_def_diag") -- arrows = VTable {} -- has only numeric indices storearrow = function (arrow) table.insert(arrows, arrow) arrow.arrown = #arrows return arrow end -- «arrows-test» (to ".arrows-test") --[[  (eepitch-lua51)  (eepitch-kill)  (eepitch-lua51) dofile "DiagStacks1.lua" dofile "DiagTeX1.lua" Stack.__index.tostring = mytostringv ds:push(storenode {x=4, y=5, tag="A"}) ds:push(storenode {x=6, y=7, tag="B"}) ds:push(storenode {x=8, y=9, tag="C"}) ds:push(storearrow(DxyArrow {from=1, to=2, shape="->"})) ds:push(storearrow(DxyArrow {from=2, to=3, shape="->"})) = nodes = arrows = diagxy_def_diag("Foo") --]] -- Local Variables: -- coding: utf-8-unix -- End: