3 template <typename T> void PushSBClass(lua_State * L, T * obj);
5 // This function is called from Lua::CallBreakpointCallback
6 llvm::Expected<bool> lldb_private::LLDBSwigLuaBreakpointCallbackFunction(
7 lua_State * L, lldb::StackFrameSP stop_frame_sp,
8 lldb::BreakpointLocationSP bp_loc_sp,
9 const StructuredDataImpl &extra_args_impl) {
10 lldb::SBFrame sb_frame(stop_frame_sp);
11 lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp);
14 lldb::SBStructuredData extra_args(extra_args_impl);
16 // Push the Lua wrappers
17 PushSBClass(L, &sb_frame);
18 PushSBClass(L, &sb_bp_loc);
20 if (extra_args.IsValid()) {
21 PushSBClass(L, &extra_args);
25 // Call into the Lua callback passing 'sb_frame' and 'sb_bp_loc'.
26 // Expects a boolean return.
27 if (lua_pcall(L, nargs, 1, 0) != LUA_OK) {
28 llvm::Error E = llvm::make_error<llvm::StringError>(
29 llvm::formatv("{0}\n", lua_tostring(L, -1)),
30 llvm::inconvertibleErrorCode());
31 // Pop error message from the stack.
36 // Boolean return from the callback
37 bool stop = lua_toboolean(L, -1);
43 // This function is called from Lua::CallWatchpointCallback
44 llvm::Expected<bool> lldb_private::LLDBSwigLuaWatchpointCallbackFunction(
45 lua_State * L, lldb::StackFrameSP stop_frame_sp, lldb::WatchpointSP wp_sp) {
46 lldb::SBFrame sb_frame(stop_frame_sp);
47 lldb::SBWatchpoint sb_wp(wp_sp);
50 // Push the Lua wrappers
51 PushSBClass(L, &sb_frame);
52 PushSBClass(L, &sb_wp);
54 // Call into the Lua callback passing 'sb_frame' and 'sb_wp'.
55 // Expects a boolean return.
56 if (lua_pcall(L, nargs, 1, 0) != LUA_OK) {
57 llvm::Error E = llvm::make_error<llvm::StringError>(
58 llvm::formatv("{0}\n", lua_tostring(L, -1)),
59 llvm::inconvertibleErrorCode());
60 // Pop error message from the stack.
65 // Boolean return from the callback
66 bool stop = lua_toboolean(L, -1);
72 static void LLDBSwigLuaCallLuaLogOutputCallback(const char *str, void *baton) {
73 lua_State *L = (lua_State *)baton;
75 lua_pushlightuserdata(L, (void *)&LLDBSwigLuaCallLuaLogOutputCallback);
76 lua_gettable(L, LUA_REGISTRYINDEX);
78 // FIXME: There's no way to report errors back to the user
79 lua_pushstring(L, str);
80 lua_pcall(L, 1, 0, 0);
83 static int LLDBSwigLuaCloseFileHandle(lua_State * L) {
84 return luaL_error(L, "You cannot close a file handle used by lldb.");