static int mk_name_set(lua_State * L) { name_set r; int nargs = lua_gettop(L); for (int i = 1; i <= nargs; i++) r.insert(to_name_ext(L, i)); return push_name_set(L, r); }
static int add_private_name(lua_State * L) { int nargs = lua_gettop(L); optional<unsigned> h; if (nargs > 2) h = lua_tonumber(L, 3); auto p = add_private_name(to_environment(L, 1), to_name_ext(L, 2), h); push_environment(L, p.first); push_name(L, p.second); return 2; }
static int mk_exprs_action(lua_State * L) { int nargs = lua_gettop(L); unsigned rbp = nargs <= 5 ? 0 : lua_tonumber(L, 6); optional<name> terminator; if (nargs >= 4) terminator = to_optional_name(L, 4); return push_notation_action(L, mk_exprs_action(to_name_ext(L, 1), to_expr(L, 2), lua_isnil(L, 3) ? none_expr() : some_expr(to_expr(L, 3)), terminator, lua_toboolean(L, 5), rbp)); }
static int find(lua_State * L) { list<pair<action, parse_table>> it = to_parse_table(L, 1).find(to_name_ext(L, 2)); if (it) { // TODO(Leo): support multiple actions auto p = head(it); push_notation_action(L, p.first); push_parse_table(L, p.second); return 2; } else { return push_nil(L); } }
static int add(lua_State * L) { int nargs = lua_gettop(L); buffer<transition> ts; luaL_checktype(L, 2, LUA_TTABLE); int sz = objlen(L, 2); for (int i = 1; i <= sz; i++) { lua_rawgeti(L, 2, i); if (lua_isstring(L, -1) || is_name(L, -1)) { ts.push_back(transition(to_name_ext(L, -1), mk_expr_action())); lua_pop(L, 1); } else { luaL_checktype(L, -1, LUA_TTABLE); lua_rawgeti(L, -1, 1); lua_rawgeti(L, -2, 2); ts.push_back(transition(to_name_ext(L, -2), to_notation_action_ext(L, -1))); lua_pop(L, 3); } } bool overload = (nargs <= 3) || lua_toboolean(L, 4); return push_parse_table(L, to_parse_table(L, 1).add(ts.size(), ts.data(), to_expr(L, 3), LEAN_DEFAULT_NOTATION_PRIORITY, overload)); }
static int app_builder_mk_app(lua_State * L) { int nargs = lua_gettop(L); buffer<expr> args; app_builder & b = to_app_builder_ref(L, 1)->m_builder; bool use_cache = true; name n = to_name_ext(L, 2); for (int i = 3; i <= nargs; i++) { if (i < nargs || is_expr(L, i)) args.push_back(to_expr(L, i)); else use_cache = lua_toboolean(L, i); } return push_optional_expr(L, b.mk_app(n, args.size(), args.data(), use_cache)); }
int options_update(lua_State * L) { name k = to_name_ext(L, 2); auto it = get_option_declarations().find(k); if (it == get_option_declarations().end()) { throw exception(sstream() << "unknown option '" << k.to_string().c_str() << "'"); } else { option_declaration const & d = it->second; switch (d.kind()) { case BoolOption: return options_update_bool(L); case IntOption: return options_update_int(L); case UnsignedOption: return options_update_unsigned(L); case DoubleOption: return options_update_double(L); case StringOption: return options_update_string(L); default: throw exception(sstream() << "unsupported option kind for '" << k.to_string().c_str() << "'"); } } }
int mk_options(name const & prefix, lua_State * L) { options r; int nargs = lua_gettop(L); if (nargs % 2 != 0) throw exception("options expects an even number of arguments"); for (int i = 1; i < nargs; i+=2) { name k = prefix + to_name_ext(L, i); auto it = get_option_declarations().find(k); if (it == get_option_declarations().end()) { throw exception(sstream() << "unknown option '" << k.to_string().c_str() << "'"); } else { option_declaration const & d = it->second; switch (d.kind()) { case BoolOption: r = r.update(k, static_cast<bool>(lua_toboolean(L, i+1))); break; case IntOption: r = r.update(k, static_cast<int>(lua_tointeger(L, i+1))); break; case UnsignedOption: r = r.update(k, static_cast<unsigned>(lua_tointeger(L, i+1))); break; case DoubleOption: r = r.update(k, static_cast<double>(lua_tonumber(L, i+1))); break; case StringOption: r = r.update(k, lua_tostring(L, i+1)); break; default: throw exception(sstream() << "unsupported option kind for '" << k.to_string().c_str() << "'"); } } } return push_options(L, r); }
static int name_set_contains(lua_State * L) { return push_boolean(L, to_name_set(L, 1).contains(to_name_ext(L, 2))); }
static int name_set_erase(lua_State * L) { return push_name_set(L, erase(to_name_set(L, 1), to_name_ext(L, 2))); }
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)); }
static int name_set_insert(lua_State * L) { return push_name_set(L, insert(to_name_set(L, 1), to_name_ext(L, 2))); }
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)); }
static int mk_name_generator(lua_State * L) { if (lua_gettop(L) == 0) return push_name_generator(L, name_generator(*g_tmp_prefix)); else return push_name_generator(L, name_generator(to_name_ext(L, 1))); }
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)); }
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)); }
static int check_token_next(lua_State * L) { gparser.check_token_next(to_name_ext(L, 1), lua_tostring(L, 2)); return 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)); }
static int options_contains(lua_State * L) { return push_boolean(L, to_options(L, 1).contains(to_name_ext(L, 2))); }
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)))); }
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))); }
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))); }
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)))); }
static int hidden_to_user_name(lua_State * L) { return push_optional_name(L, hidden_to_user_name(to_environment(L, 1), to_name_ext(L, 2))); }
static int curr_is_token_or_id(lua_State * L) { return push_boolean(L, gparser.curr_is_token_or_id(to_name_ext(L, 1))); }