mirror of
https://github.com/janet-lang/janet
synced 2024-12-25 07:50:27 +00:00
Add extra argument to (native) to allow for passing
in custom environment to add stuff to.
This commit is contained in:
parent
b535c91ee1
commit
b626e73d19
@ -1623,7 +1623,7 @@ value, one key will be ignored."
|
||||
(def n (find-native path))
|
||||
(if (not n)
|
||||
(error (string "could not open file for module " path)))
|
||||
(native n)))))))
|
||||
(native n (make-env))))))))
|
||||
|
||||
(defn import*
|
||||
"Import a module into a given environment table. This is the
|
||||
|
@ -67,10 +67,15 @@ JanetModule janet_native(const char *name, const uint8_t **error) {
|
||||
|
||||
static Janet janet_core_native(int32_t argc, Janet *argv) {
|
||||
JanetModule init;
|
||||
JanetTable *env = janet_table(0);
|
||||
janet_fixarity(argc, 1);
|
||||
janet_arity(argc, 1, 2);
|
||||
const uint8_t *path = janet_getstring(argv, 0);
|
||||
const uint8_t *error = NULL;
|
||||
JanetTable *env;
|
||||
if (argc == 2) {
|
||||
env = janet_gettable(argv, 1);
|
||||
} else {
|
||||
env = janet_table(0);
|
||||
}
|
||||
init = janet_native((const char *)path, &error);
|
||||
if (!init) {
|
||||
janet_panicf("could not load native %S: %S", path, error);
|
||||
@ -245,7 +250,7 @@ static Janet janet_core_hash(int32_t argc, Janet *argv) {
|
||||
|
||||
static const JanetReg cfuns[] = {
|
||||
{"native", janet_core_native,
|
||||
"(native path)\n\n"
|
||||
"(native path [,env])\n\n"
|
||||
"Load a native module from the given path. The path "
|
||||
"must be an absolute or relative path on the file system, and is "
|
||||
"usually a .so file on Unix systems, and a .dll file on Windows. "
|
||||
|
Loading…
Reference in New Issue
Block a user