|
Hi!
(defn main [& args]
(if (< (length args) 2)
(do
(print "Use: my_app <script.janet>")
(os/exit 1)))
(def script-path (get args 1))
(print "[Janet Host]: Read external file: " script-path)
(if (os/stat script-path)
(let [script-content (slurp script-path)
current-env (make-env)]
(print "--------------------------------------------------")
(eval-string script-content current-env)
(print "--------------------------------------------------")
(print "[Janet Host]: Done."))
(print "[Janet Host]: Error: No file found!")))
#include <janet.h>
#include <stdio.h>
static Janet c_do_thing1(int32_t argc, Janet *argv) {
(void) argc; (void) argv;
printf("[C mylib1]: Call from monolith binary!\n");
return janet_wrap_nil();
}
static const JanetReg cfuns[] = {
{"do-thing1", c_do_thing1, "(do-thing1)\n\nPrint from C."},
{NULL, NULL, NULL}
};
JANET_MODULE_ENTRY(JanetTable *env) {
printf("[C mylib1]: entry!\n");
janet_cfuns(env, "mylib1", cfuns);
}
(declare-project
:name "my-static-app"
:author "Developer")
(def m1
(declare-native
:name "mylib1"
:source @["mylib1.c"]))
(declare-executable
:name "myexec"
:entry "main.janet"
:deps [(m1 :static)])
#(import mylib1 :export true)
(print "[External File]: On air!")
(print "[External File]: call (do-thing1):")
(do-thing1)
(print "[External File]: End")
./build/myexec ./script.janetError: Q1: How to deal with it? I want Q2: If I declare Probably I do something wrong, but have no idea what exactly is wrong. Thanks! |
Answered by
sogaiu
Jul 30, 2026
Replies: 1 comment 3 replies
|
Does this help? (use mylib1)
# trick from: https://github.com/janet-lang/janet/discussions/1619
(def my-env (curenv))
(defn main [& args]
(if (< (length args) 2)
(do
(print "Use: my_app <script.janet>")
(os/exit 1)))
(def script-path (get args 1))
(print "[Janet Host]: Read external file: " script-path)
(if (os/stat script-path)
(do
(print "--------------------------------------------------")
(dofile script-path :env my-env)
(print "--------------------------------------------------")
(print "[Janet Host]: Done."))
(print "[Janet Host]: Error: No file found!")))Seems to work here: In case the static bits don't work, possibly this might be worth investigating. |
3 replies
Answer selected by
dmitrys99
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this help?
Seems to work here: