feat(library/kernel_bindings): expose environment::add(declaration) method in the Lua API, and add example to demonstrate its usage

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-05-21 11:05:22 -07:00
parent 9b9041fa2e
commit f08a852da8
2 changed files with 18 additions and 1 deletions

View file

@ -1099,7 +1099,12 @@ static int environment_add_global_level(lua_State * L) { return push_environment
static int environment_is_global_level(lua_State * L) { return push_boolean(L, to_environment(L, 1).is_global_level(to_name_ext(L, 2))); }
static int environment_find(lua_State * L) { return push_optional_declaration(L, to_environment(L, 1).find(to_name_ext(L, 2))); }
static int environment_get(lua_State * L) { return push_declaration(L, to_environment(L, 1).get(to_name_ext(L, 2))); }
static int environment_add(lua_State * L) { return push_environment(L, to_environment(L, 1).add(to_certified_declaration(L, 2))); }
static int environment_add(lua_State * L) {
if (is_declaration(L, 2))
return push_environment(L, to_environment(L, 1).add(to_declaration(L, 2)));
else
return push_environment(L, to_environment(L, 1).add(to_certified_declaration(L, 2)));
}
static int environment_replace(lua_State * L) { return push_environment(L, to_environment(L, 1).replace(to_certified_declaration(L, 2))); }
static int mk_empty_environment(lua_State * L) {
unsigned trust_lvl = get_uint_named_param(L, 1, "trust_lvl", 0);

12
tests/lua/env9.lua Normal file
View file

@ -0,0 +1,12 @@
local env = empty_environment()
-- Trust level is set to 0 by default. Then, we must type check a
-- definition, before adding it to the environment
assert(not pcall(function() env:add(mk_var_decl("A", Bool)) end))
-- The function check produces a "certified declaration".
env:add(check(env, mk_var_decl("A", Bool)))
local env = empty_environment({trust_level = 10000000})
-- Now, env has trust_level > LEAN_BELIEVER_TRUST_LEVEL, then we can
-- add declarations without type checking them.
env:add(mk_var_decl("A", Bool))