From 0a597e63f1203725090dca503d1c910d4d228dda Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sun, 6 Apr 2025 06:51:43 +0200 Subject: [PATCH] Small coroutine fix --- src/elements/Container.lua | 2 +- src/elements/Graph.lua | 1 + src/main.lua | 14 ++++++++------ src/plugins/benchmark.lua | 9 ++++----- src/plugins/reactive.lua | 4 ++++ 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/elements/Container.lua b/src/elements/Container.lua index 006d13a..b92d52b 100644 --- a/src/elements/Container.lua +++ b/src/elements/Container.lua @@ -6,7 +6,7 @@ local split = require("libraries/utils").split ---@configDescription The container class. It is a visual element that can contain other elements. It is the base class for all containers ---@configDefault true ---- The Container class serves as a fundamental building block for organizing UI elements. It acts as a parent element that can hold and manage child elements, providing layout management, event propagation, and rendering capabilities. Used as base class for Frames, Windows, and other container-like elements. +--- The Container class serves as a fundamental building block for organizing UI elements. It acts as a parent element that can hold and manage child elements. --- @usage local container = basalt.getMainFrame() --- @usage container:addButton() -- Add a child element ---@class Container : VisualElement diff --git a/src/elements/Graph.lua b/src/elements/Graph.lua index 2b23583..721f18f 100644 --- a/src/elements/Graph.lua +++ b/src/elements/Graph.lua @@ -55,6 +55,7 @@ end --- @param bgCol number The background color of the series --- @param fgCol number The foreground color of the series --- @param pointCount number The number of points in the series +--- @return Graph self The graph instance function Graph:addSeries(name, symbol, bgCol, fgCol, pointCount) local series = self.get("series") table.insert(series, { diff --git a/src/main.lua b/src/main.lua index ab0ba6a..348b30a 100644 --- a/src/main.lua +++ b/src/main.lua @@ -238,13 +238,15 @@ local function updateEvent(event, ...) end for _, func in ipairs(basalt._schedule) do - if(event==func.filter)or(func.filter==nil)then - local ok, result = coroutine.resume(func.coroutine, event, ...) - if(not ok)then - errorManager.header = "Basalt Schedule Error" - errorManager.error(result) + if(coroutine.status(func.coroutine)=="suspended")then + if(event==func.filter)or(func.filter==nil)then + local ok, result = coroutine.resume(func.coroutine, event, ...) + if(not ok)then + errorManager.header = "Basalt Schedule Error" + errorManager.error(result) + end + func.filter = result end - func.filter = result end if(coroutine.status(func.coroutine)=="dead")then basalt.removeSchedule(func.coroutine) diff --git a/src/plugins/benchmark.lua b/src/plugins/benchmark.lua index 96f55ef..933dc89 100644 --- a/src/plugins/benchmark.lua +++ b/src/plugins/benchmark.lua @@ -39,9 +39,6 @@ end ---@splitClass ---- This is the benchmark plugin. It provides performance measurement tools for elements and methods, ---- with support for hierarchical profiling and detailed statistics. ---- The following methods are available for BaseElement ---@class BaseElement local BaseElement = {} @@ -298,8 +295,10 @@ function Container:stopContainerBenchmark(methodName) return self end ---- Benchmark API methods ----@class BenchmarkAPI +--- This is the benchmark plugin. It provides performance measurement tools for elements and methods, +--- with support for hierarchical profiling and detailed statistics. The plugin is meant to be used for very big projects +--- where performance is critical. It allows you to measure the time taken by specific methods and log the results. +---@class Benchmark local API = {} --- Starts a custom benchmark diff --git a/src/plugins/reactive.lua b/src/plugins/reactive.lua index c6710bd..aeae996 100644 --- a/src/plugins/reactive.lua +++ b/src/plugins/reactive.lua @@ -195,6 +195,10 @@ end) --- This module provides reactive functionality for elements, it adds no new functionality for elements. --- It is used to evaluate expressions in property values and update the element when the expression changes. +--- @usage local button = main:addButton({text="Exit"}) +--- @usage button:setX("{parent.x - 12}") +--- @usage button:setBackground("{self.clicked and colors.red or colors.green}") +--- @usage button:setWidth("{self.text:len() + 2}") ---@class Reactive local BaseElement = {}