Add eval command to console.
This commit is contained in:
parent
d3eee75e2c
commit
8e04b3fc01
|
@ -25,6 +25,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ext/gif.h"
|
#include "ext/gif.h"
|
||||||
#include "ext/file_dialog.h"
|
#include "ext/file_dialog.h"
|
||||||
|
#include "machine.h"
|
||||||
|
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
@ -2216,6 +2217,28 @@ static void onConsoleResumeCommand(Console* console, const char* param)
|
||||||
resumeRunMode();
|
resumeRunMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void onConsoleEvalCommand(Console* console, const char* param)
|
||||||
|
{
|
||||||
|
printLine(console);
|
||||||
|
|
||||||
|
tic_machine* machine = (tic_machine*)console->tic;
|
||||||
|
lua_State* lua = machine->lua;
|
||||||
|
|
||||||
|
// TODO: check for other languages/runtimes?
|
||||||
|
if(lua)
|
||||||
|
{
|
||||||
|
if(luaL_dostring(lua, param) != LUA_OK)
|
||||||
|
{
|
||||||
|
printError(console, lua_tostring(lua, -1));
|
||||||
|
}
|
||||||
|
lua_settop(lua, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printError(console, "Lua state uninitialized.\n");
|
||||||
|
|
||||||
|
commandDone(console);
|
||||||
|
}
|
||||||
|
|
||||||
static void onAddFile(const char* name, AddResult result, void* data)
|
static void onAddFile(const char* name, AddResult result, void* data)
|
||||||
{
|
{
|
||||||
Console* console = (Console*)data;
|
Console* console = (Console*)data;
|
||||||
|
@ -2418,6 +2441,7 @@ static const struct
|
||||||
{"save", NULL, "save cart", onConsoleSaveCommand},
|
{"save", NULL, "save cart", onConsoleSaveCommand},
|
||||||
{"run", NULL, "run loaded cart", onConsoleRunCommand},
|
{"run", NULL, "run loaded cart", onConsoleRunCommand},
|
||||||
{"resume", NULL, "resume run cart", onConsoleResumeCommand},
|
{"resume", NULL, "resume run cart", onConsoleResumeCommand},
|
||||||
|
{"eval", "=", "run code", onConsoleEvalCommand},
|
||||||
{"dir", "ls", "show list of files", onConsoleDirCommand},
|
{"dir", "ls", "show list of files", onConsoleDirCommand},
|
||||||
{"cd", NULL, "change directory", onConsoleChangeDirectory},
|
{"cd", NULL, "change directory", onConsoleChangeDirectory},
|
||||||
{"mkdir", NULL, "make directory", onConsoleMakeDirectory},
|
{"mkdir", NULL, "make directory", onConsoleMakeDirectory},
|
||||||
|
@ -3310,4 +3334,4 @@ void initConsole(Console* console, tic_mem* tic, FileSystem* fs, Config* config,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
console->active = !console->embed.yes;
|
console->active = !console->embed.yes;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue