Skip to content

SYSTEM variable cannot be used within functions #71

@kunzaatko

Description

@kunzaatko

Note

Perhaps this may be a mistake on my side and if so, forgive me for a fake issue.

I would like to use the system variable in functions to shorten some templating. For instance I have this function defined.

fn hostuser_match(hostname, username) {
    global::SYSTEM.hostname == hostname && global::SYSTEM.username == username
}

for conciseness in the template files and I use it in the git egg like this:

[user]
    email = martinkunz@email.cz
    name = Martin Kunz
    signingkey = FF79D9C5AB73C014 # {< if hostuser_match("TPad", "kunzaatko") >}

but this throws

Error: 
  × Error evaluating rhai
  ╰─▶ Variable not found: global::SYSTEM (line 2, position 5)
      in call to function 'hostuser_match' (line 1, position 1)
   ╭─[/home/kunzaatko/.config/yolk/eggs/git/config:4:41]
 3 │     name = Martin Kunz
 4 │     signingkey = FF79D9C5AB73C014 # {< if hostuser_match("TPad", "kunzaatko") >}
   ·                                         ┬
   ·                                         ╰── here
 5 │ [core]
   ╰────

This should work according to my understanding of docs of global in rhai.
Why doesn't it work? Is the SYSTEM table not a constant?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions