add wesnoth.show_lua_console, as a debugging aide
This allows some sort of "drop into debug" mode for lua if your script detects an error. We could consider to actually add an "option to attach debugger" as an error handling mechanism, but it might be complicated because of wesnoth exceptions which must go through lua and be treated as lua errors, and we cannot handle two exceptions at once obviously, so the lua interpreter is probably not safe to run that way in general. Anyways this commit does not do that.
This commit is contained in:
parent
ad93493f87
commit
84f5677155
4 changed files with 31 additions and 0 deletions
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "gui/auxiliary/canvas.hpp" // for tcanvas
|
||||
#include "gui/auxiliary/window_builder.hpp" // for twindow_builder, etc
|
||||
#include "gui/dialogs/lua_interpreter.hpp"
|
||||
#include "gui/widgets/clickable.hpp" // for tclickable_
|
||||
#include "gui/widgets/control.hpp" // for tcontrol
|
||||
#include "gui/widgets/multi_page.hpp" // for tmulti_page
|
||||
|
@ -438,4 +439,10 @@ int intf_set_dialog_active(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int show_lua_console(lua_State * /*L*/, CVideo & video, lua_kernel_base * lk)
|
||||
{
|
||||
gui2::tlua_interpreter::display(video, lk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // end namespace lua_gui2
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
struct lua_State;
|
||||
class CVideo;
|
||||
class lua_kernel_base;
|
||||
|
||||
namespace lua_gui2 {
|
||||
|
||||
|
@ -27,6 +28,7 @@ int intf_set_dialog_markup(lua_State *L);
|
|||
int intf_set_dialog_canvas(lua_State *L);
|
||||
int intf_set_dialog_active(lua_State *L);
|
||||
int show_dialog(lua_State *L, CVideo & video);
|
||||
int show_lua_console(lua_State*L, CVideo & video, lua_kernel_base * lk);
|
||||
|
||||
} // end namespace lua_gui2
|
||||
|
||||
|
|
|
@ -110,6 +110,24 @@ int lua_kernel_base::intf_show_dialog(lua_State *L)
|
|||
return lua_gui2::show_dialog(L, *video_);
|
||||
}
|
||||
|
||||
// The show lua console callback is similarly a method of lua kernel
|
||||
int lua_kernel_base::intf_show_lua_console(lua_State *L)
|
||||
{
|
||||
if (!video_) {
|
||||
ERR_LUA << "Cannot show dialog, no video object is available to this lua kernel.";
|
||||
lua_error(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cmd_log_.external_log_ != NULL) {
|
||||
std::string message = "There is already an external logger attached to this lua kernel, you cannot open the lua console right now.";
|
||||
log_error(message.c_str());
|
||||
cmd_log_ << message << "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
return lua_gui2::show_lua_console(L, *video_, this);
|
||||
}
|
||||
|
||||
// End Callback implementations
|
||||
|
||||
|
@ -238,6 +256,7 @@ lua_kernel_base::lua_kernel_base(CVideo * video)
|
|||
{ "dofile", boost::bind(&lua_kernel_base::intf_dofile, this, _1)},
|
||||
{ "require", boost::bind(&lua_kernel_base::intf_require, this, _1)},
|
||||
{ "show_dialog", boost::bind(&lua_kernel_base::intf_show_dialog, this, _1)},
|
||||
{ "show_lua_console", boost::bind(&lua_kernel_base::intf_show_lua_console, this, _1)},
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -89,6 +89,9 @@ protected:
|
|||
// Show a dialog to the currently connected video object (if available)
|
||||
int intf_show_dialog(lua_State * L);
|
||||
|
||||
// Show the interactive lua console (for debugging purposes)
|
||||
int intf_show_lua_console(lua_State * L);
|
||||
|
||||
// Execute a protected call. Error handler is called in case of an error, using syntax for log_error and throw_exception above. Returns true if successful.
|
||||
bool protected_call(int nArgs, int nRets, error_handler);
|
||||
// Load a string onto the stack as a function. Returns true if successful, error handler is called if not.
|
||||
|
|
Loading…
Add table
Reference in a new issue