2013-11-10 17:11:44 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
2013-11-27 03:15:49 +00:00
|
|
|
#include "util/lua.h"
|
2013-11-12 04:29:53 +00:00
|
|
|
#include "kernel/threadsafe_environment.h"
|
|
|
|
|
2013-11-10 17:11:44 +00:00
|
|
|
namespace lean {
|
2013-11-27 03:15:49 +00:00
|
|
|
void open_kernel_module(lua_State * L);
|
|
|
|
UDATA_DEFS(level)
|
|
|
|
UDATA_DEFS(local_entry)
|
|
|
|
UDATA_DEFS_CORE(local_context)
|
|
|
|
UDATA_DEFS(expr);
|
|
|
|
UDATA_DEFS(context_entry)
|
|
|
|
UDATA_DEFS(context)
|
|
|
|
UDATA_DEFS(formatter)
|
|
|
|
UDATA_DEFS(object)
|
2013-11-15 01:19:51 +00:00
|
|
|
UDATA_DEFS(environment)
|
2013-11-27 03:15:49 +00:00
|
|
|
UDATA_DEFS(justification)
|
|
|
|
UDATA_DEFS(metavar_env)
|
2013-12-13 00:33:31 +00:00
|
|
|
int push_environment(lua_State * L, ro_environment const & env);
|
2013-12-08 07:21:07 +00:00
|
|
|
int push_optional_expr(lua_State * L, optional<expr> const & e);
|
|
|
|
int push_optional_justification(lua_State * L, optional<justification> const & j);
|
2013-12-08 22:37:38 +00:00
|
|
|
int push_optional_object(lua_State * L, optional<object> const & o);
|
2013-11-27 03:15:49 +00:00
|
|
|
/**
|
|
|
|
\brief Return the formatter object associated with the given Lua State.
|
|
|
|
This procedure checks for options at:
|
|
|
|
1- Lean state object associated with \c L
|
|
|
|
2- Lua Registry associated with \c L
|
|
|
|
*/
|
2013-12-09 01:33:18 +00:00
|
|
|
optional<formatter> get_global_formatter_core(lua_State * L);
|
|
|
|
/**
|
|
|
|
\brief Similar to \c get_global_formatter_core, but returns
|
|
|
|
the simple_formatter if a formatter can't be found.
|
|
|
|
*/
|
2013-11-27 03:15:49 +00:00
|
|
|
formatter get_global_formatter(lua_State * L);
|
|
|
|
/**
|
|
|
|
\brief Update the formatter object associated with the given Lua State.
|
|
|
|
If \c L is associated with a Lean state object \c S, then we update the formatter of \c S.
|
|
|
|
Otherwise, we update the registry of \c L.
|
|
|
|
*/
|
|
|
|
void set_global_formatter(lua_State * L, formatter const & fmt);
|
2013-11-10 18:12:43 +00:00
|
|
|
/**
|
|
|
|
\brief Auxiliary class for setting the Lua registry of a Lua state
|
|
|
|
with an environment object.
|
|
|
|
*/
|
|
|
|
class set_environment {
|
|
|
|
lua_State * m_state;
|
|
|
|
public:
|
2013-12-13 00:33:31 +00:00
|
|
|
set_environment(lua_State * L, environment const & env);
|
2013-11-10 18:12:43 +00:00
|
|
|
~set_environment();
|
|
|
|
};
|
2013-11-12 04:29:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Helper class for getting a read-only reference
|
|
|
|
for an environment object on the Lua stack.
|
|
|
|
*/
|
2013-12-12 19:19:09 +00:00
|
|
|
class ro_shared_environment : public read_only_shared_environment {
|
2013-11-12 04:29:53 +00:00
|
|
|
public:
|
2013-12-12 19:19:09 +00:00
|
|
|
ro_shared_environment(lua_State * L, int idx);
|
|
|
|
ro_shared_environment(lua_State * L);
|
2013-11-12 04:29:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Helper class for getting a read-write reference
|
|
|
|
for an environment object on the Lua stack.
|
|
|
|
*/
|
2013-12-12 19:19:09 +00:00
|
|
|
class rw_shared_environment : public read_write_shared_environment {
|
2013-11-12 04:29:53 +00:00
|
|
|
public:
|
2013-12-12 19:19:09 +00:00
|
|
|
rw_shared_environment(lua_State * L, int idx);
|
|
|
|
rw_shared_environment(lua_State * L);
|
2013-11-12 04:29:53 +00:00
|
|
|
};
|
2013-11-10 17:11:44 +00:00
|
|
|
}
|