3 template <typename T> void PushSBClass(lua_State * L, T * obj);
5 // This function is called from Lua::CallBreakpointCallback
7 lldb_private::lua::SWIGBridge::LLDBSwigLuaBreakpointCallbackFunction(
8 lua_State * L, lldb::StackFrameSP stop_frame_sp,
9 lldb::BreakpointLocationSP bp_loc_sp,
10 const StructuredDataImpl &extra_args_impl) {
11 lldb::SBFrame sb_frame(stop_frame_sp);
12 lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp);
15 lldb::SBStructuredData extra_args(extra_args_impl);
17 // Push the Lua wrappers
18 PushSBClass(L, &sb_frame);
19 PushSBClass(L, &sb_bp_loc);
21 if (extra_args.IsValid()) {
22 PushSBClass(L, &extra_args);
26 // Call into the Lua callback passing 'sb_frame' and 'sb_bp_loc'.
27 // Expects a boolean return.
28 if (lua_pcall(L, nargs, 1, 0) != LUA_OK) {
29 llvm::Error E = llvm::make_error<llvm::StringError>(
30 llvm::formatv("{0}\n", lua_tostring(L, -1)),
31 llvm::inconvertibleErrorCode());
32 // Pop error message from the stack.
37 // Boolean return from the callback
38 bool stop = lua_toboolean(L, -1);
44 // This function is called from Lua::CallWatchpointCallback
46 lldb_private::lua::SWIGBridge::LLDBSwigLuaWatchpointCallbackFunction(
47 lua_State * L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp) {
48 lldb::SBFrame sb_frame(stop_frame_sp);
49 lldb::SBWatchpoint sb_wp(wp_sp);
52 // Push the Lua wrappers
53 PushSBClass(L, &sb_frame);
54 PushSBClass(L, &sb_wp);
56 // Call into the Lua callback passing 'sb_frame' and 'sb_wp'.
57 // Expects a boolean return.
58 if (lua_pcall(L, nargs, 1, 0) != LUA_OK) {
59 llvm::Error E = llvm::make_error<llvm::StringError>(
60 llvm::formatv("{0}\n", lua_tostring(L, -1)),
61 llvm::inconvertibleErrorCode());
62 // Pop error message from the stack.
67 // Boolean return from the callback
68 bool stop = lua_toboolean(L, -1);
74 static void LLDBSwigLuaCallLuaLogOutputCallback(const char *str, void *baton) {
75 lua_State *L = (lua_State *)baton;
77 lua_pushlightuserdata(L, (void *)&LLDBSwigLuaCallLuaLogOutputCallback);
78 lua_gettable(L, LUA_REGISTRYINDEX);
80 // FIXME: There's no way to report errors back to the user
81 lua_pushstring(L, str);
82 lua_pcall(L, 1, 0, 0);
85 static int LLDBSwigLuaCloseFileHandle(lua_State * L) {
86 return luaL_error(L, "You cannot close a file handle used by lldb.");