From 191f8e48322bc648a88db37caedb1880a8173ccf Mon Sep 17 00:00:00 2001 From: Caleb Foust Date: Fri, 9 Feb 2024 16:13:36 +0800 Subject: [PATCH] fix: cy freezing on (cy/set :animate :true) --- pkg/cy/docs-cy.md | 2 +- pkg/cy/janet.go | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/cy/docs-cy.md b/pkg/cy/docs-cy.md index 74879632..faefa594 100644 --- a/pkg/cy/docs-cy.md +++ b/pkg/cy/docs-cy.md @@ -16,7 +16,7 @@ Get the value of the [parameter](./parameters.md) with key `key`. (cy/set key value) -Set the value of the [parameter](./parameters.md) with key `key` to value `value`. +Set the value of the [parameter](./parameters.md) with key `key` to value `value`. For the time being, parameter values can only be strings, booleans, and integers. This is expected to change in the future. # doc: Replay diff --git a/pkg/cy/janet.go b/pkg/cy/janet.go index 0d07c77e..997ad2db 100644 --- a/pkg/cy/janet.go +++ b/pkg/cy/janet.go @@ -103,14 +103,14 @@ func (c *CyModule) Get(user interface{}, key *janet.Value) (interface{}, error) func (c *CyModule) Set(user interface{}, key *janet.Value, value *janet.Value) error { defer key.Free() - client, ok := user.(*Client) - if !ok { - return fmt.Errorf("missing client context") - } - - node := client.Node() - if node == nil { - return fmt.Errorf("client was not attached") + // If there is no client, this probably means a parameter is being set + // in cy's startup script. + var node tree.Node = c.cy.tree.Root() + if client, ok := user.(*Client); ok { + node = client.Node() + if node == nil { + return fmt.Errorf("client was not attached") + } } var keyword janet.Keyword @@ -133,7 +133,7 @@ func (c *CyModule) Set(user interface{}, key *janet.Value, value *janet.Value) e return nil } - var _bool int + var _bool bool err = value.Unmarshal(&_bool) if err == nil { node.Params().Set(string(keyword), _bool)