2011-09-14 22:59:54 +03:00
|
|
|
#include "lua-int.hpp"
|
|
|
|
#include "command.hpp"
|
2011-09-17 01:05:41 +03:00
|
|
|
#include "window.hpp"
|
2011-09-14 22:59:54 +03:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2011-09-17 12:26:58 +03:00
|
|
|
function_ptr_luafun lua_print("print", [](lua_State* LS, const std::string& fname) -> int {
|
|
|
|
int stacksize = 0;
|
|
|
|
while(!lua_isnone(LS, stacksize + 1))
|
|
|
|
stacksize++;
|
|
|
|
std::string toprint;
|
|
|
|
bool first = true;
|
|
|
|
for(int i = 0; i < stacksize; i++) {
|
|
|
|
size_t len;
|
|
|
|
const char* tmp = NULL;
|
|
|
|
if(lua_isnil(LS, i + 1)) {
|
|
|
|
tmp = "nil";
|
|
|
|
len = 3;
|
|
|
|
} else if(lua_isboolean(LS, i + 1) && lua_toboolean(LS, i + 1)) {
|
|
|
|
tmp = "true";
|
|
|
|
len = 4;
|
|
|
|
} else if(lua_isboolean(LS, i + 1) && !lua_toboolean(LS, i + 1)) {
|
|
|
|
tmp = "false";
|
|
|
|
len = 5;
|
|
|
|
} else {
|
|
|
|
tmp = lua_tolstring(LS, i + 1, &len);
|
|
|
|
if(!tmp) {
|
|
|
|
tmp = "(unprintable)";
|
|
|
|
len = 13;
|
2011-09-14 22:59:54 +03:00
|
|
|
}
|
|
|
|
}
|
2011-09-17 12:26:58 +03:00
|
|
|
std::string localmsg(tmp, tmp + len);
|
|
|
|
if(first)
|
|
|
|
toprint = localmsg;
|
|
|
|
else
|
|
|
|
toprint = toprint + "\t" + localmsg;
|
|
|
|
first = false;
|
2011-09-14 22:59:54 +03:00
|
|
|
}
|
2011-09-17 12:26:58 +03:00
|
|
|
window::message(toprint);
|
|
|
|
return 0;
|
|
|
|
});
|
2011-09-14 22:59:54 +03:00
|
|
|
|
2011-09-17 12:26:58 +03:00
|
|
|
function_ptr_luafun lua_exec("exec", [](lua_State* LS, const std::string& fname) -> int {
|
|
|
|
std::string text = get_string_argument(LS, 1, fname.c_str());
|
|
|
|
command::invokeC(text);
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|