Since window is singleton anyway, get rid of window* parameters
[lsnes.git] / lua / core.cpp
blobe2d322dfc93a9e077fafed0dca4e9151199246cc
1 #include "lua-int.hpp"
2 #include "command.hpp"
3 #include "window.hpp"
5 namespace
7 class lua_print : public lua_function
9 public:
10 lua_print() : lua_function("print") {}
11 int invoke(lua_State* LS)
13 int stacksize = 0;
14 while(!lua_isnone(LS, stacksize + 1))
15 stacksize++;
16 std::string toprint;
17 bool first = true;
18 for(int i = 0; i < stacksize; i++) {
19 size_t len;
20 const char* tmp = NULL;
21 if(lua_isnil(LS, i + 1)) {
22 tmp = "nil";
23 len = 3;
24 } else if(lua_isboolean(LS, i + 1) && lua_toboolean(LS, i + 1)) {
25 tmp = "true";
26 len = 4;
27 } else if(lua_isboolean(LS, i + 1) && !lua_toboolean(LS, i + 1)) {
28 tmp = "false";
29 len = 5;
30 } else {
31 tmp = lua_tolstring(LS, i + 1, &len);
32 if(!tmp) {
33 tmp = "(unprintable)";
34 len = 13;
37 std::string localmsg(tmp, tmp + len);
38 if(first)
39 toprint = localmsg;
40 else
41 toprint = toprint + "\t" + localmsg;
42 first = false;
44 window::message(toprint);
45 return 0;
47 } print;
49 class lua_exec : public lua_function
51 public:
52 lua_exec() : lua_function("exec") {}
53 int invoke(lua_State* LS)
55 std::string text = get_string_argument(LS, 1, fname.c_str());
56 command::invokeC(text);
57 return 0;
59 } exec;