1 //===-- Lua.cpp -----------------------------------------------------------===// 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 #include "Lua.h" 10 #include "llvm/Support/FormatVariadic.h" 11 12 using namespace lldb_private; 13 14 llvm::Error Lua::Run(llvm::StringRef buffer) { 15 int error = 16 luaL_loadbuffer(m_lua_state, buffer.data(), buffer.size(), "buffer") || 17 lua_pcall(m_lua_state, 0, 0, 0); 18 if (!error) 19 return llvm::Error::success(); 20 21 llvm::Error e = llvm::make_error<llvm::StringError>( 22 llvm::formatv("{0}\n", lua_tostring(m_lua_state, -1)), 23 llvm::inconvertibleErrorCode()); 24 // Pop error message from the stack. 25 lua_pop(m_lua_state, 1); 26 return e; 27 } 28