2013-11-07 21:56:04 +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
|
|
|
|
*/
|
2013-11-08 19:59:47 +00:00
|
|
|
#pragma once
|
2013-11-07 21:56:04 +00:00
|
|
|
#include <memory>
|
2013-11-11 23:05:10 +00:00
|
|
|
#include <lua.hpp>
|
2013-11-08 19:59:47 +00:00
|
|
|
#include "bindings/lua/lua_exception.h"
|
2013-11-07 21:56:04 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2013-11-10 18:12:43 +00:00
|
|
|
class environment;
|
2013-11-12 23:38:00 +00:00
|
|
|
class state;
|
2013-11-07 21:56:04 +00:00
|
|
|
/**
|
|
|
|
\brief Wrapper for lua_State objects which contains all Lean bindings.
|
|
|
|
*/
|
|
|
|
class leanlua_state {
|
|
|
|
struct imp;
|
|
|
|
std::shared_ptr<imp> m_ptr;
|
2013-11-12 00:25:17 +00:00
|
|
|
friend class leanlua_thread;
|
2013-11-12 01:46:39 +00:00
|
|
|
friend int state_dostring(lua_State * L);
|
2013-11-12 20:54:34 +00:00
|
|
|
friend int state_set_global(lua_State * L);
|
2013-11-12 01:46:39 +00:00
|
|
|
friend int mk_thread(lua_State * L);
|
|
|
|
friend int thread_wait(lua_State * L);
|
2013-11-07 21:56:04 +00:00
|
|
|
public:
|
|
|
|
leanlua_state();
|
|
|
|
~leanlua_state();
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Execute the file with the given name.
|
|
|
|
This method throws an exception if an error occurs.
|
|
|
|
*/
|
|
|
|
void dofile(char const * fname);
|
|
|
|
/**
|
|
|
|
\brief Execute the given string.
|
|
|
|
This method throws an exception if an error occurs.
|
|
|
|
*/
|
|
|
|
void dostring(char const * str);
|
2013-11-11 23:05:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Execute the given script, but sets the registry with the given environment object.
|
|
|
|
The registry can be accessed by \str by invoking the function <tt>env()</tt>.
|
|
|
|
The script \c str should not store a reference to the environment \c env.
|
|
|
|
*/
|
2013-11-10 18:12:43 +00:00
|
|
|
void dostring(char const * str, environment & env);
|
2013-11-12 23:38:00 +00:00
|
|
|
|
|
|
|
void dostring(char const * str, environment & env, state & st);
|
2013-11-07 21:56:04 +00:00
|
|
|
};
|
|
|
|
}
|