Example #1
0
vm_obj options_fold(vm_obj const &, vm_obj const & o, vm_obj const & a, vm_obj const & fn) {
    vm_obj r = a;
    to_options(o).for_each([&](name const & n) {
            r = invoke(fn, to_obj(n), r);
        });
    return r;
}
Example #2
0
options get_global_options(lua_State * L) {
    lua_pushlightuserdata(L, static_cast<void *>(&g_options_key));
    lua_gettable(L, LUA_REGISTRYINDEX);
    options r;
    if (is_options(L, -1))
        r = to_options(L, -1);
    lua_pop(L, 1);
    return r;
}
Example #3
0
static int _set_global_option(lua_State * L) {
    options o = get_global_options(L);
    push_options(L, o);
    lua_insert(L, 1);
    options_update(L);
    o = to_options(L, -1);
    set_global_options(L, o);
    return 0;
}
Example #4
0
vm_obj format_to_buffer(vm_obj const & fmt, vm_obj const & opts) {
    std::ostringstream out;
    out << mk_pair(to_format(fmt), to_options(opts));

    // TODO(jroesch): make this more performant?
    auto fmt_string = out.str();
    parray<vm_obj> buffer;

    for (auto c : out.str()) {
        buffer.push_back(mk_vm_simple(c));
    }

    return mk_buffer(buffer);
}
Example #5
0
/** Implement two different signatures:
    1) throwable -> options -> format
    2) throwable -> unit -> format */
vm_obj throwable_to_format(vm_obj const & _ex, vm_obj const & _opts) {
    throwable * ex = to_throwable(_ex);
    if (!ex)
        return to_obj(format("null-exception"));

    if (auto kex = dynamic_cast<ext_exception*>(ex)) {
        if (is_simple(_opts)) {
            io_state_stream ios = tout();
            formatter fmt = ios.get_formatter();
            return to_obj(kex->pp(fmt));
        } else {
            options opts = to_options(_opts);
            scope_trace_env scope1(opts);
            io_state_stream ios = tout();
            formatter fmt = ios.get_formatter();
            return to_obj(kex->pp(fmt));
        }
    } else if (auto fex = dynamic_cast<formatted_exception*>(ex)) {
        return to_obj(fex->pp());
    } else {
        return to_obj(format(ex->what()));
    }
}
Example #6
0
static int options_update_double(lua_State * L) {
    return push_options(L, to_options(L, 1).update(to_name_ext(L, 2), lua_tonumber(L, 3)));
}
Example #7
0
static int options_update_string(lua_State * L) {
    return push_options(L, to_options(L, 1).update(to_name_ext(L, 2), lua_tostring(L, 3)));
}
Example #8
0
vm_obj options_has_decidable_eq(vm_obj const & o1, vm_obj const & o2) {
    return mk_vm_bool(to_options(o1) == to_options(o2));
}
Example #9
0
static int options_update_unsigned(lua_State * L) {
    return push_options(L, to_options(L, 1).update(to_name_ext(L, 2), static_cast<unsigned>(lua_tointeger(L, 3))));
}
Example #10
0
vm_obj format_print_using(vm_obj const & fmt, vm_obj const & opts, vm_obj const & /* state */) {
    get_global_ios().get_regular_stream() << mk_pair(to_format(fmt), to_options(opts));
    return mk_io_result(mk_vm_unit());
}
Example #11
0
vm_obj format_to_string(vm_obj const & fmt, vm_obj const & opts) {
    std::ostringstream out;
    out << mk_pair(to_format(fmt), to_options(opts));
    return to_obj(out.str());
}
Example #12
0
static int options_get_int(lua_State * L) {
    int nargs = lua_gettop(L);
    int defval = nargs < 3 ? 0 : lua_tointeger(L, 3);
    return push_integer(L, to_options(L, 1).get_int(to_name_ext(L, 2), defval));
}
Example #13
0
static int _set_global_options(lua_State * L) {
    options o = to_options(L, 1);
    set_global_options(L, o);
    return 0;
}
Example #14
0
static int options_empty(lua_State * L) {
    return push_boolean(L, to_options(L, 1).empty());
}
Example #15
0
static int options_get_bool(lua_State * L) {
    int nargs = lua_gettop(L);
    bool defval = nargs < 3 ? false : lua_toboolean(L, 3);
    return push_boolean(L, to_options(L, 1).get_bool(to_name_ext(L, 2), defval));
}
Example #16
0
static int options_contains(lua_State * L) {
    return push_boolean(L, to_options(L, 1).contains(to_name_ext(L, 2)));
}
Example #17
0
static int options_size(lua_State * L) {
    return push_integer(L, to_options(L, 1).size());
}
Example #18
0
static int options_tostring(lua_State * L) {
    std::ostringstream out;
    out << to_options(L, 1);
    return push_string(L, out.str().c_str());
}
Example #19
0
static int options_join(lua_State * L) {
    return push_options(L, join(to_options(L, 1), to_options(L, 2)));
}
Example #20
0
static int options_get_unsigned(lua_State * L) {
    int nargs = lua_gettop(L);
    unsigned defval = nargs < 3 ? 0 : lua_tointeger(L, 3);
    return push_number(L, to_options(L, 1).get_unsigned(to_name_ext(L, 2), defval));
}
Example #21
0
vm_obj options_get_string(vm_obj const & o, vm_obj const & n, vm_obj const & v) {
    return to_obj(std::string(to_options(o).get_string(to_name(n), to_string(v).c_str())));
}
Example #22
0
vm_obj level_to_format(vm_obj const & l, vm_obj const & o) {
    return to_obj(pp(to_level(l), to_options(o)));
}
Example #23
0
vm_obj options_get_nat(vm_obj const & o, vm_obj const & n, vm_obj const & v) {
    return mk_vm_nat(to_options(o).get_unsigned(to_name(n), to_unsigned(v)));
}
Example #24
0
vm_obj options_get_bool(vm_obj const & o, vm_obj const & n, vm_obj const & v) {
    return mk_vm_bool(to_options(o).get_bool(to_name(n), to_bool(v)));
}
Example #25
0
vm_obj format_of_options(vm_obj const & opts) {
    return to_obj(pp(to_options(opts)));
}
Example #26
0
static int options_update_bool(lua_State * L) {
    return push_options(L, to_options(L, 1).update(to_name_ext(L, 2), static_cast<bool>(lua_toboolean(L, 3))));
}
Example #27
0
static int options_get_double(lua_State * L) {
    int nargs = lua_gettop(L);
    double defval = nargs < 3 ? 0.0 : lua_tonumber(L, 3);
    return push_number(L, to_options(L, 1).get_double(to_name_ext(L, 2), defval));
}
Example #28
0
vm_obj options_join(vm_obj const & o1, vm_obj const & o2) {
    return to_obj(join(to_options(o1), to_options(o2)));
}
Example #29
0
static int options_get_string(lua_State * L) {
    int nargs = lua_gettop(L);
    char const * defval = nargs < 3 ? "" : lua_tostring(L, 3);
    return push_string(L, to_options(L, 1).get_string(to_name_ext(L, 2), defval));
}
Example #30
0
vm_obj options_set_string(vm_obj const & o, vm_obj const & n, vm_obj const & v) {
    return to_obj(to_options(o).update(to_name(n), to_string(v)));
}