1//===-- ScriptInterpreterLua.h ----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef liblldb_Lua_h_
10#define liblldb_Lua_h_
11
12#include "lldb/lldb-types.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/Support/Error.h"
15
16#include "lua.hpp"
17
18#include <mutex>
19
20namespace lldb_private {
21
22extern "C" {
23int luaopen_lldb(lua_State *L);
24}
25
26class Lua {
27public:
28  Lua() : m_lua_state(luaL_newstate()) {
29    assert(m_lua_state);
30    luaL_openlibs(m_lua_state);
31    luaopen_lldb(m_lua_state);
32  }
33
34  ~Lua() {
35    assert(m_lua_state);
36    luaL_openlibs(m_lua_state);
37  }
38
39  llvm::Error Run(llvm::StringRef buffer);
40  llvm::Error LoadModule(llvm::StringRef filename);
41
42private:
43  lua_State *m_lua_state;
44};
45
46} // namespace lldb_private
47
48#endif // liblldb_Lua_h_
49