Skip to content

Commit

Permalink
Merge branch 'add_lua_interpreter_launch_command'
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Nov 28, 2014
2 parents 949b05f + 84f5677 commit 87d5f3b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/scripting/lua_gui2.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/scripting/lua_gui2.hpp
Expand Up @@ -17,6 +17,7 @@

struct lua_State;
class CVideo;
class lua_kernel_base;

namespace lua_gui2 {

Expand All @@ -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

Expand Down
19 changes: 19 additions & 0 deletions src/scripting/lua_kernel_base.cpp
Expand Up @@ -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

Expand Down Expand Up @@ -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 }
};

Expand Down
3 changes: 3 additions & 0 deletions src/scripting/lua_kernel_base.hpp
Expand Up @@ -89,6 +89,9 @@ class lua_kernel_base {
// 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.
Expand Down

0 comments on commit 87d5f3b

Please sign in to comment.