bakpakin on master
Fix #996 - linking command work… (compare)
bakpakin on master
Allow shorthand for setting tas… (compare)
bakpakin on master
Fix function handlers for :out … Merge branch 'master' of github… (compare)
bakpakin on master
Use relative path for include/j… Merge pull request #994 from sh… (compare)
bakpakin on master
Add basic test for tabseq Merge pull request #993 from pe… (compare)
(defn execute_pre_sync_hook []
(def path_no_extension (string (get_cfg_dir) "/hooks/pre-sync"))
(if (file_exists? (string path_no_extension ".janet"))
(do (print "Executing pre-sync-hook...")
(import* path_no_extension)
(pre-sync/pre-sync))
true))
error: cfg.janet:138:11: compile error: unknown symbol pre-sync/pre-sync
(defn execute_pre_sync_hook []
(def path (string (get_cfg_dir) "/hooks/pre-sync.janet"))
(if (file_exists? path)
(do (print "Executing pre-sync-hook...")
(def pre-sync (eval-string (slurp path)))
(pre-sync))
true))
You modify the environment in the middle of a compiled block - the block is compiled before *import
is run, because compilation always comes before evaluation. No amount of hacks will fix that. As I said, Janet is (almost) always early bound.
eval-string is not the right solution to your problem though, I can tell you that. Could you not do something like:
(defn load-hooks
"load pre and post hooks"
[module-path]
(def module (require module-path))
(def pre-sync (get-in module ['pre-sync :value]))
(pre-sync))
require
, dofile
if you want to just pass in a bare path
They do work, I just tested locally. I think the issue is you are making use of things like eval
and eval-string
inside your "hooks" file. These are inherently dependent on the context they are run in - you would have the same issues in any programming language. Using "require" or "dofile" does not just bring all of the bindings from the given path into the current environment, it returns a fully encapsulated module table. Even *import will auto-prefix bindings before bringing them into the current environment table.
Also, the effect of import or *import has no effect until the top level block is executed. You cannot do:
(do
(import my-mod)
(my-mod/abc 123))
(import my-mod)
(my-mod/abc 123)
This is because Janet use incremental compilation, basically a repl. The first example (using do) has the following flow:
(do (import ...))
my-mod/abc
is undefined.The second working form has the following flow:
(import my-mod)
my-mod/abc
defined.(my-mod/abc 123)
my-mod/abc
was defined in the previous form, this evaluates without compilation error.This incremental compilation is pretty common to Lisps and is not the stringly typed dynamism that is from a language like TCL.
(defn post-sync []
(match ((cfg "config" "node.name") :text)
"citadel" (do (os/execute ["vdirsyncer" "sync"] :p)
(os/execute ["wiki" "calendar_commit"] :p)
(os/execute ["wiki" "contacts_commit" "--no_pull"] :p))))
I am working c++ (gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1), trying to add a key to a janet table.
I get the table with: JanetTable *tt = janet_table(0); .
I try to add an entry with: janet_table_put(tt, janet_wrap_string("count"), janet_wrap_number(10)); .
The key shows up as "" when I print the table in the repl?
why?
thank you in advance!
@bakpakin:matrix.org It is not a problem with Janet. I figured out the problem. The Documentation should include a note to Check-Mark the C++ Build tools when installing the VS Build Tools. Now when i type cl.exe it gives me this: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools>cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27048 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
sudo jpm deps
:$ sudo jpm deps
From https://github.com/janet-lang/json
* branch HEAD -> FETCH_HEAD
HEAD is now at c4671e8 Use normal, module level import in test file.
compiling json.c to build/json.o...
json.c:23:10: fatal error: 'janet.h' file not found
#include <janet.h>
^~~~~~~~~
1 error generated.
error: command failed with non-zero exit code 1
error: build fail
in pdag [/opt/homebrew/Cellar/janet/1.22.0/lib/janet/jpm/dagbuild.janet] (tailcall) on line 79, column 23
in <anonymous> [/opt/homebrew/Cellar/janet/1.22.0/lib/janet/jpm/pm.janet] on line 215, column 9
in <anonymous> [/opt/homebrew/Cellar/janet/1.22.0/lib/janet/jpm/pm.janet] on line 200, column 5
in bundle-install [/opt/homebrew/Cellar/janet/1.22.0/lib/janet/jpm/pm.janet] on line 198, column 3
in deps [/opt/homebrew/Cellar/janet/1.22.0/lib/janet/jpm/commands.janet] (tailcall) on line 198, column 7
in _thunk [/usr/local/bin/jpm] (tailcall) on line -1, column -1
in cli-main [boot.janet] on line 3759, column 17