From c725ffd3bc6e5291f21934ba823dbc143ec00401 Mon Sep 17 00:00:00 2001 From: Calic Date: Sun, 14 Jun 2026 19:53:00 +0200 Subject: [PATCH] fix: nil-guard in _invoke_context_menu + README English - _invoke_context_menu now early-returns if locale_factory() returns nil mid-frame, symmetric with build_rows. Prevents the race where a workbench destroyed between render and right-click would propagate nil locale into ctx_inner and crash craft. - README v0.2.0 sections (M.create + action-callback) translated from Denglisch to English for consistency with the rest of the file. Co-Authored-By: Claude Opus 4.7 (1M context) --- README.md | 31 +++++++++++++++---------------- init.lua | 1 + 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 5b9268c..bb473a6 100644 --- a/README.md +++ b/README.md @@ -105,15 +105,15 @@ there propagate (consistent with rest of the lib stack). ### `display.create(arg, opts) -> widget_def` -Creates a crafting widget. **`arg`** ist eines von: +Creates a crafting widget. **`arg`** is one of: -- **Form 1 (Bw-Compat v0.1):** bare container-entity-handle. Intern - als constant locale_factory gewrappt (`function() return arg end`). -- **Form 2 (v0.2 NEU):** `function() -> locale` — wird pro Frame - aufgerufen. Locale ist entweder ein entity-handle (Form-1 sub- - semantik) oder eine Table `{sources={...}, sink=...}`. Forward- - compat zu dynamischen Topologien (player-bewegt-sich → - adjacent-Container-Set ändert sich, ohne widget-Recreate). +- **Form 1 (bw-compat from v0.1):** bare container-entity-handle. Wrapped + internally as a constant locale_factory (`function() return arg end`). +- **Form 2 (NEW in v0.2):** `function() -> locale` — invoked per frame. + Locale is either an entity-handle (Form-1 sub-semantics) or a table + `{sources={...}, sink=...}`. Forward-compatible with dynamic + topologies (player moves → adjacent-container set changes, no widget + recreate required). **Syntax:** `display.create(arg: entity | function() -> locale, opts: table|nil) -> widget_def` @@ -157,24 +157,23 @@ Loud-error if `arg` is `nil`. --- -### Action-Callback Signatur (v0.2.0 Update) +### Action-Callback Signature (v0.2.0 Update) -Callbacks erhalten `(recipe_id, ctx_inner)` wo `ctx_inner`: +Callbacks receive `(recipe_id, ctx_inner)` where `ctx_inner` is: ```lua { - locale = , -- v0.2 NEU + locale = , -- NEW in v0.2 container = , -- bw-compat alias close_menu = function() ... end, refresh = function() ... end, } ``` -Modul-Aktion ruft typisch `crafting.craft(recipe_id, -ctx_inner.locale, ctx)`. Existing v0.1 callers die -`ctx_inner.container` benutzen funktionieren weiter via Form-1 -bw-compat-shim (sink-handle wird intern als single-container -behandelt). +Module action typically calls `crafting.craft(recipe_id, +ctx_inner.locale, ctx)`. Existing v0.1 callers that use +`ctx_inner.container` continue to work via the Form-1 bw-compat shim +(sink-handle is treated internally as a single-container). --- diff --git a/init.lua b/init.lua index adb0978..d3083a6 100644 --- a/init.lua +++ b/init.lua @@ -296,6 +296,7 @@ end function M._invoke_context_menu(widget, recipe_id, mx, my) local locale = widget._locale_factory() + if locale == nil then return end -- symmetric with build_rows local sink_alias if type(locale) == "table" then sink_alias = locale.sink