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 "llvm/ADT/StringRef.h" 13 #include "llvm/Support/Error.h" 14 15 #include "lua.hpp" 16 17 #include <mutex> 18 19 namespace lldb_private { 20 21 extern "C" { 22 int luaopen_lldb(lua_State *L); 23 } 24 25 class Lua { 26 public: 27 Lua() : m_lua_state(luaL_newstate()) { 28 assert(m_lua_state); 29 luaL_openlibs(m_lua_state); 30 luaopen_lldb(m_lua_state); 31 } 32 33 ~Lua() { 34 assert(m_lua_state); 35 luaL_openlibs(m_lua_state); 36 } 37 38 llvm::Error Run(llvm::StringRef buffer); 39 40 private: 41 std::mutex m_mutex; 42 lua_State *m_lua_state; 43 }; 44 45 } // namespace lldb_private 46 47 #endif // liblldb_Lua_h_ 48