2013-11-10 17:11:44 +00:00
|
|
|
/*
|
2014-04-29 18:52:09 +00:00
|
|
|
Copyright (c) 2013-2014 Microsoft Corporation. All rights reserved.
|
2013-11-10 17:11:44 +00:00
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
2014-06-18 05:36:47 +00:00
|
|
|
#include "util/script_state.h"
|
2014-04-29 18:52:09 +00:00
|
|
|
#include "kernel/environment.h"
|
2013-11-12 04:29:53 +00:00
|
|
|
|
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)
|
2014-05-01 22:30:30 +00:00
|
|
|
UDATA_DEFS(expr)
|
2013-11-27 03:15:49 +00:00
|
|
|
UDATA_DEFS(formatter)
|
2014-04-29 18:52:09 +00:00
|
|
|
UDATA_DEFS(definition)
|
2014-05-02 01:29:34 +00:00
|
|
|
UDATA_DEFS(macro_definition)
|
2013-11-15 01:19:51 +00:00
|
|
|
UDATA_DEFS(environment)
|
2014-05-01 22:30:30 +00:00
|
|
|
UDATA_DEFS(substitution)
|
2013-11-27 03:15:49 +00:00
|
|
|
UDATA_DEFS(justification)
|
2014-04-29 18:52:09 +00:00
|
|
|
UDATA_DEFS(constraint)
|
|
|
|
UDATA_DEFS(substitution)
|
2013-12-30 19:20:23 +00:00
|
|
|
UDATA_DEFS(io_state)
|
2014-06-12 19:29:04 +00:00
|
|
|
int push_optional_level(lua_State * L, optional<level> const & e);
|
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);
|
2014-05-31 22:40:36 +00:00
|
|
|
int push_optional_declaration(lua_State * L, optional<declaration> const & e);
|
2014-06-26 20:35:36 +00:00
|
|
|
int push_optional_constraint(lua_State * L, optional<constraint> const & c);
|
2014-06-09 22:24:33 +00:00
|
|
|
int push_list_expr(lua_State * L, list<expr> const & l);
|
2013-11-27 03:15:49 +00:00
|
|
|
/**
|
2014-07-10 17:32:00 +00:00
|
|
|
\brief Return the formatter factory object associated with the given Lua State.
|
2013-11-27 03:15:49 +00:00
|
|
|
This procedure checks for options at:
|
|
|
|
1- Lean state object associated with \c L
|
|
|
|
2- Lua Registry associated with \c L
|
|
|
|
*/
|
2014-07-10 17:32:00 +00:00
|
|
|
optional<formatter_factory> get_global_formatter_factory_core(lua_State * L);
|
2013-12-09 01:33:18 +00:00
|
|
|
/**
|
2014-07-10 17:32:00 +00:00
|
|
|
\brief Similar to \c get_global_formatter_factory_core, but returns
|
2013-12-09 01:33:18 +00:00
|
|
|
the simple_formatter if a formatter can't be found.
|
|
|
|
*/
|
2014-07-10 17:32:00 +00:00
|
|
|
formatter_factory get_global_formatter_factory(lua_State * L);
|
2013-11-27 03:15:49 +00:00
|
|
|
/**
|
|
|
|
\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.
|
|
|
|
*/
|
2014-07-10 17:32:00 +00:00
|
|
|
void set_global_formatter_factory(lua_State * L, formatter_factory const & fmtf);
|
|
|
|
|
|
|
|
/** \brief Make a fresh formatter object using the global formatter factory associated with L, and the global environment */
|
|
|
|
formatter mk_formatter(lua_State * L);
|
2014-01-14 00:54:21 +00:00
|
|
|
|
|
|
|
/** \brief Set the Lua registry of a Lua state with an environment object. */
|
|
|
|
void set_global_environment(lua_State * L, environment const & env);
|
2014-06-27 13:59:17 +00:00
|
|
|
environment get_global_environment(lua_State * L);
|
2013-11-10 18:12:43 +00:00
|
|
|
/**
|
2014-01-14 00:54:21 +00:00
|
|
|
\brief Auxiliary class for temporarily setting the Lua registry of a Lua state
|
2013-11-10 18:12:43 +00:00
|
|
|
with an environment object.
|
|
|
|
*/
|
|
|
|
class set_environment {
|
2014-06-11 18:03:12 +00:00
|
|
|
lua_State * m_state;
|
2014-06-18 05:36:47 +00:00
|
|
|
environment * m_old_env;
|
2013-11-10 18:12:43 +00:00
|
|
|
public:
|
2014-06-11 18:03:12 +00:00
|
|
|
set_environment(lua_State * L, environment & env);
|
2014-06-18 05:36:47 +00:00
|
|
|
set_environment(script_state & S, environment & env):set_environment(S.get_state(), env) {}
|
2013-11-10 18:12:43 +00:00
|
|
|
~set_environment();
|
|
|
|
};
|
2013-11-12 04:29:53 +00:00
|
|
|
|
2014-01-14 00:54:21 +00:00
|
|
|
/** \brief Set the Lua registry of a Lua state with an io_state object. */
|
|
|
|
void set_global_io_state(lua_State * L, io_state & ios);
|
2013-12-30 19:20:23 +00:00
|
|
|
/**
|
|
|
|
\brief Auxiliary class for temporarily setting the Lua registry of a Lua state
|
|
|
|
with a Lean io_state object.
|
|
|
|
*/
|
|
|
|
class set_io_state {
|
|
|
|
lua_State * m_state;
|
|
|
|
io_state * m_prev;
|
|
|
|
options m_prev_options;
|
|
|
|
public:
|
2014-06-18 05:36:47 +00:00
|
|
|
set_io_state(lua_State * L, io_state & ios);
|
|
|
|
set_io_state(script_state & S, io_state & ios):set_io_state(S.get_state(), ios) {}
|
2013-12-30 19:20:23 +00:00
|
|
|
~set_io_state();
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
\brief Return the Lean state object associated with the given Lua state.
|
|
|
|
Return nullptr is there is none.
|
|
|
|
*/
|
2014-05-25 13:05:31 +00:00
|
|
|
io_state * get_io_state_ptr(lua_State * L);
|
|
|
|
io_state get_io_state(lua_State * L);
|
2014-05-29 20:35:11 +00:00
|
|
|
io_state to_io_state_ext(lua_State * L, int idx);
|
2013-12-30 19:20:23 +00:00
|
|
|
void open_io_state(lua_State * L);
|
2013-11-10 17:11:44 +00:00
|
|
|
}
|