Esempio n. 1
0
// loads the core library
void l_load_lib(LClosure *closure) {
  // FIXME use absolute paths
#if L_SKIP_LIB == 0
  l_eval_path("lib/core/list.lid", closure);
  l_eval_path("lib/core/math.lid", closure);
#endif
}
Esempio n. 2
0
int main (int argc, char **argv) {
  // parse args
  struct arguments arguments;
  arguments.argc = 0;
  argp_parse (&argp, argc, argv, 0, 0, &arguments);
  char *filename = arguments.args[0];

  LClosure *closure = l_closure_new(NULL);
  l_closure_set_funcs(closure);

  LValue* f = l_value_new(L_STR_TYPE, closure);
  f->core.str = make_stringbuf((char*)filename);
  l_closure_set(closure, "-script", f, true);

  LValue *arg;
  LValue *args = l_value_new(L_LIST_TYPE, closure);
  args->core.list = create_vector();
  int i;
  for(i=1; i<arguments.argc; i++) {
    arg = l_value_new(L_STR_TYPE, closure);
    arg->core.str = make_stringbuf(arguments.args[i]);
    vector_add(args->core.list, arg, sizeof(arg));
  }
  l_closure_set(closure, "-args", args, true);

  l_eval_path(filename, closure);

  exit(0);
}
Esempio n. 3
0
LValue *l_func_require(LValue *args, LClosure *closure) {
  if(l_loaded_libs == NULL)
    l_loaded_libs = create_hashmap();
  int i;
  char *p;
  LValue *path;
  closure = l_closure_root(closure);
  for(i=0; i<args->core.list->length; i++) {
    path = l_list_get(args, i);
    l_assert_is(path, L_STR_TYPE, "Path for require must be a string.", closure);
    p = path->core.str->str;
    // TODO search in cwd, then in lib/extra
    if(!hashmap_get(l_loaded_libs, p)) {
      l_eval_path(p, closure);
      hashmap_put(l_loaded_libs, p, p, sizeof(p));
    }
  }
  return args;
}