From a445b895ee08ba056a864d7f5c111a4692bf256f Mon Sep 17 00:00:00 2001 From: Calic Date: Sun, 14 Jun 2026 00:05:24 +0200 Subject: [PATCH] fix: hoist local M = {} above closures to resolve M.get_theme _dispatch_event captures M at closure-definition time; with M declared further down the file, the capture resolved to global M (nil), causing 'attempt to index a nil value (global M)' every frame the panel was open and a mouse event was dispatched. Hoisting the table declaration above the dispatch helpers fixes the resolution at compile time. --- init.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index de34e2f..cf63c2d 100644 --- a/init.lua +++ b/init.lua @@ -34,6 +34,11 @@ -- Module-level state (all local — no globals) -- ----------------------------------------------------------------------- +-- Module-table declared early so closures in module-local helpers below +-- can reference M.X functions. Method assignments (function M.x() ... end) +-- still land further down once the public surface section starts. +local M = {} + local widgets = {} -- widget_id (string) → widget_def table local active = nil -- active widget_id or nil local theme = {} -- merged DEFAULT_THEME + overrides @@ -187,11 +192,8 @@ local function _dispatch_event(event) end -- ----------------------------------------------------------------------- --- Public module table +-- Public API (M declared at top of file so closures above can reference it) -- ----------------------------------------------------------------------- - -local M = {} - -- ----------------------------------------------------------------------- -- Registry / Lifecycle -- -----------------------------------------------------------------------