From 8f5491447a676a2465d0e8ce825e9bb513022f57 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Fri, 2 May 2014 17:42:27 -0700 Subject: [PATCH] feat(library/kernel_bindings): add environment_id Lua API Signed-off-by: Leonardo de Moura --- src/library/kernel_bindings.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/library/kernel_bindings.cpp b/src/library/kernel_bindings.cpp index cead933c7..af5a51d1d 100644 --- a/src/library/kernel_bindings.cpp +++ b/src/library/kernel_bindings.cpp @@ -806,6 +806,24 @@ static void open_formatter(lua_State * L) { SET_GLOBAL_FUN(set_formatter, "set_formatter"); } +// Environment_id +DECL_UDATA(environment_id) +static int environment_id_descendant(lua_State * L) { return push_boolean(L, to_environment_id(L, 1).is_descendant(to_environment_id(L, 2))); } +static const struct luaL_Reg environment_id_m[] = { + {"__gc", environment_id_gc}, // never throws + {"is_descendant", safe_function}, + {0, 0} +}; + +static void open_environment_id(lua_State * L) { + luaL_newmetatable(L, environment_id_mt); + lua_pushvalue(L, -1); + lua_setfield(L, -2, "__index"); + setfuncs(L, environment_id_m, 0); + + SET_GLOBAL_FUN(environment_id_pred, "is_environment_id"); +} + // Environment DECL_UDATA(environment) @@ -1335,6 +1353,7 @@ void open_kernel_module(lua_State * L) { open_macro_definition(L); open_definition(L); open_formatter(L); + open_environment_id(L); open_environment(L); open_io_state(L); open_justification(L);