Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

publicise sl_require, add sl_require_add_path, add $PREFIX/lib/slash/…

… to require path on boot
  • Loading branch information...
commit a74d94175019928f0e617c7af074f4c166cd122f 1 parent 2bad99a
@charliesome charliesome authored
View
1  Makefile
@@ -64,6 +64,7 @@ install:
mkdir -p $(INSTALL_PREFIX)/lib
mkdir -p $(INSTALL_PREFIX)/include
cp libslash.a $(INSTALL_PREFIX)/lib
+ cp -r lib/* $(INSTALL_PREFIX)/lib
cp -r inc/* $(INSTALL_PREFIX)/include
for sapi in $(SAPIS_ENABLED); do make -C sapi/$$sapi install; done
View
6 configure
@@ -206,6 +206,10 @@ for my $ext (@exts) {
}
open my $init_exts, ">$path/src/init_exts.c";
+my $require_path = "$prefix/lib/slash/";
+$require_path =~ s/\\/\\\\/g;
+$require_path =~ s/"/\\"/g;
+$require_path =~ s/\n/\\\n/g;
print $init_exts <<"C";
#include <slash.h>
@@ -220,7 +224,7 @@ sl_static_init_exts()
void
sl_init_exts(sl_vm_t* vm)
{
- (void)vm; // avoid unused variable error if no exts are enabled
+ sl_require_path_add(vm, "$require_path");
$ext_inits
}
C
View
13 inc/slash/lib/require.h
@@ -0,0 +1,13 @@
+#ifndef SL_LIB_REQUIRE_H
+#define SL_LIB_REQUIRE_H
+
+#include <slash/vm.h>
+#include <slash/value.h>
+
+SLVAL
+sl_require(sl_vm_t* vm, SLVAL self, SLVAL file);
+
+void
+sl_require_path_add(sl_vm_t* vm, char* path);
+
+#endif
View
17 src/lib/require.c
@@ -1,8 +1,8 @@
#include <slash.h>
#include <string.h>
-static SLVAL
-require(sl_vm_t* vm, SLVAL self, SLVAL file)
+SLVAL
+sl_require(sl_vm_t* vm, SLVAL self, SLVAL file)
{
SLVAL include_dirs = sl_class_get_const(vm, vm->lib.Object, "INC");
SLVAL err;
@@ -34,11 +34,22 @@ require(sl_vm_t* vm, SLVAL self, SLVAL file)
}
void
+sl_require_path_add(sl_vm_t* vm, char* path)
+{
+ SLVAL include_dirs = sl_class_get_const(vm, vm->lib.Object, "INC");
+ if(!sl_is_a(vm, include_dirs, vm->lib.Array)) {
+ return;
+ }
+ SLVAL pathv = sl_make_cstring(vm, path);
+ sl_array_push(vm, include_dirs, 1, &pathv);
+}
+
+void
sl_init_require(sl_vm_t* vm)
{
SLVAL inc[2];
inc[0] = sl_make_cstring(vm, ".");
inc[1] = sl_make_cstring(vm, "");
sl_class_set_const(vm, vm->lib.Object, "INC", sl_make_array(vm, 2, inc));
- sl_define_method(vm, vm->lib.Object, "require", 1, require);
+ sl_define_method(vm, vm->lib.Object, "require", 1, sl_require);
}
Please sign in to comment.
Something went wrong with that request. Please try again.