Skip to content
adamwagner edited this page Jan 17, 2021 · 9 revisions

##.wiki Inspiration

state management concepts

See repo for a a short demo of 6 different approaches to statement management:

  1. Behavior machine
  2. functional / redux
  3. qt state machine
  4. state chart
  5. static state

This is similar: https://github.com/cedricporter/lua-statemachine-test/tree/master/framework

Good tutorial on using state charts in lua: https://github.com/Phrogz/LXSC https://github.com/kmarkus/rFSM/blob/master/doc/rFSM-manual.md

Guarded transitions

Guard conditions are expressions which evaluates either to TRUE or FALSE based on extended state variables and event parameters. Guards are used with actions and transitions to dynamically choose if particular action or transition should be executed. Aspects of guards, event parameters and extended state variables are simply to make state machine design much more simple.

More state machine links https://statecharts.github.io/how-to-use-statecharts.html https://statecharts.github.io/concepts.html https://deniskyashif.com/2019/11/20/a-practical-guide-to-state-machines/ https://github.com/krasimir/stent/blob/master/docs/action-handler.md https://www.smashingmagazine.com/2018/01/rise-state-machines/ https://codesandbox.io/embed/lxpjok1w7m https://xstate.js.org/docs/guides/guards.html#guards-condition-functions https://stackoverflow.com/questions/13221168/how-to-implement-a-fsm-finite-state-machine-in-java https://deislabs.io/posts/a-fistful-of-states/ https://raganwald.com/2018/02/23/forde.html https://rclayton.silvrback.com/use-state-machines https://github.com/Phrogz/LXSC https://github.com/orocos-toolchain/rfsm-rtt-example https://github.com/midouest/statechart https://github.com/swordday/lunar/tree/master/lunar/containers https://github.com/xopxe/ahsm

Candidate libs https://github.com/kmarkus/rFSM/blob/master/doc/rFSM-manual.md https://github.com/prakaros/dota2fun/blob/master/utilities/state_chart.lua https://github.com/freedomcondor/luastate/blob/master/State.lua https://statecharts.github.io/concepts.html https://github.com/midouest/statechart https://github.com/maihd/statemachine

DUIL

Dude's User Interface Library, A Love2d GUI Library Two things to note:

#1: Update method sets a good bar for simplicity

function Object:update(dt)
	local x, y, w, h = self:getX(), self:getY(), self:getWidth(), self:getHeight()
	local posChanged = self.previousBounds == nil or self.previousBounds.x ~= x or self.previousBounds.y ~= y
	local sizeChanged = self.previousBounds == nil or self.previousBounds.w ~= w or self.previousBounds.h ~= h
	if posChanged or sizeChanged then
		self.previousBounds = {x=x, y=y, w=w, h=h}
		self:boundsChanged(posChanged, sizeChanged)
	end
	for _, component in pairs(self.components) do
		component:update(self, dt)
	end
	for _, child in pairs(self.children) do
		child:update(dt)
	end
end

#2: Register pattern

local registerableMts = {[Object]=Object, [Component]=Component, [Skin]=Skin}
function DUIL.register(object)
	local mt = Utils.GetMetatableMtRecursive(object, registerableMts)
	if mt == Object then
		assert(type(object.type) == "string")
		DUIL.objects[object.type] = object
	elseif mt == Component then
		assert(type(object.type) == "string")
		DUIL.components[object.type] = object
	elseif mt == Skin then
		assert(type(object.type) == "string")
		DUIL.skins[object.type] = object
	else
		error("Attempt to register an unknown feature. (Invalid metatable)")
	end
end

luakit

- `settings` supports `settings.register()` 
- built custom test runner, which actually seems kinda simple? Interesting that they maintain it in the same repo rather than a git submodule: [link](https://github.com/luakit/luakit/tree/develop/tests)

luarocks

- [rockspec.lua](https://github.com/luarocks/luarocks/blob/master/src/luarocks/type/rockspec.lua) does schema validation.
- somewhat unique module metatable pattern: [results.lua](https://github.com/luarocks/luarocks/blob/master/src/luarocks/results.lua)

z.lua

All one-file approach (2700 loc).

luacheck

Especially the tests & spec/helper.lua

lor

a fast, minimalist web framework. Notable for design pattern used for middleware module.

lain

awesomewm component library. Notable for using gears (dependency injection) see separators.lua

Jumper

Notable for module design pattern. See path.lua

rxi/lite Fantastically modular design. Lots to learn from this:

- https://github.com/rxi/lite/blob/master/data/core/init.lua
- https://github.com/rxi/lite/blob/master/data/core/object.lua
- https://github.com/rxi/lite/blob/master/data/core/common.lua
- https://github.com/rxi/lite/blob/master/data/core/view.lua
- https://github.com/rxi/lite/blob/master/data/core/config.lua

hhtwm/init.lua Probably the best source of inspo, esp. the module.cache = {…} implementation. Note that it uses hs._asm.undocumented.spaces, though, and we'd like to avoid adding another dependency.

megalithic/window.lua

window_set.lua Seems similar to what stackline is doing, but it didn't run w/ SpoonInstall so I haven't used it yet

See how they manage window indicators:

  • single (full-frame) canvas
  • window methods set indicator = nil to kill
  • window.lua#L249

Others

  • draw_border.lua: Simple script to draw border on active window
  • status-display.lua: Ki status-display. He clears canvas elements in the draw method! This might work well, esp. for updating.
  • Indicator_KE.lua: Another project, Indicator_KE.lua, does the same thing.
  • msteams.lua
  • window.lua: See how they manage tracking borders on windows as they're moved / resized
  • preocas.lua: Complicated canvas stuff (asmagill)
  • quickPreview.lua: Uses metatables to do canvas stuff. I don't really get it.
  • .hammerspoon/bar:Status bar. Not that useful, for my purposes.
  • dashboard.lua: This looks a little too simple, which might mean it's worth a second look later
  • colorboard.lua: CommandPost Colorboard The opposite of above, this is complicated! Lots of state management, but not sure how applicable it is for stackline.
  • statuslets.lua: statuslets

Testing inspiration

Super sophisticated helpers: fixture loader, default before/after funcs, stubbing, etc.

Huge, well-organized spec folder: https://github.com/kevbrain/apicastsix/blob/master/spec/spec_helper.lua https://github.com/myrepo5588/apicast/blob/master/spec/spec_helper.lua

See fixtures: https://github.com/kevbrain/apicastsix/tree/master/spec/fixtures See complex tests: https://github.com/kevbrain/apicastsix/blob/master/spec/mapping_rule_spec.lua https://github.com/kevbrain/apicastsix/blob/master/spec/mapping_rules_matcher_spec.lua https://github.com/kevbrain/apicastsix/blob/master/spec/configuration_store_spec.lua